-
Notifications
You must be signed in to change notification settings - Fork 52
Update date type handling in mpas_xarray #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ dependencies: | |
- lxml | ||
- xarray | ||
- matplotlib | ||
- dask |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,10 +63,10 @@ def ocn_modelvsobs(config, field): | |
if field.lower() == 'mld': | ||
obs_filename = "%s/holtetalley_mld_climatology.nc" % obsdir | ||
|
||
ds = xr.open_mfdataset(infiles, preprocess=lambda x: preprocess_mpas(x, yearoffset=yr_offset, | ||
timeSeriesStats=True, | ||
timestr='time_avg_daysSinceStartOfSim', | ||
onlyvars=['time_avg_dThreshMLD'])) | ||
ds = xr.open_mfdataset(infiles, preprocess=lambda x: | ||
preprocess_mpas(x, yearoffset=yr_offset, | ||
timestr=['xtime_start', 'xtime_end'], | ||
onlyvars=['time_avg_dThreshMLD'])) | ||
ds = remove_repeated_time_index(ds) | ||
ds.rename({'time_avg_dThreshMLD':'mpasData'}, inplace = True) | ||
|
||
|
@@ -93,11 +93,11 @@ def ocn_modelvsobs(config, field): | |
|
||
elif field.lower() == 'sst': | ||
|
||
ds = xr.open_mfdataset(infiles, preprocess=lambda x: preprocess_mpas(x, yearoffset=yr_offset, | ||
timeSeriesStats=True, | ||
timestr='time_avg_daysSinceStartOfSim', | ||
onlyvars=['time_avg_activeTracers_temperature'], | ||
selvals={'nVertLevels':1})) | ||
ds = xr.open_mfdataset(infiles, preprocess=lambda x: | ||
preprocess_mpas(x, yearoffset=yr_offset, | ||
timestr=['xtime_start', 'xtime_end'], | ||
onlyvars=['time_avg_activeTracers_temperature'], | ||
selvals={'nVertLevels':1})) | ||
ds = remove_repeated_time_index(ds) | ||
ds.rename({'time_avg_activeTracers_temperature':'mpasData'}, inplace = True) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make things backward compatible, it seems like we need a list of options for the timestr variable as well: did you want to handle this in the specific PR that will address #20? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @milenaveneziani, yes that's exactly right. What I realized in the process of making this PR is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Yes, this is backwards compatible at least back to alpha7. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ def ohc_timeseries(config): | |
Performs analysis of ocean heat content (OHC) from time-series output. | ||
|
||
Author: Xylar Asay-Davis, Milena Veneziani | ||
Last Modified: 10/26/2016 | ||
Last Modified: 11/25/2016 | ||
""" | ||
|
||
# read parameters from config file | ||
|
@@ -50,6 +50,8 @@ 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') | ||
|
||
|
@@ -75,20 +77,27 @@ def ohc_timeseries(config): | |
|
||
# Load data | ||
print " Load ocean data..." | ||
ds = xr.open_mfdataset(infiles, preprocess=lambda x: preprocess_mpas(x, yearoffset=yr_offset, | ||
timeSeriesStats=True, | ||
timestr='time_avg_daysSinceStartOfSim', | ||
onlyvars=['time_avg_avgValueWithinOceanLayerRegion_avgLayerTemperature', | ||
'time_avg_avgValueWithinOceanLayerRegion_sumLayerMaskValue', | ||
'time_avg_avgValueWithinOceanLayerRegion_avgLayerArea', | ||
'time_avg_avgValueWithinOceanLayerRegion_avgLayerThickness'])) | ||
|
||
varList = ['time_avg_avgValueWithinOceanLayerRegion_avgLayerTemperature', | ||
'time_avg_avgValueWithinOceanLayerRegion_sumLayerMaskValue', | ||
'time_avg_avgValueWithinOceanLayerRegion_avgLayerArea', | ||
'time_avg_avgValueWithinOceanLayerRegion_avgLayerThickness'] | ||
ds = xr.open_mfdataset(infiles, | ||
preprocess=lambda x: | ||
preprocess_mpas(x, | ||
yearoffset=yr_offset, | ||
timestr=['xtime_start','xtime_end'], | ||
onlyvars=varList)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice cleaning up! |
||
|
||
ds = remove_repeated_time_index(ds) | ||
|
||
# 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)) | ||
|
||
# Select year-1 data and average it (for later computing anomalies) | ||
time_start = datetime.datetime(yr_offset+1,1,1) | ||
time_end = datetime.datetime(yr_offset+1,12,31) | ||
time_start = datetime.datetime(timeseries_yr1, 1, 1) | ||
time_end = datetime.datetime(timeseries_yr1, 12, 31) | ||
ds_yr1 = ds.sel(Time=slice(time_start,time_end)) | ||
mean_yr1 = ds_yr1.mean('Time') | ||
|
||
|
@@ -107,7 +116,8 @@ def ohc_timeseries(config): | |
if ref_casename_v0 != "None": | ||
print " Load in OHC for ACMEv0 case..." | ||
infiles_v0data = "".join([indir_v0data,'/OHC.',ref_casename_v0,'.year*.nc']) | ||
ds_v0 = xr.open_mfdataset(infiles_v0data,preprocess=lambda x: preprocess_mpas(x, yearoffset=yr_offset)) | ||
ds_v0 = xr.open_mfdataset(infiles_v0data, preprocess=lambda x: | ||
preprocess_mpas(x, yearoffset=yr_offset)) | ||
ds_v0 = remove_repeated_time_index(ds_v0) | ||
ds_v0_tslice = ds_v0.sel(Time=slice(time_start,time_end)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize that splitting the
lambda x:
andprocess_mpas(...
lines here and elsewhere is not optimal. I have not found a more elegant solution that is PEP8 compliant.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to find one either @xylar. The way you have done this is much clearer so this is great forward progress we all should be very happy about. Thanks for taking another look.