New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
problem with slicing of time in open_dataset_extra #797
Comments
MWE:
Another good example would be to download monthly output and convert this to a period that doesn't start or end on the first of the month. For example when downloading and converting monthly-mean NO3 (
|
This also happens in tests/examples/preprocess_interpolate_nc_to_bc.py now (#802), which was not the case before: import os
import dfm_tools as dfmt
import xarray as xr
file_pli = r'p:\archivedprojects\11208054-004-dcsm-fm\models\model_input\bnd_cond\pli\DCSM-FM_OB_all_20181108.pli'
tstart = '2012-01-16 12:00'
tstop = '2012-04-16 12:00'
dir_sourcefiles_waq = r'p:\archivedprojects\11206304-futuremares-rawdata-preps\python_scripts\ocean_boundaryCMEMS\data_monthly'
dir_pattern = os.path.join(dir_sourcefiles_waq,'cmems_mod_glo_bgc_my_0.25_P1M-m_{ncvarname}_*.nc')
ds = xr.open_mfdataset(dir_pattern.format(ncvarname="no3"))
print(ds.time)
data_xr_vars = dfmt.open_dataset_extra(dir_pattern=dir_pattern,
quantity='tracerbndNO3',
tstart=tstart, tstop=tstop)` But this is actually since the source data is monthly and mixed noon/midnight times. |
The time slicing in the function open_dataset_extra in interpolate_grid2bnd.py causes an error if the timestamp of the requested
tstart
is not at midnight (00:00).Think of an xarray.DataArray, where:
and:
tstart, tstop = Timestamp('2021-12-31 12:00:00'), Timestamp('2022-01-02 12:00:00')
This line:
dfm_tools/dfm_tools/interpolate_grid2bnd.py
Line 335 in 245909c
returns an xarray.DataArray without the first and last times:
This causes an error in the following line, where a check is done:
dfm_tools/dfm_tools/interpolate_grid2bnd.py
Line 338 in 245909c
I suggest to change line 335 to:
data_xr_vars = data_xr[quantity_list].sel(time=slice(tstart.floor('1d'),tstop.ceil('1d')))
The text was updated successfully, but these errors were encountered: