Skip to content

Commit e1b0d64

Browse files
committed
Make time-series scripts use timeseries_yr1 & 2
This merge updates the 3 time-series analysis scripts to make use of the time series start and end dates, computed via timeseries_yr1 and timeseries_yr2, allowing analysis of a subset of the output data.
1 parent d4c0a98 commit e1b0d64

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

mpas_analysis/ocean/ohc_timeseries.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
from ..shared.io import NameList, StreamsFile
1313

14+
from ..shared.timekeeping.Date import Date
15+
1416
def ohc_timeseries(config):
1517
"""
1618
Performs analysis of ocean heat content (OHC) from time-series output.
1719
1820
Author: Xylar Asay-Davis, Milena Veneziani
19-
Last Modified: 11/25/2016
21+
Last Modified: 11/28/2016
2022
"""
2123

2224
# read parameters from config file
@@ -50,8 +52,6 @@ def ohc_timeseries(config):
5052
plots_dir = config.get('paths','plots_dir')
5153

5254
yr_offset = config.getint('time','yr_offset')
53-
timeseries_yr1 = yr_offset + config.getint('time', 'timeseries_yr1')
54-
timeseries_yr2 = yr_offset + config.getint('time', 'timeseries_yr2')
5555

5656
N_movavg = config.getint('ohc_timeseries','N_movavg')
5757

@@ -90,14 +90,17 @@ def ohc_timeseries(config):
9090

9191
ds = remove_repeated_time_index(ds)
9292

93+
# convert the start and end dates to datetime objects using
94+
# the Date class, which ensures the results are within the
95+
# supported range
96+
time_start = Date(startDate).to_datetime(yr_offset)
97+
time_end = Date(endDate).to_datetime(yr_offset)
9398
# select only the data in the specified range of years
94-
# time_start = datetime.datetime(timeseries_yr1, 1, 1)
95-
# time_end = datetime.datetime(timeseries_yr2, 12, 31)
96-
# ds = ds.sel(Time=slice(time_start, time_end))
99+
ds = ds.sel(Time=slice(time_start, time_end))
97100

98101
# Select year-1 data and average it (for later computing anomalies)
99-
time_start = datetime.datetime(timeseries_yr1, 1, 1)
100-
time_end = datetime.datetime(timeseries_yr1, 12, 31)
102+
time_start = datetime.datetime(time_start.year, 1, 1)
103+
time_end = datetime.datetime(time_start.year, 12, 31)
101104
ds_yr1 = ds.sel(Time=slice(time_start,time_end))
102105
mean_yr1 = ds_yr1.mean('Time')
103106

mpas_analysis/ocean/sst_timeseries.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99

1010
from ..shared.io import StreamsFile
1111

12+
from ..shared.timekeeping.Date import Date
13+
1214
def sst_timeseries(config):
1315
"""
1416
Performs analysis of the time-series output of sea-surface temperature
1517
(SST).
1618
1719
Author: Xylar Asay-Davis, Milena Veneziani
18-
Last Modified: 10/27/2016
20+
Last Modified: 11/28/2016
1921
"""
2022
# Define/read in general variables
2123
print " Load SST data..."
@@ -55,6 +57,14 @@ def sst_timeseries(config):
5557
onlyvars=['time_avg_avgValueWithinOceanRegion_avgSurfaceTemperature']))
5658
ds = remove_repeated_time_index(ds)
5759

60+
# convert the start and end dates to datetime objects using
61+
# the Date class, which ensures the results are within the
62+
# supported range
63+
time_start = Date(startDate).to_datetime(yr_offset)
64+
time_end = Date(endDate).to_datetime(yr_offset)
65+
# select only the data in the specified range of years
66+
ds = ds.sel(Time=slice(time_start, time_end))
67+
5868
SSTregions = ds.time_avg_avgValueWithinOceanRegion_avgSurfaceTemperature
5969

6070
year_start = (pd.to_datetime(ds.Time.min().values)).year

mpas_analysis/sea_ice/timeseries.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
from ..shared.io import StreamsFile
1212
from ..shared.io.utility import paths
1313

14+
from ..shared.timekeeping.Date import Date
15+
1416
def seaice_timeseries(config):
1517
"""
1618
Performs analysis of time series of sea-ice properties.
1719
1820
Author: Xylar Asay-Davis, Milena Veneziani
19-
Last Modified: 10/27/2016
21+
Last Modified: 11/28/2016
2022
"""
2123

2224
# read parameters from config file
@@ -79,6 +81,14 @@ def seaice_timeseries(config):
7981
'timeSeriesStatsMonthly_avg_iceVolumeCell_1']))
8082
ds = remove_repeated_time_index(ds)
8183

84+
# convert the start and end dates to datetime objects using
85+
# the Date class, which ensures the results are within the
86+
# supported range
87+
time_start = Date(startDate).to_datetime(yr_offset)
88+
time_end = Date(endDate).to_datetime(yr_offset)
89+
# select only the data in the specified range of years
90+
ds = ds.sel(Time=slice(time_start, time_end))
91+
8292
ds = ds.merge(dsmesh)
8393

8494
year_start = (pd.to_datetime(ds.Time.min().values)).year

0 commit comments

Comments
 (0)