Skip to content
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

New year edge case error: Daily prediction generation #57

Open
bnubald opened this issue Jan 6, 2025 · 0 comments · Fixed by #58
Open

New year edge case error: Daily prediction generation #57

bnubald opened this issue Jan 6, 2025 · 0 comments · Fixed by #58
Assignees
Labels
bug Something isn't working
Milestone

Comments

@bnubald
Copy link
Contributor

bnubald commented Jan 6, 2025

Issue

When attempting to generate daily forecasts using the run_era5_forecast.sh over the first week of a year, it fails with the following error (Script run on 5th/6th of Jan 2025):

$ ./run_era5_forecast.sh atmos23

Traceback (most recent call last):
  File "/data/hpcdata/users/username/miniconda3/envs/icenet0.2.9_dev/lib/python3.11/site-packages/xarray/backends/file_manager.py", line 209, in _acquire_with_cache_info
    file = self._cache[self._key]
           ~~~~~~~~~~~^^^^^^^^^^^
  File "/data/hpcdata/users/username/miniconda3/envs/icenet0.2.9_dev/lib/python3.11/site-packages/xarray/backends/lru_cache.py", line 55, in __getitem__
    value = self._cache[key]
            ~~~~~~~~~~~^^^^^
KeyError: [<class 'netCDF4._netCDF4.Dataset'>, ('/data/hpcdata/users/username/icenet-daily-forecast-generation/data/era5/south/tas/2025.nc',), 'r', (('clobber', True), ('diskless', False), ('format', 'NETCDF4'), ('persist', False)), '569e43f1-2646-4b70-8b7b-4178558efa60']

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/data/hpcdata/users/username/miniconda3/envs/icenet0.2.9_dev/lib/python3.11/site-packages/xarray/backends/api.py", line 541, in open_dataset
    backend_ds = backend.open_dataset(
                 ^^^^^^^^^^^^^^^^^^^^^
  File "/data/hpcdata/users/username/miniconda3/envs/icenet0.2.9_dev/lib/python3.11/site-packages/xarray/backends/netCDF4_.py", line 578, in open_dataset
    store = NetCDF4DataStore.open(
            ^^^^^^^^^^^^^^^^^^^^^^
  File "/data/hpcdata/users/username/miniconda3/envs/icenet0.2.9_dev/lib/python3.11/site-packages/xarray/backends/netCDF4_.py", line 382, in open
    return cls(manager, group=group, mode=mode, lock=lock, autoclose=autoclose)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/hpcdata/users/username/miniconda3/envs/icenet0.2.9_dev/lib/python3.11/site-packages/xarray/backends/netCDF4_.py", line 329, in __init__
    self.format = self.ds.data_model
                  ^^^^^^^
  File "/data/hpcdata/users/username/miniconda3/envs/icenet0.2.9_dev/lib/python3.11/site-packages/xarray/backends/netCDF4_.py", line 391, in ds
    return self._acquire()
           ^^^^^^^^^^^^^^^
  File "/data/hpcdata/users/username/miniconda3/envs/icenet0.2.9_dev/lib/python3.11/site-packages/xarray/backends/netCDF4_.py", line 385, in _acquire
    with self._manager.acquire_context(needs_lock) as root:
  File "/data/hpcdata/users/username/miniconda3/envs/icenet0.2.9_dev/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/data/hpcdata/users/username/miniconda3/envs/icenet0.2.9_dev/lib/python3.11/site-packages/xarray/backends/file_manager.py", line 197, in acquire_context
    file, cached = self._acquire_with_cache_info(needs_lock)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/hpcdata/users/username/miniconda3/envs/icenet0.2.9_dev/lib/python3.11/site-packages/xarray/backends/file_manager.py", line 215, in _acquire_with_cache_info
    file = self._opener(*self._args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "src/netCDF4/_netCDF4.pyx", line 2353, in netCDF4._netCDF4.Dataset.__init__
  File "src/netCDF4/_netCDF4.pyx", line 1963, in netCDF4._netCDF4._ensure_nc_success
FileNotFoundError: [Errno 2] No such file or directory: b'/data/hpcdata/users/username/icenet-daily-forecast-generation/data/era5/south/tas/2025.nc'

Solution

Problem caused by:

FORECAST_INIT=`python -c 'import xarray as xr; print(str(xr.open_dataset("data/era5/'$HEMI'/tas/'${DATE_RANGE:0:4}'.nc").time.values.max())[0:10])'`

The DATE_RANGE here:

DATE_RANGE="`date +%Y-1-1` `date +%F`"

resolves to 2025-1-1 2025-1-6

And, it tries to load: data/era5/south/tas/2025.nc, but due to the ~5 day lag in ERA5 data availability, this file does not yet exist, and so, shows this error.

If this happens, it should try to figure out the latest available date to initialise forecast from using the previous year's file instead.

@bnubald bnubald added the bug Something isn't working label Jan 6, 2025
@bnubald bnubald added this to the v0.2.9 milestone Jan 6, 2025
@bnubald bnubald self-assigned this Jan 6, 2025
@bnubald bnubald changed the title Edge case error: Daily prediction generation New year edge case error: Daily prediction generation Jan 6, 2025
bnubald added a commit to bnubald/icenet-pipeline that referenced this issue Jan 6, 2025
bnubald added a commit to bnubald/icenet-pipeline that referenced this issue Jan 6, 2025
bnubald added a commit that referenced this issue Jan 6, 2025
Fix #57: Check if ERA5 nc file for this year exists, else, use latest date from prev year
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant