From 3c52f04dbbf2e7bca6b7da8e919a1769f5326fd8 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Mon, 28 Nov 2016 06:45:45 -0800 Subject: [PATCH] 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. --- mpas_analysis/ocean/ohc_timeseries.py | 19 +++++++++++-------- mpas_analysis/ocean/sst_timeseries.py | 12 +++++++++++- mpas_analysis/sea_ice/timeseries.py | 12 +++++++++++- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/mpas_analysis/ocean/ohc_timeseries.py b/mpas_analysis/ocean/ohc_timeseries.py index e948faeaf..12983d586 100644 --- a/mpas_analysis/ocean/ohc_timeseries.py +++ b/mpas_analysis/ocean/ohc_timeseries.py @@ -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 @@ -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') @@ -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') diff --git a/mpas_analysis/ocean/sst_timeseries.py b/mpas_analysis/ocean/sst_timeseries.py index f8749d932..b705713f1 100644 --- a/mpas_analysis/ocean/sst_timeseries.py +++ b/mpas_analysis/ocean/sst_timeseries.py @@ -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..." @@ -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 diff --git a/mpas_analysis/sea_ice/timeseries.py b/mpas_analysis/sea_ice/timeseries.py index e26011590..3ffac1168 100644 --- a/mpas_analysis/sea_ice/timeseries.py +++ b/mpas_analysis/sea_ice/timeseries.py @@ -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 @@ -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