# Annualising ACCESS-ESM Past 1000 data over tropical years while in a Gregorian Calendar Format

**URL:** https://forum.access-hive.org.au/t/annualising-access-esm-past-1000-data-over-tropical-years-while-in-a-gregorian-calendar-format/1739
**Category:** Technical
**Tags:** python
**Created:** [22 January 2024 02:54 UTC](https://forum.access-hive.org.au/t/annualising-access-esm-past-1000-data-over-tropical-years-while-in-a-gregorian-calendar-format/1739 "2024-01-22T02:54:33Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![bridgetleibold](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@bridgetleibold](https://forum.access-hive.org.au/u/bridgetleibold)
#### Post date: [22 January 2024 02:54 UTC](https://forum.access-hive.org.au/t/annualising-access-esm-past-1000-data-over-tropical-years-while-in-a-gregorian-calendar-format/1739/1 "2024-01-22T02:54:33Z")

</div>

Hi All,

I been having a problem when trying to annualise precipitation, sea surface temperature and sea level pressure data from ACCESS-ESM Past 1000 over tropical years (which I define as May 1 to April 30). I am having this problem because the data are stored in a Gregorian calendar format (Year-Month-Day-Hour-Minute-Second).

I have used numpy functions to annualise other data over tropical years (by using defining a function called tropical year where months prior to may return the year - 1, and months after may return the year), but I cannot use these functions with the ACCESS-ESM Past 1000 data because of the Gregorian format (and the fact that I can’t extract the year and month within the format).

Does anyone have any ideas on how I could annualise over tropical years from Gregorian format data?

Thank you in advance for your help!

---

<div class="post-metadata">

### Author: ![atteggiani](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/atteggiani/32/212_2.png) [@atteggiani](https://forum.access-hive.org.au/u/atteggiani)
#### Post date: [22 January 2024 03:20 UTC](https://forum.access-hive.org.au/t/annualising-access-esm-past-1000-data-over-tropical-years-while-in-a-gregorian-calendar-format/1739/2 "2024-01-22T03:20:17Z")

</div>

Hi @bridgetleibold, welcome to ACCESS-Hive forum!

In general, using the function you defined (months prior to may return `year - 1`, and months after may return `year`) you should be able to convert your data to annual data, regardless of the Gregorian calendar.  
If your data has a _Year-Month-…_ format, as you said, you should be able to extract those _Year_ and _Month_ values to apply your defined function.

Can you please provide a few more details of the function / data you are using?  
Maybe try providing a link to both data and python script (or function) you are currently using, so we can better help you.

Cheers  
Davide

---

<div class="post-metadata">

### Author: ![bridgetleibold](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@bridgetleibold](https://forum.access-hive.org.au/u/bridgetleibold)
#### Post date: [22 January 2024 03:32 UTC](https://forum.access-hive.org.au/t/annualising-access-esm-past-1000-data-over-tropical-years-while-in-a-gregorian-calendar-format/1739/3 "2024-01-22T03:32:47Z")

</div>

Hi Davide - thanks for having a look at this.

The link to the working file is: g/data/v45/bl2788/working ENSO response to eruptions.ipynb

the link to the data is: g/data/v45/bl2788/PMIP4data (within the PMIP4data folder are three variables folders each with 10 files I combined and used in the working file)

I am aiming to adapt the technique I used in: g/data/v45/bl2788/15 Jan working Identify Eruptions.ipynb (which the code for is under the heading ‘annualise the monthly data over tropical years’).

Thank you so much again for your help!

---

<div class="post-metadata">

### Author: ![atteggiani](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/atteggiani/32/212_2.png) [@atteggiani](https://forum.access-hive.org.au/u/atteggiani)
#### Post date: [23 January 2024 00:50 UTC](https://forum.access-hive.org.au/t/annualising-access-esm-past-1000-data-over-tropical-years-while-in-a-gregorian-calendar-format/1739/4 "2024-01-23T00:50:54Z")

</div>

Hi @bridgetleibold ,

Thank you for sharing the working script and data.  
Unfortunately, I have not access to the `v45` project (I requested access but still haven’t been granted).

To speed up the process, would you be able to copy the working script in `/scratch/public`? Maybe you can create a folder with your username there.

If the data is not too big, please copy it as well (even just one variable), otherwise I will still try to understand it based on the working script.

Thank you  
Davide

---

<div class="post-metadata">

### Author: ![Scott](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/scott/32/37_2.png) [@Scott](https://forum.access-hive.org.au/u/Scott)
#### Post date: [23 January 2024 22:38 UTC](https://forum.access-hive.org.au/t/annualising-access-esm-past-1000-data-over-tropical-years-while-in-a-gregorian-calendar-format/1739/5 "2024-01-23T22:38:22Z")

</div>

Are you wanting the annual mean using your tropical year definition? You can add a custom coordinate and group over that, `where()` is a nice function to use here:

```python
path = "/g/data/fs38/publications/CMIP6/PMIP/CSIRO/ACCESS-ESM1-5/past1000/r1i1p1f1/Amon/tas/gn/latest/tas_Amon_ACCESS-ESM1-5_past1000_r1i1p1f1_gn_*.nc"
ds = xarray.open_mfdataset(path, use_cftime=True, chunks={'time': 100})

def tropical_year(dates):
    # Returns year - 1 when month is before May
    return xarray.where(dates.dt.month < 5, dates.dt.year - 1, dates.dt.year)

# Add a custom coordinate to the data
ds.coords['tropical_year'] = tropical_year(ds.time)

# Group by the custom coordinate and mean
tropical_mean = ds.groupby('tropical_year').mean()

tropical_mean.to_netcdf(Path(os.environ['TMPDIR'])/'tropical_mean.nc')

```

---

<div class="post-metadata">

### Author: ![bridgetleibold](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@bridgetleibold](https://forum.access-hive.org.au/u/bridgetleibold)
#### Post date: [1 February 2024 23:48 UTC](https://forum.access-hive.org.au/t/annualising-access-esm-past-1000-data-over-tropical-years-while-in-a-gregorian-calendar-format/1739/6 "2024-02-01T23:48:02Z")

</div>

Hi Scott, this has worked perfectly. Thank you so much for your help  
Thanks, Bridget
