# How to extract number of time steps in data?

**URL:** <https://forum.ecmwf.int/t/how-to-extract-number-of-time-steps-in-data/1804>\
**Category:** Other - Software and tools\
**Tags:** c3s, toolbox\
**Created:** [22 March 2022 11:47 UTC](https://forum.ecmwf.int/t/how-to-extract-number-of-time-steps-in-data/1804 "2022-03-22T11:47:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerald\_Lohmann](https://forum.ecmwf.int/letter_avatar_proxy/v4/letter/g/a183cd/32.png) [@Gerald\_Lohmann](https://forum.ecmwf.int/u/Gerald_Lohmann)\
**Post date:** [22 March 2022 11:47 UTC](https://forum.ecmwf.int/t/how-to-extract-number-of-time-steps-in-data/1804/1 "2022-03-22T11:47:39Z")

</div>

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 = ???
```

---

<div class="post-metadata">

**Author:** ![Eduardo\_Penabad](https://forum.ecmwf.int/letter_avatar_proxy/v4/letter/e/6a8cbe/32.png) [@Eduardo\_Penabad](https://forum.ecmwf.int/u/Eduardo_Penabad)\
**Post date:** [22 March 2022 12:57 UTC](https://forum.ecmwf.int/t/how-to-extract-number-of-time-steps-in-data/1804/2 "2022-03-22T12:57:18Z")

</div>

Have you tried ct.cdm.get\_coordinates()?  
  
 For instance:

```
coords = ct.cdm.get_coordinates(data)
nDay = len(coords['time']['data'])
```

---

<div class="post-metadata">

**Author:** ![Gerald\_Lohmann](https://forum.ecmwf.int/letter_avatar_proxy/v4/letter/g/a183cd/32.png) [@Gerald\_Lohmann](https://forum.ecmwf.int/u/Gerald_Lohmann)\
**Post date:** [22 March 2022 13:04 UTC](https://forum.ecmwf.int/t/how-to-extract-number-of-time-steps-in-data/1804/3 "2022-03-22T13:04:13Z")

</div>

Amazing! I had looked for such a long time but did not figure this out. Thank you very much - it works like a charm.
