Skip to content

Commit

Permalink
preserve attributes in seasonal mean when working with climo files
Browse files Browse the repository at this point in the history
  • Loading branch information
brianpm committed Dec 21, 2023
1 parent a38a23b commit d841890
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/plotting_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,14 @@ def seasonal_mean(data, season=None, is_climo=None):
time_dim_num = data.shape.index(12)
fakedims = [f"dim{n}" for n in range(len(data.shape))]
fakedims[time_dim_num] = "time"
data = xr.DataArray(data, dims=fakedims)
data = xr.DataArray(data, dims=fakedims, attrs=data.attrs)
timefix = pd.date_range(start='1/1/1999', end='12/1/1999', freq='MS') # generic time coordinate from a non-leap-year
data = data.assign_coords({"time":timefix})
month_length = data.time.dt.days_in_month
#End try/except

data = data.sel(time=data.time.dt.month.isin(seasons[season])) # directly take the months we want based on season kwarg
return data.weighted(data.time.dt.daysinmonth).mean(dim='time')
return data.weighted(data.time.dt.daysinmonth).mean(dim='time', keep_attrs=True)



Expand Down

0 comments on commit d841890

Please sign in to comment.