Skip to content

Commit

Permalink
616 fill nans in ini saltem netcdf (#617)
Browse files Browse the repository at this point in the history
* added interpolate_na/ffill/bfill to preprocess_ini_cmems_to_nc()

* updated whatsnew
  • Loading branch information
veenstrajelmer authored Oct 25, 2023
1 parent 04cb646 commit 6685971
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 10 additions & 0 deletions dfm_tools/modelbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ def preprocess_ini_cmems_to_nc(ext_old, tstart, dir_data, dir_out):
print(f'opening {len(file_nc_list)} datasets')
data_xr = xr.open_mfdataset(file_nc_list)

# fill nans
# start with lat/lon to avoid values from shallow coastal areas in deep layers
# first interpolate nans to get smooth filling of e.g. islands, this cannot fill nans at the edge of the dataset
data_xr = data_xr.interpolate_na(dim='latitude').interpolate_na(dim='longitude')

# then use bfill/ffill to fill nans at the edge for lat/lon/depth
data_xr = data_xr.ffill(dim='latitude').bfill(dim='latitude')
data_xr = data_xr.ffill(dim='longitude').bfill(dim='longitude')
data_xr = data_xr.ffill(dim='depth').bfill(dim='depth')

tSimStart = pd.Timestamp(tstart)
data_xr_ontime = data_xr.sel(time=slice(tSimStart-dt.timedelta(days=1),tSimStart+dt.timedelta(days=1)))

Expand Down
1 change: 1 addition & 0 deletions docs/whats-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Fix
- increased buffer in `dfmt.download_ERA5()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#612](https://github.com/Deltares/dfm_tools/pull/612)
- support for Polygon geometries in `dfmt.geodataframe_to_PolyFile()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#610](https://github.com/Deltares/dfm_tools/pull/610)
- fill nan-values in initial salinity/temperature netcdf dataset in `dfmt.preprocess_ini_cmems_to_nc()` by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#617](https://github.com/Deltares/dfm_tools/pull/617)


## 0.15.0 (2023-10-19)
Expand Down
11 changes: 6 additions & 5 deletions tests/examples_workinprogress/workinprogress_modelbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
dir_output = r'p:\11209231-003-bes-modellering\hydrodynamica\hackathon\preprocessing\ModelBuilderOutput_JV2'
path_style = 'windows' # windows / unix
overwrite = False # used for downloading of forcing data. Always set to True when changing the domain
paths_relative = False #TODO: currently only works with path_style='windows' (same OS as IDE)
paths_relative = True #TODO: currently only works with path_style='windows' (same OS as IDE)
is_geographic = True
crs = 'EPSG:4326'

Expand Down Expand Up @@ -117,12 +117,13 @@

# FES2014 tidal components bc file
file_bc_basename = os.path.basename(poly_file).replace('.pli','')
ForcingModel_object = dfmt.interpolate_tide_to_bc(tidemodel='FES2014', file_pli=poly_file, component_list=None) # tidemodel: FES2014, FES2012, EOT20, GTSMv4.1
file_bc_out = os.path.join(dir_output,f'tide_{file_bc_basename}_FES2014.bc')
tidemodel = 'EOT20' # tidemodel: FES2014, FES2012, EOT20, GTSMv4.1, GTSMv4.1_opendap
ForcingModel_object = dfmt.interpolate_tide_to_bc(tidemodel=tidemodel, file_pli=poly_file, component_list=None)
file_bc_out = os.path.join(dir_output,f'tide_{file_bc_basename}_{tidemodel}.bc')
ForcingModel_object.save(filepath=file_bc_out)
boundary_object = hcdfm.Boundary(quantity='waterlevelbnd', #the FM quantity for tide is also waterlevelbnd
locationfile=poly_file,
forcingfile=ForcingModel_object)
locationfile=poly_file,
forcingfile=ForcingModel_object)
ext_new.boundary.append(boundary_object)

# CMEMS - download
Expand Down

0 comments on commit 6685971

Please sign in to comment.