Skip to content

Commit

Permalink
update example scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cuill committed Feb 1, 2024
1 parent ac3bcfc commit 445ea19
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 31 deletions.
48 changes: 39 additions & 9 deletions examples/HYCOM/download_hycom.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,46 @@
logger.setLevel(logging.INFO)

if __name__ == '__main__':
hgrid = Hgrid.open('./hgrid.gr3', crs='epsg:4326')
date=datetime(2018, 1, 1)
outdir = './'

##example 1 - download data for IC
#rnday = 1

#hgrid = Hgrid.open('./hgrid.gr3', crs='epsg:4326')
#hycom = DownloadHycom(hgrid=hgrid)

#t0 = time()
#hycom.fetch_data(date, rnday=1, bnd=False, nudge=False, outdir=outdir)
#print(f'It took {(time()-t0)/60} mins to download')

#example 2 - download data for bnd
rnday = 10

xmin = -55
xmax = -50
ymin = 0
ymax = 53
bbox = Bbox.from_extents(xmin, ymin, xmax, ymax)

hycom = DownloadHycom(bbox=bbox)

#xmin = -65
#xmax = -50
#ymin = 0
#ymax = 53
#bbox = Bbox.from_extents(xmin, ymin, xmax, ymax)
hycom = DownloadHycom(hgrid=hgrid)
t0 = time()
hycom.fetch_data(date, rnday=1, bnd=False, nudge=False, sub_sample=3, outdir='./')
hycom.fetch_data(date, rnday=rnday, bnd=True, nudge=False, fmt='schism', outdir=outdir)
print(f'It took {(time()-t0)/60} mins to download')

#"""

"""example 3 - download data for nudge
rnday = 20
xmin = -65
xmax = -50
ymin = 0
ymax = 53
bbox = Bbox.from_extents(xmin, ymin, xmax, ymax)
hycom = DownloadHycom(bbox=bbox)
hycom.fetch_data(date, rnday=rnday, bnd=False, nudge=True, outdir=outdir)
print(f'It took {(time()-t0)/60} mins to download')
"""
8 changes: 4 additions & 4 deletions examples/Sflux/gen_sflux_hrrr3.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
#rndelta = end -start
#rnday = rndelta.total_seconds() / 86400.
start = datetime(2023, 10, 26)
rnday = 2
rnday = 10
hgrid = Hgrid.open('./hgrid.gr3', crs='epsg:4326')
#outdir = path = pathlib.Path('./HRRR_2017_2')
#bbox = Bbox.from_extents(-162, 60.79, -143, 69.1)


#pscr - to save downloaded grib2 files and files will be deleted after nc files are created
pscr='/sciclone/pscr/lcui01/HRRR/'
hrrr = HRRR(level=2, region='alaska', pscr=pscr, bbox=bbox)

hrrr = HRRR(level=2, region='conus', pscr=pscr, bbox=hgrid.bbox)
hrrr.write(start_date=start, rnday=rnday, air=True, prc=True, rad=True)
print(f'It took {(time()-t0)/60} mins to process {rnday} days!')
36 changes: 18 additions & 18 deletions pyschism/forcing/hycom/hycom2schism.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,16 +804,16 @@ def fetch_data(self, start_date, rnday=1, fmt='schism', bnd=False, nudge=False,

time_idx, lon_idx1, lon_idx2, lat_idx1, lat_idx2, x2, y2, isLonSame = get_idxs(date, database, self.bbox)

url_ssh = f'https://tds.hycom.org/thredds/dodsC/{database}?lat[{lat_idx1}:{sub_sample}:{lat_idx2}],' + \
f'lon[{lon_idx1}:{sub_sample}:{lon_idx2}],depth[0:1:-1],time[{time_idx}],' + \
f'surf_el[{time_idx}][{lat_idx1}:{sub_sample}:{lat_idx2}][{lon_idx1}:{sub_sample}:{lon_idx2}],' + \
f'water_u[{time_idx}][0:1:39][{lat_idx1}:{sub_sample}:{lat_idx2}][{lon_idx1}:{sub_sample}:{lon_idx2}],' + \
f'water_v[{time_idx}][0:1:39][{lat_idx1}:{sub_sample}:{lat_idx2}][{lon_idx1}:{sub_sample}:{lon_idx2}],' + \
f'water_temp[{time_idx}][0:1:39][{lat_idx1}:{sub_sample}:{lat_idx2}][{lon_idx1}:{sub_sample}:{lon_idx2}],' + \
f'salinity[{time_idx}][0:1:39][{lat_idx1}:{sub_sample}:{lat_idx2}][{lon_idx1}:{sub_sample}:{lon_idx2}]'

foutname = f'hycom_{date.strftime("%Y%m%d")}.nc'
if fmt == 'schism':
url_ssh = f'https://tds.hycom.org/thredds/dodsC/{database}?lat[{lat_idx1}:{sub_sample}:{lat_idx2}],' + \
f'lon[{lon_idx1}:{sub_sample}:{lon_idx2}],depth[0:1:-1],time[{time_idx}],' + \
f'surf_el[{time_idx}][{lat_idx1}:{sub_sample}:{lat_idx2}][{lon_idx1}:{sub_sample}:{lon_idx2}],' + \
f'water_u[{time_idx}][0:1:39][{lat_idx1}:{sub_sample}:{lat_idx2}][{lon_idx1}:{sub_sample}:{lon_idx2}],' + \
f'water_v[{time_idx}][0:1:39][{lat_idx1}:{sub_sample}:{lat_idx2}][{lon_idx1}:{sub_sample}:{lon_idx2}],' + \
f'water_temp[{time_idx}][0:1:39][{lat_idx1}:{sub_sample}:{lat_idx2}][{lon_idx1}:{sub_sample}:{lon_idx2}],' + \
f'salinity[{time_idx}][0:1:39][{lat_idx1}:{sub_sample}:{lat_idx2}][{lon_idx1}:{sub_sample}:{lon_idx2}]'

foutname = f'hycom_{date.strftime("%Y%m%d")}.nc'
#foutname = f'TS_{i+1}.nc'
logger.info(f'filename is {foutname}')
ds = xr.open_dataset(url_ssh)
Expand Down Expand Up @@ -862,15 +862,15 @@ def fetch_data(self, start_date, rnday=1, fmt='schism', bnd=False, nudge=False,
os.symlink(src, dst)

elif fmt == 'hycom':
url=f'https://tds.hycom.org/thredds/dodsC/{database}?lat[{lat_idx1}:1:{lat_idx2}],' + \
f'lon[{lon_idx1}:1:{lon_idx2}],depth[0:1:-1],time[{time_idx}],' + \
f'surf_el[{time_idx}][{lat_idx1}:1:{lat_idx2}][{lon_idx1}:1:{lon_idx2}],' + \
f'water_temp[{time_idx}][0:1:39][{lat_idx1}:1:{lat_idx2}][{lon_idx1}:1:{lon_idx2}],' + \
f'salinity[{time_idx}][0:1:39][{lat_idx1}:1:{lat_idx2}][{lon_idx1}:1:{lon_idx2}],' + \
f'water_u[{time_idx}][0:1:39][{lat_idx1}:1:{lat_idx2}][{lon_idx1}:1:{lon_idx2}],' + \
f'water_v[{time_idx}][0:1:39][{lat_idx1}:1:{lat_idx2}][{lon_idx1}:1:{lon_idx2}]'

foutname = f'hycom_{date.strftime("%Y%m%d")}.nc'
#url=f'https://tds.hycom.org/thredds/dodsC/{database}?lat[{lat_idx1}:1:{lat_idx2}],' + \
# f'lon[{lon_idx1}:1:{lon_idx2}],depth[0:1:-1],time[{time_idx}],' + \
# f'surf_el[{time_idx}][{lat_idx1}:1:{lat_idx2}][{lon_idx1}:1:{lon_idx2}],' + \
# f'water_temp[{time_idx}][0:1:39][{lat_idx1}:1:{lat_idx2}][{lon_idx1}:1:{lon_idx2}],' + \
# f'salinity[{time_idx}][0:1:39][{lat_idx1}:1:{lat_idx2}][{lon_idx1}:1:{lon_idx2}],' + \
# f'water_u[{time_idx}][0:1:39][{lat_idx1}:1:{lat_idx2}][{lon_idx1}:1:{lon_idx2}],' + \
# f'water_v[{time_idx}][0:1:39][{lat_idx1}:1:{lat_idx2}][{lon_idx1}:1:{lon_idx2}]'

#foutname = f'hycom_{date.strftime("%Y%m%d")}.nc'
ds = xr.open_dataset(url)
ds.to_netcdf(foutname, 'w')

Expand Down

0 comments on commit 445ea19

Please sign in to comment.