Skip to content

Commit

Permalink
Make time-series scripts use timeseries_yr1 & 2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xylar committed Nov 28, 2016
1 parent e30389f commit 7cf12f9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
19 changes: 11 additions & 8 deletions mpas_analysis/ocean/ohc_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

from ..shared.io import NameList, StreamsFile

from ..shared.timekeeping.Date import Date

def ohc_timeseries(config):
"""
Performs analysis of ocean heat content (OHC) from time-series output.
Author: Xylar Asay-Davis, Milena Veneziani
Last Modified: 11/25/2016
Last Modified: 11/28/2016
"""

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

yr_offset = config.getint('time','yr_offset')
timeseries_yr1 = yr_offset + config.getint('time', 'timeseries_yr1')
timeseries_yr2 = yr_offset + config.getint('time', 'timeseries_yr2')

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

Expand Down Expand Up @@ -90,14 +90,17 @@ def ohc_timeseries(config):

ds = remove_repeated_time_index(ds)

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

# Select year-1 data and average it (for later computing anomalies)
time_start = datetime.datetime(timeseries_yr1, 1, 1)
time_end = datetime.datetime(timeseries_yr1, 12, 31)
time_start = datetime.datetime(time_start.year, 1, 1)
time_end = datetime.datetime(time_start.year, 12, 31)
ds_yr1 = ds.sel(Time=slice(time_start,time_end))
mean_yr1 = ds_yr1.mean('Time')

Expand Down
12 changes: 11 additions & 1 deletion mpas_analysis/ocean/sst_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

from ..shared.io import StreamsFile

from ..shared.timekeeping.Date import Date

def sst_timeseries(config):
"""
Performs analysis of the time-series output of sea-surface temperature
(SST).
Author: Xylar Asay-Davis, Milena Veneziani
Last Modified: 10/27/2016
Last Modified: 11/28/2016
"""
# Define/read in general variables
print " Load SST data..."
Expand Down Expand Up @@ -55,6 +57,14 @@ def sst_timeseries(config):
onlyvars=['time_avg_avgValueWithinOceanRegion_avgSurfaceTemperature']))
ds = remove_repeated_time_index(ds)

# convert the start and end dates to datetime objects using
# the Date class, which ensures the results are within the
# supported range
time_start = Date(startDate).to_datetime(yr_offset)
time_end = Date(endDate).to_datetime(yr_offset)
# select only the data in the specified range of years
ds = ds.sel(Time=slice(time_start, time_end))

SSTregions = ds.time_avg_avgValueWithinOceanRegion_avgSurfaceTemperature

year_start = (pd.to_datetime(ds.Time.min().values)).year
Expand Down
12 changes: 11 additions & 1 deletion mpas_analysis/sea_ice/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
from ..shared.io import StreamsFile
from ..shared.io.utility import paths

from ..shared.timekeeping.Date import Date

def seaice_timeseries(config):
"""
Performs analysis of time series of sea-ice properties.
Author: Xylar Asay-Davis, Milena Veneziani
Last Modified: 10/27/2016
Last Modified: 11/28/2016
"""

# read parameters from config file
Expand Down Expand Up @@ -79,6 +81,14 @@ def seaice_timeseries(config):
'timeSeriesStatsMonthly_avg_iceVolumeCell_1']))
ds = remove_repeated_time_index(ds)

# convert the start and end dates to datetime objects using
# the Date class, which ensures the results are within the
# supported range
time_start = Date(startDate).to_datetime(yr_offset)
time_end = Date(endDate).to_datetime(yr_offset)
# select only the data in the specified range of years
ds = ds.sel(Time=slice(time_start, time_end))

ds = ds.merge(dsmesh)

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

0 comments on commit 7cf12f9

Please sign in to comment.