Hello everyone!

I would like to automatically extract the number of data in the time dimension, i.e. to know how many "observations" there are in my retrieved data set. This ought to be a simple no-brainer, but I do not seem to be able to find the appropriate way to do this in the toolbox...

Does anyone know how to tackle the issue?

Cheers,
Gerald

Here's a MWE:

import cdstoolbox as ct
@ct.application(title='MWE')
def application():
    data = ct.catalogue.retrieve(
        'reanalysis-era5-single-levels',
        {
            'variable': '2m_temperature',
            'product_type': 'reanalysis',
            'year': '2020',
            'month': '02',
            'day': [
                '01', '02', '03',
                '04', '05', '06',
                '07', '08', '09',
                '10', '11', '12',
                '13', '14', '15',
                '16', '17', '18',
                '19', '20', '21',
                '22', '23', '24',
                '25', '26', '27',
                '28', '29', '30',
                '31',
            ],
            'time': '12:00',
        }
    )
    
# Of course, the number is being shown in the info when I print(data)...
    print(data)

  # But how to extract the number as a simple integer? (It's 29 in this example)
    # nDay = ???

2 Comments

  1. Have you tried ct.cdm.get_coordinates()?

    For instance:

    coords = ct.cdm.get_coordinates(data)
    nDay = len(coords['time']['data'])
    1. Amazing! I had looked for such a long time but did not figure this out. Thank you very much - it works like a charm.