Interpolate to nearest hour when time is only slightly offset
- Dominant language
- Python
- Stars
- 33
- Forks
- 19
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 30
Description
```
ValueError: Constraint doesn't produce single cube. ConstraintCombination(ConstraintCombination(ConstraintCombination(ConstraintCombination(Constraint(), Constraint(name='air_temperature'), ), Constraint(cube_func=.check_cell_methods at 0x7f82d8fc4cc0>), ), Constraint(cube_func=.no_pressure_coordinate at 0x7f82d8fc4e00>), ), Constraint(coord_values={'time': . at 0x7f82d8fc4ea0>}), )
< No cubes >
```
The error is quite obvious, and I am wondering whether it is due to the time constraint. For example, in **_job.err_**, you can see the variables defined to produce the constraints:
`024-05-27 02:44:52,706 DEBUG Recipe variables: {'VARNAME': 'air_temperature', 'VALIDITY_TIME': '20220716T0000Z'}`
However, the first model output of the data is offset by +12 seconds, which corresponds to the first model time step. This can be verified on an interactive python interpreter session:
```
...
>>> print(cb)
air_temperature / (K) (time: 13; grid_latitude: 1250; grid_longitude: 1800)
Dimension coordinates:
time x - -
grid_latitude - x -
grid_longitude - - x
Auxiliary coordinates:
forecast_period x - -
Scalar coordinates:
forecast_reference_time 2022-07-16 00:00:00
height 1.5 m
Attributes:
STASH m01s03i236
source 'Data from Met Office Unified Model'
um_version '13.0'
>>> cube_dt = cf_units.num2date(cb.coord('time').points, cb.coord('time').units.name, calendar='standard')
>>> cube_dt
array([cftime.DatetimeGregorian(2022, 7, 16, 0, 0, 12, 0, has_year_zero=False),
cftime.DatetimeGregorian(2022, 7, 16, 1, 0, 0, 0, has_year_zero=False),
...
```
If this (time offset) indeed is the case, an option is to interpolate to the nearest hour.
_Originally posted by @vinodk-bom in https://github.com/MetOffice/CSET/issues/472#issuecomment-2132556048_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the constraint-generation path that uses VALIDITY_TIME and reproduce the failure from job.err against a cube whose first time is 12 seconds late. Check how the time constraint handles that offset and define done as selecting the intended hourly data without the “No cubes” error, with a regression test for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100