Skip to content

Commit fe893b6

Browse files
committed
Fix start time in replicte_cycle for sea-ice data
This merge fixes the starting time of the replicate_cycle function used to repeat sea-ice climatology data sets. The start time was not correct if the comparison data set did not start at the same time as the first cycle of the repeated data set.
1 parent bbfc607 commit fe893b6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mpas_analysis/sea_ice/timeseries.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,14 @@ def replicate_cycle(ds, ds_toreplicate):
306306
dsshift = ds_toreplicate.copy()
307307
shiftT = ((dsshift.Time.max() - dsshift.Time.min()) +
308308
(dsshift.Time.isel(Time=1) - dsshift.Time.isel(Time=0)))
309-
nT = np.ceil((ds.Time.max() - ds.Time.min())/shiftT)
309+
startIndex = int(np.floor((ds.Time.min()-ds_toreplicate.Time.min())/shiftT))
310+
endIndex = int(np.ceil((ds.Time.max()-ds_toreplicate.Time.min())/shiftT))
311+
dsshift['Time'] = dsshift['Time'] + startIndex*shiftT
310312

311313
# replicate cycle:
312-
for i in np.arange(nT):
314+
for cycleIndex in range(startIndex, endIndex):
313315
dsnew = ds_toreplicate.copy()
314-
dsnew['Time'] = dsnew.Time + (i+1)*shiftT
316+
dsnew['Time'] = dsnew['Time'] + (cycleIndex+1)*shiftT
315317
dsshift = xr.concat([dsshift, dsnew], dim='Time')
316318
# constrict replicated ds_short to same time dimension as ds_long:
317319
dsshift = dsshift.sel(Time=ds.Time.values, method='nearest')

0 commit comments

Comments
 (0)