|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 | import argparse
|
3 | 3 | import datetime
|
| 4 | +import numpy as np |
4 | 5 | import os
|
5 | 6 | import requests
|
6 | 7 | import subprocess
|
7 | 8 | import sys
|
| 9 | +import wget |
8 | 10 | import gnssrefl.gps as g
|
9 | 11 |
|
10 | 12 | #from gnssrefl.utils import validate_input_datatypes, str2bool
|
@@ -402,6 +404,78 @@ def pickup_from_noaa(station,date1,date2,datum, printmeta):
|
402 | 404 |
|
403 | 405 | return data, error
|
404 | 406 |
|
| 407 | +def download_qld(station,year,plt): |
| 408 | + """ |
| 409 | + Parameters |
| 410 | + ---------- |
| 411 | + station : str |
| 412 | + tide gauge station name |
| 413 | + year : int |
| 414 | + calendar year |
| 415 | + plt : bool |
| 416 | + whether you want a plot to the screen |
| 417 | + """ |
| 418 | + # unfortunately hardwired for 2022 now |
| 419 | + #https://www.qld.gov.au/environment/coasts-waterways/beach/storm/storm-sites |
| 420 | + # last seven days |
| 421 | + # https://www.data.qld.gov.au/dataset/coastal-data-system-near-real-time-storm-tide-data |
| 422 | + if year is None: |
| 423 | + print('Year is required for the Queensland option') |
| 424 | + sys.exit() |
| 425 | + else: |
| 426 | + url = 'https://www.data.qld.gov.au/dataset/179c7cc5-26a7-4f57-9e1e-3ec2ed5dd4de/resource/cacc9e98-be38-44f7-a535-07acd22a3b91/' |
| 427 | + url2 = 'download/h071004a_' + str(year) + '_' + station + '_10min.csv' |
| 428 | + tmpfile = station + '_' + str(year) + '_10min.csv' |
| 429 | + wget.download(url+url2, tmpfile) |
| 430 | + |
| 431 | + xdir = os.environ['REFL_CODE'] |
| 432 | + outdir = xdir + '/Files/' |
| 433 | + if not os.path.exists(outdir) : |
| 434 | + subprocess.call(['mkdir', outdir]) |
| 435 | + outfile = outdir + station + '_' + str(year) + '.txt' |
| 436 | + |
| 437 | + fout = open(outfile, 'w+') |
| 438 | + print('Queensland Tide file written to :', outfile) |
| 439 | + |
| 440 | + obstimes=[] |
| 441 | + sl = [] |
| 442 | + fout.write("{0:s} \n".format('%' + ' QLD Station: ' + station )) |
| 443 | + fout.write("%YYYY MM DD HH MM SS Water(m) DOY MJD \n") |
| 444 | + fout.write("% 1 2 3 4 5 6 7 8 9\n") |
| 445 | + |
| 446 | + if os.path.isfile(tmpfile): |
| 447 | + x=np.loadtxt(tmpfile,usecols=(0,1,3),skiprows=40,dtype='str',delimiter=',') |
| 448 | + nr,nc=np.shape(x) |
| 449 | + for i in range(0,nr): |
| 450 | + sealevel = float(x[i,2]) |
| 451 | + sl.append(sealevel) |
| 452 | + d = int(x[i,0][0:2]) ; m = int(x[i,0][3:5]) |
| 453 | + y = int(x[i,0][6:10]) |
| 454 | + hr = int(x[i,1][1:3]); mm = int(x[i,1][4:6]) |
| 455 | + bigT = datetime.datetime(year=y, month=m, day=d,hour=hr,minute=mm,second=0) |
| 456 | + obstimes.append(bigT) |
| 457 | + modjul, fr = g.mjd(y,m,d,hr,mm,0) |
| 458 | + mjd = modjul+fr |
| 459 | + doy,cdoy,cyyyy,cyy = g.ymd2doy(y, m, d ) |
| 460 | + fout.write(" {0:4.0f} {1:2.0f} {2:2.0f} {3:2.0f} {4:2.0f} {5:2.0f} {6:7.3f} {7:3.0f} {8:15.6f} \n".format(y, m, d, hr, mm, 0, sealevel, doy, mjd)) |
| 461 | + |
| 462 | + fout.close() |
| 463 | + else: |
| 464 | + print('No file was downloaded') |
| 465 | + sys.exit() |
| 466 | + |
| 467 | + if plt: |
| 468 | + g.quickp(station,obstimes,sl) |
| 469 | + |
| 470 | + # clean up - remove csv file |
| 471 | + subprocess.call(['rm','-f',tmpfile]) |
| 472 | + |
| 473 | +# this is more direct API call for last seven days ... I think |
| 474 | +#urlL = 'https://www.data.qld.gov.au/api/3/action/datastore_search?resource_id=7afe7233-fae0-4024-bc98-3a72f05675bd' |
| 475 | +#endL = '&q=' + station + '&limit=' + str(NV) |
| 476 | + |
| 477 | +# https://www.data.qld.gov.au/dataset/coastal-data-system-near-real-time-storm-tide-data |
| 478 | + |
405 | 479 |
|
406 | 480 | if __name__ == "__main__":
|
407 | 481 | main()
|
|
0 commit comments