ESMValGroup / ESMValCore

ESMValCore: A community tool for pre-processing data from Earth system models in CMIP and running analysis scripts.
https://www.esmvaltool.org
Apache License 2.0
42 stars 38 forks source link

`clip_timerange` gives the wrong end date if ending not on the 31st of December #2489

Open malininae opened 4 months ago

malininae commented 4 months ago

While working on #2304, I've discovered that clip_timerange would give you a wrong end date if the end_day and end_month aren't the 31st of December. Example, I need to process ERA5 data for the current year which ends on the 18th of July of 2024. Out of fun I'm passing the 17th of July 2024 as an end date, example:

documentation:
  title: test extract_time.
  description: test extract_time.
  authors:
  - malinina_elizaveta

preprocessors:  
  preproc_regions:
    custom_order: true
    extract_time:
        start_year: 2024
        start_month: 3
        start_day: 1
        end_year: 2024
        end_month: 7
        end_day: 14
    convert_units:
      units: degrees_C

datasets:
- dataset: ERA5
  project: OBS6
  type: reanaly
  version: v1
  tier: 3

diagnostics:
  heatwave:
    description: just a test
    variables:
      current:
        short_name: tasmax
        start_year: 2024
        start_month: 1
        start_day: 1
        end_year: 2024
        end_month: 7
        end_day: 17
        mip: day
        preprocessor: preproc_regions
    scripts: null

Now, what I would expect, the cube to be cropped to 2024-01-01 - 2024-07-17, but because the timerange that gets passed into the clip_timerange(cube: Cube, timerange: str) is 2024/2024, the cube gets to be clipped to 2024-01-01 - 2025-01-01. While I can see that the described use case might be more on a rare side, I think it's still important to be fixed.

Pinging @bouweandela, since he wrote a bunch of time preprocessors.

bouweandela commented 4 months ago

You can achieve this with something like:

documentation:
  title: test extract_time.
  description: test extract_time.
  authors:
  - malinina_elizaveta

preprocessors:  
  preproc_regions:
    custom_order: true
    convert_units:
      units: degrees_C

datasets:
- dataset: ERA5
  project: OBS6
  type: reanaly
  version: v1
  tier: 3

diagnostics:
  heatwave:
    description: just a test
    variables:
      current:
        short_name: tasmax
        timerange: '20240102/20240717'
        mip: day
        preprocessor: preproc_regions
    scripts: null

See here and here https://github.com/ESMValGroup/ESMValCore/issues/2048 for more information.