Skip to content

Commit

Permalink
Merge pull request #337 from xylar/ticks_in_config
Browse files Browse the repository at this point in the history
User-specified tick start and stride for time axes

A config file can now be used to specify firstYearXTicks and
yearStrideXTicks to control how ticks are set for a time axis.
  • Loading branch information
xylar authored Apr 24, 2018
2 parents 27bda72 + a916406 commit 5871157
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 19 deletions.
77 changes: 77 additions & 0 deletions mpas_analysis/config.default
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,14 @@ preprocessedFieldPrefix = ohc
# window)
movingAveragePoints = 12

# An optional first year for the tick marks on the x axis. Leare commented out
# to start at the beginning of the time series.
# firstYearXTicks = 1

# An optional number of years between tick marks on the x axis. Leave
# commented out to determine the distance between ticks automatically.
# yearStrideXTicks = 1

[hovmollerOHCAnomaly]
## options related to time vs. depth Hovmoller plots of ocean heat content
## (OHC) anomalies from year 1
Expand All @@ -344,6 +352,15 @@ colorbarLevels = [-2.4, -0.8, -0.4, -0.2, 0, 0.2, 0.4, 0.8, 2.4]
# contour line levels
contourLevels = np.arange(-2.5, 2.6, 0.5)

# An optional first year for the tick marks on the x axis. Leare commented out
# to start at the beginning of the time series.

# firstYearXTicks = 1

# An optional number of years between tick marks on the x axis. Leave
# commented out to determine the distance between ticks automatically.
# yearStrideXTicks = 1

[hovmollerTemperatureAnomaly]
## options related to plotting time series of temperature vs. depth

Expand All @@ -364,6 +381,16 @@ colorbarLevels = [-1, -0.5, -0.2, -0.05, 0, 0.05, 0.2, 0.5, 1]
# contour line levels
contourLevels = np.arange(-1.0, 1.26, 0.25)

# An optional first year for the tick marks on the x axis. Leare commented out
# to start at the beginning of the time series.

# firstYearXTicks = 1

# An optional number of years between tick marks on the x axis. Leave
# commented out to determine the distance between ticks automatically.

# yearStrideXTicks = 1

[hovmollerSalinityAnomaly]
## options related to plotting time series of salinity vs. depth

Expand All @@ -384,6 +411,16 @@ colorbarLevels = [-0.1, -0.02, -0.003, -0.001, 0, 0.001, 0.003, 0.02, 0.1]
# contour line levels
contourLevels = np.arange(-0.1, 0.11, 0.02)

# An optional first year for the tick marks on the x axis. Leare commented out
# to start at the beginning of the time series.

# firstYearXTicks = 1

# An optional number of years between tick marks on the x axis. Leave
# commented out to determine the distance between ticks automatically.

# yearStrideXTicks = 1

[timeSeriesSST]
## options related to plotting time series of sea surface temperature (SST)

Expand All @@ -396,6 +433,16 @@ regions = ['global']
# window)
movingAveragePoints = 12

# An optional first year for the tick marks on the x axis. Leare commented out
# to start at the beginning of the time series.

# firstYearXTicks = 1

# An optional number of years between tick marks on the x axis. Leave
# commented out to determine the distance between ticks automatically.

# yearStrideXTicks = 1

[indexNino34]
## options related to plotting time series of the El Nino 3.4 index

Expand Down Expand Up @@ -504,6 +551,16 @@ movingAveragePoints = 12
# latitude) for climatological MOC plots
movingAveragePointsClimatological = 1

# An optional first year for the tick marks on the x axis. Leare commented out
# to start at the beginning of the time series.

# firstYearXTicks = 1

# An optional number of years between tick marks on the x axis. Leave
# commented out to determine the distance between ticks automatically.

# yearStrideXTicks = 1

[timeSeriesSeaIceAreaVol]
## options related to plotting time series of sea ice area and volume

Expand All @@ -518,6 +575,16 @@ titleFontSize = 18
# plot on polar plot
polarPlot = False

# An optional first year for the tick marks on the x axis. Leare commented out
# to start at the beginning of the time series.

# firstYearXTicks = 1

# An optional number of years between tick marks on the x axis. Leave
# commented out to determine the distance between ticks automatically.

# yearStrideXTicks = 1

[climatologyMapSST]
## options related to plotting horizontally remapped climatologies of
## sea surface temperature (SST) against reference model results and
Expand Down Expand Up @@ -673,6 +740,16 @@ iceShelvesToPlot = ['Antarctica']
# Number of months over which to compute moving average
movingAverageMonths = 1

# An optional first year for the tick marks on the x axis. Leare commented out
# to start at the beginning of the time series.

# firstYearXTicks = 1

# An optional number of years between tick marks on the x axis. Leave
# commented out to determine the distance between ticks automatically.

# yearStrideXTicks = 1

[climatologyMapSoseTemperature]
## options related to plotting climatology maps of Antarctic
## potential temperature at various levels, including the sea floor against
Expand Down
2 changes: 1 addition & 1 deletion mpas_analysis/ocean/index_nino34.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ def _nino34_timeseries_plot(self, nino34s, title, panelTitles, outFileName,
minDays = time.min()
maxDays = time.max()

plot_xtick_format(plt, calendar, minDays, maxDays, maxXTicks)
plot_xtick_format(calendar, minDays, maxDays, maxXTicks)

plt.tight_layout(rect=[0, 0.03, 1, 0.90])

Expand Down
16 changes: 15 additions & 1 deletion mpas_analysis/ocean/plot_depth_integrated_time_series_subtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,25 @@ def run_task(self): # {{{
maxPoints.append(points[rangeIndex])
legendText.append(None)

if config.has_option(self.taskName, 'firstYearXTicks'):
firstYearXTicks = config.getint(self.taskName,
'firstYearXTicks')
else:
firstYearXTicks = None

if config.has_option(self.taskName, 'yearStrideXTicks'):
yearStrideXTicks = config.getint(self.taskName,
'yearStrideXTicks')
else:
yearStrideXTicks = None

timeseries_analysis_plot(config=config, dsvalues=timeSeries, N=None,
title=title, xlabel=xLabel, ylabel=yLabel,
fileout=figureName, lineStyles=lineStyles,
lineWidths=lineWidths, maxPoints=maxPoints,
legendText=legendText, calendar=calendar)
legendText=legendText, calendar=calendar,
firstYearXTicks=firstYearXTicks,
yearStrideXTicks=yearStrideXTicks)

write_image_xml(
config=config,
Expand Down
16 changes: 15 additions & 1 deletion mpas_analysis/ocean/plot_hovmoller_subtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,25 @@ def run_task(self): # {{{

figureName = '{}/{}.png'.format(self.plotsDirectory, self.filePrefix)

if config.has_option(self.sectionName, 'firstYearXTicks'):
firstYearXTicks = config.getint(self.sectionName,
'firstYearXTicks')
else:
firstYearXTicks = None

if config.has_option(self.sectionName, 'yearStrideXTicks'):
yearStrideXTicks = config.getint(self.sectionName,
'yearStrideXTicks')
else:
yearStrideXTicks = None

plot_vertical_section(config, Time, depth, field, self.sectionName,
suffix='', colorbarLabel=self.unitsLabel,
title=title, xlabel=xLabel, ylabel=yLabel,
fileout=figureName, linewidths=1,
xArrayIsTime=True, calendar=self.calendar)
xArrayIsTime=True, calendar=self.calendar,
firstYearXTicks=firstYearXTicks,
yearStrideXTicks=yearStrideXTicks)

write_image_xml(
config=config,
Expand Down
17 changes: 15 additions & 2 deletions mpas_analysis/ocean/streamfunction_moc.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def __init__(self, config, mpasClimatologyTask): # {{{
# -------
# Xylar Asay-Davis

#
# first, call the constructor from the base class (AnalysisTask)
super(StreamfunctionMOC, self).__init__(
config=config,
Expand Down Expand Up @@ -242,11 +241,25 @@ def run_task(self): # {{{

figureName = '{}/{}.png'.format(self.plotsDirectory, filePrefix)

if config.has_option(self.taskName, 'firstYearXTicks'):
firstYearXTicks = config.getint(self.taskName,
'firstYearXTicks')
else:
firstYearXTicks = None

if config.has_option(self.taskName, 'yearStrideXTicks'):
yearStrideXTicks = config.getint(self.taskName,
'yearStrideXTicks')
else:
yearStrideXTicks = None

timeseries_analysis_plot(config, [dsMOCTimeSeries.mocAtlantic26],
movingAveragePoints, title,
xLabel, yLabel, figureName,
lineStyles=['k-'], lineWidths=[2],
legendText=[None], calendar=self.calendar)
legendText=[None], calendar=self.calendar,
firstYearXTicks=firstYearXTicks,
yearStrideXTicks=yearStrideXTicks)

caption = u'Time Series of maximum Meridional Overturning ' \
u'Circulation at 26.5°N'
Expand Down
16 changes: 15 additions & 1 deletion mpas_analysis/ocean/time_series_antarctic_melt.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,28 @@ def run_task(self): # {{{
lineWidths.append(1.2)
legendText.append(refRunName)

if config.has_option(self.taskName, 'firstYearXTicks'):
firstYearXTicks = config.getint(self.taskName,
'firstYearXTicks')
else:
firstYearXTicks = None

if config.has_option(self.taskName, 'yearStrideXTicks'):
yearStrideXTicks = config.getint(self.taskName,
'yearStrideXTicks')
else:
yearStrideXTicks = None

timeseries_analysis_plot(config, fields, movingAverageMonths,
title, xLabel, yLabel, figureName,
lineStyles=lineStyles,
lineWidths=lineWidths,
legendText=legendText,
calendar=calendar, obsMean=obsMeltRate,
obsUncertainty=obsMeltRateUnc,
obsLegend=list(obsDict.keys()))
obsLegend=list(obsDict.keys()),
firstYearXTicks=firstYearXTicks,
yearStrideXTicks=yearStrideXTicks)

caption = 'Running Mean of Area-averaged Melt Rate under Ice ' \
'Shelves in the {} Region'.format(title)
Expand Down
16 changes: 15 additions & 1 deletion mpas_analysis/ocean/time_series_sst.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,25 @@ def run_task(self): # {{{
lineWidths.append(1.5)
legendText.append(preprocessedReferenceRunName)

if config.has_option(self.taskName, 'firstYearXTicks'):
firstYearXTicks = config.getint(self.taskName,
'firstYearXTicks')
else:
firstYearXTicks = None

if config.has_option(self.taskName, 'yearStrideXTicks'):
yearStrideXTicks = config.getint(self.taskName,
'yearStrideXTicks')
else:
yearStrideXTicks = None

timeseries_analysis_plot(config, fields, movingAveragePoints,
title, xLabel, yLabel, figureName,
lineStyles=lineStyles,
lineWidths=lineWidths,
legendText=legendText, calendar=calendar)
legendText=legendText, calendar=calendar,
firstYearXTicks=firstYearXTicks,
yearStrideXTicks=yearStrideXTicks)

caption = 'Running Mean of {} Sea Surface Temperature'.format(
region)
Expand Down
17 changes: 16 additions & 1 deletion mpas_analysis/sea_ice/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,18 @@ def run_task(self): # {{{
lineStyles.append('g-')
lineWidths.append(1.2)

if config.has_option(self.taskName, 'firstYearXTicks'):
firstYearXTicks = config.getint(self.taskName,
'firstYearXTicks')
else:
firstYearXTicks = None

if config.has_option(self.taskName, 'yearStrideXTicks'):
yearStrideXTicks = config.getint(self.taskName,
'yearStrideXTicks')
else:
yearStrideXTicks = None

# separate plots for nothern and southern hemispheres
timeseries_analysis_plot(config, dsvalues,
movingAveragePoints,
Expand All @@ -428,7 +440,10 @@ def run_task(self): # {{{
lineWidths=lineWidths,
legendText=legendText,
titleFontSize=titleFontSize,
calendar=calendar)
calendar=calendar,
firstYearXTicks=firstYearXTicks,
yearStrideXTicks=yearStrideXTicks)

filePrefix = '{}{}_{}'.format(variableName,
hemisphere,
mainRunName)
Expand Down
Loading

0 comments on commit 5871157

Please sign in to comment.