pythonmeanpython-xarray

How to get season as JJAS instead of JJA in xarray?


How to get monsoon months (JJAS) in xarray while calculating seasonal mean instead of JJA?

import xarray as xr
fname='/home/krishna/SIMS/P1/*.nc'
ds=xr.open_mfdataset(fname)
temp=ds.temp
sea_temp=temp.groupby('time.season').mean(dim='time')
sea_temp.plot.imshow(col='season',robust=True)

the output shows in JJA month instead of JJAS. How can I calculate seasonal mean for JJAS (June-September)


Solution

  • I could resolve this issue by writing a function as follows

    def is_jjas(month):
        return (month >= 6) & (month <= 9)
    
    seasonal_temp = temp.sel(time=is_jjas(temp['time.month']))
    

    I hope this will help someone who has the same doubt doing seasonal mean for the Indian summer monsoon season (JJAS).