Skip to content

Commit

Permalink
504 support for waq in modelbuilder example script (#601)
Browse files Browse the repository at this point in the history
* larger buffer for cmems waq variables

* updated notebook and added phyc

* return available keys in conversion_dict() when requesting non-existent one

* updated whatsnew
  • Loading branch information
veenstrajelmer authored Oct 19, 2023
1 parent 23caa35 commit 4868fbb
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 68 deletions.
10 changes: 6 additions & 4 deletions dfm_tools/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def download_CMEMS(varkey,

Path(dir_output).mkdir(parents=True, exist_ok=True)
if varkey in ['bottomT','tob','mlotst','siconc','sithick','so','thetao','uo','vo','usi','vsi','zos']: #for physchem
buffer = 2/12 # resolution is 1/12 degrees
if product == 'analysisforecast': #forecast: https://data.marine.copernicus.eu/product/GLOBAL_ANALYSISFORECAST_PHY_001_024/description
if varkey in ['uo','vo']: #anfc datset is splitted over multiple urls, construct the correct one here.
varkey_name = 'phy-cur'
Expand All @@ -124,16 +125,17 @@ def download_CMEMS(varkey,
else: #reanalysis: https://data.marine.copernicus.eu/product/GLOBAL_MULTIYEAR_PHY_001_030/description
dataset_url = 'https://my.cmems-du.eu/thredds/dodsC/cmems_mod_glo_phy_my_0.083_P1D-m'
else: #for bio
buffer = 2/4 # resolution is 1/4 degrees
if product == 'analysisforecast': #forecast: https://data.marine.copernicus.eu/product/GLOBAL_ANALYSIS_FORECAST_BIO_001_028/description
dataset_url = 'https://nrt.cmems-du.eu/thredds/dodsC/global-analysis-forecast-bio-001-028-daily' #contains ['chl','fe','no3','nppv','o2','ph','phyc','po4','si','spco2']
else: #https://data.marine.copernicus.eu/product/GLOBAL_MULTIYEAR_BGC_001_029/description
dataset_url = 'https://my.cmems-du.eu/thredds/dodsC/cmems_mod_glo_bgc_my_0.25_P1D-m' #contains ['chl','no3','nppv','o2','po4','si']

#make sure the data fully covers the desired spatial extent. Download 2 additional grid cells (resolution is 1/12 degrees, but a bit more/less in alternating cells) in each direction
longitude_min -= 2/12
longitude_max += 2/12
latitude_min -= 2/12
latitude_max += 2/12
longitude_min -= buffer
longitude_max += buffer
latitude_min -= buffer
latitude_max += buffer

download_OPeNDAP(dataset_url=dataset_url,
varkey=varkey,
Expand Down
6 changes: 6 additions & 0 deletions dfm_tools/interpolate_grid2bnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ def open_dataset_extra(dir_pattern, quantity, tstart, tstop, conversion_dict=Non
quantity_list = ['ux','uy']
else:
quantity_list = [quantity]

# check existence of requested keys in conversion_dict
for quan in quantity_list:
if quan not in conversion_dict.keys():
raise KeyError(f"quantity '{quan}' not in conversion_dict, (case sensitive) options are: {str(list(conversion_dict.keys()))}")

ncvarname_list = [conversion_dict[quan]['ncvarname'] for quan in quantity_list]

#convert tstart/tstop from str/dt.datetime/pd.Timestamp to pd.Timestamp. WARNING: when supplying '05-04-2016', monthfirst is assumed, so 2016-05-04 will be the result (may instead of april).
Expand Down
3 changes: 1 addition & 2 deletions dfm_tools/modelbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import datetime as dt
import glob
from hydrolib.core.dimr.models import DIMR, FMComponent, Start
import warnings


def cmems_nc_to_bc(ext_bnd, list_quantities, tstart, tstop, file_pli, dir_pattern, dir_output, refdate_str):
Expand All @@ -43,7 +42,7 @@ def cmems_nc_to_bc(ext_bnd, list_quantities, tstart, tstop, file_pli, dir_patter
ForcingModel_object.save(filepath=file_bc_out)

#generate boundary object for the ext file (quantity, pli-filename, bc-filename)
boundary_object = hcdfm.Boundary(quantity=quantity.replace('tide','waterlevelbnd'), #the FM quantity for tide is also waterlevelbnd
boundary_object = hcdfm.Boundary(quantity=quantity,
locationfile=file_pli,
forcingfile=ForcingModel_object)
ext_bnd.boundary.append(boundary_object)
Expand Down
Loading

0 comments on commit 4868fbb

Please sign in to comment.