diff --git a/examples/HYCOM/download_hycom.py b/examples/HYCOM/download_hycom.py index b97d242f..f94dad51 100644 --- a/examples/HYCOM/download_hycom.py +++ b/examples/HYCOM/download_hycom.py @@ -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') + """ diff --git a/examples/Sflux/gen_sflux_hrrr3.py b/examples/Sflux/gen_sflux_hrrr3.py index 63557cd5..bde3d5ad 100644 --- a/examples/Sflux/gen_sflux_hrrr3.py +++ b/examples/Sflux/gen_sflux_hrrr3.py @@ -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!') diff --git a/pyschism/forcing/hycom/hycom2schism.py b/pyschism/forcing/hycom/hycom2schism.py index 3fe29078..f18c48c2 100644 --- a/pyschism/forcing/hycom/hycom2schism.py +++ b/pyschism/forcing/hycom/hycom2schism.py @@ -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) @@ -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')