You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ERA5 replica collection at the National Computing Infrastructure down here in Australia stores monthly-averaged variable in multiple files, one file per month.
---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)
CellIn[56], line1---->1cube=tas.load()
File [/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/dataset.py:685](https://are.nci.org.au/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/dataset.py#line=684), in Dataset.load(self)682input_files.extend(supplementary_dataset.files)
683esgf.download(input_files, self.session['download_dir'])
-->685cube=self._load()
686supplementary_cubes= []
687forsupplementary_datasetinself.supplementaries:
File [/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/dataset.py:771](https://are.nci.org.au/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/dataset.py#line=770), in Dataset._load(self)766result= [
767file.local_file(self.session['download_dir']) ifisinstance(
768file, esgf.ESGFFile) elsefileforfileinself.files769 ]
770forstep, kwargsinsettings.items():
-->771result=preprocess(
772result,
773step,
774input_files=self.files,
775output_file=output_file,
776debug=self.session['save_intermediary_cubes'],
777**kwargs,
778 )
780cube=result[0]
781returncubeFile [/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/preprocessor/__init__.py:397](https://are.nci.org.au/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/preprocessor/__init__.py#line=396), in preprocess(items, step, input_files, output_file, debug, **settings)395result= []
396ifitype.endswith('s'):
-->397result.append(_run_preproc_function(function, items, settings,
398input_files=input_files))
399else:
400foriteminitems:
File [/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/preprocessor/__init__.py:346](https://are.nci.org.au/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/preprocessor/__init__.py#line=345), in _run_preproc_function(function, items, kwargs, input_files)341logger.debug(
342"Running preprocessor function '%s' on the data\n%s%s\nwith function "343"argument(s)\n%s", function.__name__, pformat(items), file_msg,
344kwargs_str)
345try:
-->346returnfunction(items, **kwargs)
347exceptException:
348# To avoid very long error messages, we truncate the arguments and349# input files here at a given threshold350n_shown_args=4File [/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/cmor/fix.py:195](https://are.nci.org.au/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/cmor/fix.py#line=194), in fix_metadata(cubes, short_name, project, dataset, mip, frequency, check_level, session, **extra_facets)193cube_list=CubeList(cube_list)
194forfixinfixes:
-->195cube_list=fix.fix_metadata(cube_list)
197# The final fix is always GenericFix, whose fix_metadata method always198# returns a single cube199cube=cube_list[0]
File [/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/cmor/_fixes/native6/era5.py:424](https://are.nci.org.au/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/cmor/_fixes/native6/era5.py#line=423), in AllVars.fix_metadata(self, cubes)421cube.standard_name=self.vardef.standard_name422cube.long_name=self.vardef.long_name-->424cube=self._fix_coordinates(cube)
425self._fix_units(cube)
427cube.data=cube.core_data().astype('float32')
File [/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/cmor/_fixes/native6/era5.py:389](https://are.nci.org.au/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/cmor/_fixes/native6/era5.py#line=388), in AllVars._fix_coordinates(self, cube)385if (notcoord.has_bounds() andlen(coord.core_points()) >1386andcoord_def.must_have_bounds=="yes"):
387coord.guess_bounds()
-->389self._fix_monthly_time_coord(cube)
391returncubeFile [/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/cmor/_fixes/native6/era5.py:396](https://are.nci.org.au/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/cmor/_fixes/native6/era5.py#line=395), in AllVars._fix_monthly_time_coord(cube)393 @staticmethod394def_fix_monthly_time_coord(cube):
395"""Set the monthly time coordinates to the middle of the month."""-->396ifget_frequency(cube) =='monthly':
397coord=cube.coord(axis='T')
398end= []
File [/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/cmor/_fixes/native6/era5.py:27](https://are.nci.org.au/g/data/xp65/public/apps/med_conda/envs/esmvaltool-0.4/lib/python3.11/site-packages/esmvalcore/cmor/_fixes/native6/era5.py#line=26), in get_frequency(cube)25iflen(time.points) ==1:
26ifcube.long_name!='Geopotential':
--->27raiseValueError('Unable to infer frequency of cube '28f'with length 1 time dimension: {cube}')
29return'fx'31interval=time.points[1] -time.points[0]
ValueError: Unabletoinferfrequencyofcubewithlength1timedimension: air_temperature [/](https://are.nci.org.au/) (K) (time: 1; latitude: 721; longitude: 1440)
Dimensioncoordinates:
timex--latitude-x-longitude--xScalarcoordinates:
height2.0mAttributes:
Conventions'CF-1.6'license'Licence to use Copernicus Products: https://apps.ecmwf.int/datasets/li ...'source_file'/g/data/rt52/era5/single-levels/monthly-averaged/2t/1959/2t_era5_moda_ ...'summary'ERA5 is the fifth generation ECMWF atmospheric reanalysis of the global ...'title'ERA5 single-levels monthly-averaged 2m_temperature 19590101-19590131'
As per trace above, the issue arises in the following lines:
raiseValueError('Unable to infer frequency of cube '
f'with length 1 time dimension: {cube}')
return'fx'
At that time, each cube from each NetCDF file has a time dimension length of 1 which raises the issue.
An easy fix is to rewrite the get_frequency variable to make it a bit more flexible:
defget_frequency(cube):
"""Determine time frequency of input cube."""try:
time=cube.coord(axis='T')
exceptiris.exceptions.CoordinateNotFoundError:
return'fx'time.convert_units('days since 1850-1-1 00:00:00.0')
if (len(time.points) ==1andcube.long_name=='Geopotential'):
return'fx'iflen(time.points) >1:
interval=time.points[1] -time.points[0]
ifinterval-1/24<1e-4:
return'hourly'return'monthly'
I will submit a PR to fix this.
The text was updated successfully, but these errors were encountered:
You might be able to use the frequency facet, which should be available in fixes, to figure out the frequency instead of looking at the data. That should avoid the problem that it's impossible compute an interval from a single time point.
Describe the bug
The ERA5 replica collection at the National Computing Infrastructure down here in Australia stores monthly-averaged variable in multiple files, one file per month.
Here is an example for the tas (tp) variable:
Using ESMValCore and the following code:
Produces the following error:
As per trace above, the issue arises in the following lines:
ESMValCore/esmvalcore/cmor/_fixes/native6/era5.py
Lines 25 to 29 in f969e82
At that time, each cube from each NetCDF file has a time dimension length of 1 which raises the issue.
An easy fix is to rewrite the
get_frequency
variable to make it a bit more flexible:I will submit a PR to fix this.
The text was updated successfully, but these errors were encountered: