Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
397 changes: 168 additions & 229 deletions mpas_analysis/ocean/index_nino34.py

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions mpas_analysis/ocean/meridional_heat_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
import numpy as np
import netCDF4
import os
import warnings

from ..shared.plot.plotting import plot_vertical_section,\
setup_colormap, plot_1D

from ..shared.io.utility import build_config_full_path

from ..shared.timekeeping.utility import get_simulation_start_time
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't being used


from ..shared import AnalysisTask
from ..shared.html import write_image_xml

Expand Down Expand Up @@ -119,8 +116,8 @@ def setup_and_check(self): # {{{
if os.path.exists(observationsFile):
self.observationsFile = observationsFile
else:
warnings.warn('No MHT observations file found: skip plotting '
'obs')
print('Warning: No MHT observations file found: skip plotting '
'obs')

mainRunName = self.config.get('runs', 'mainRunName')

Expand Down
14 changes: 6 additions & 8 deletions mpas_analysis/shared/analysis_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from __future__ import absolute_import, division, print_function, \
unicode_literals

import warnings
from multiprocessing import Process, Value
import time
import traceback
Expand Down Expand Up @@ -451,13 +450,12 @@ def check_analysis_enabled(self, analysisOptionName, default=False,
except ValueError:
enabled = default
if default:
message = 'WARNING: namelist option {} not found.\n' \
'This likely indicates that the simulation you ' \
'are analyzing was run with an\n' \
'older version of MPAS-O that did not support ' \
'this flag. Assuming enabled.'.format(
analysisOptionName)
warnings.warn(message)
print('Warning: namelist option {} not found.\n'
'This likely indicates that the simulation you '
'are analyzing was run with an\n'
'older version of MPAS-O that did not support '
'this flag. Assuming enabled.'.format(
analysisOptionName))

if not enabled and raiseException:
raise RuntimeError('*** MPAS-Analysis relies on {} = .true.\n'
Expand Down
16 changes: 7 additions & 9 deletions mpas_analysis/shared/climatology/mpas_climatology_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import xarray
import os
import warnings
import subprocess
from distutils.spawn import find_executable

Expand Down Expand Up @@ -288,14 +287,13 @@ def _update_climatology_bounds_from_file_names(self): # {{{
endYear = years[lastIndex]

if startYear != requestedStartYear or endYear != requestedEndYear:
message = "climatology start and/or end year different from " \
"requested\n" \
"requestd: {:04d}-{:04d}\n" \
"actual: {:04d}-{:04d}\n".format(requestedStartYear,
requestedEndYear,
startYear,
endYear)
warnings.warn(message)
print("Warning: climatology start and/or end year different from "
"requested\n"
"requestd: {:04d}-{:04d}\n"
"actual: {:04d}-{:04d}\n".format(requestedStartYear,
requestedEndYear,
startYear,
endYear))
config.set('climatology', 'startYear', str(startYear))
config.set('climatology', 'endYear', str(endYear))

Expand Down
36 changes: 0 additions & 36 deletions mpas_analysis/shared/plot/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,42 +1144,6 @@ def setup_colormap(config, configSectionName, suffix=''):
return (colormap, colorbarLevels)


def plot_size_y_axis(plt, xaxisValues, **data):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to IndexNino34 because it's not likely to be used elsewhere.

'''
Resize the y-axis limit based on the curves being plotted

Parameters
----------
plt : plot handle

xaxisValues : numpy.array
Values plotted along the x-axis

data : dictionary entries must be numpy.array
data for curves on plot

Authors
-------
Luke Van Roekel
'''

ax = plt.gca()
xmin = ax.get_xlim()[0]
xmax = ax.get_xlim()[1]

# find period/frequency bounds for chosen xmin/xmax
minIndex = np.abs(xaxisValues - xmin).argmin()
maxIndex = np.abs(xaxisValues - xmax).argmin()

# find maximum value of three curves plotted
maxCurveVal = -1E20
for key in data:
maxTemp = data[key][minIndex:maxIndex].max()
maxCurveVal = max(maxTemp, maxCurveVal)

return maxCurveVal


def plot_xtick_format(plt, calendar, minDays, maxDays, maxXTicks):
'''
Formats tick labels and positions along the x-axis for time series
Expand Down
40 changes: 21 additions & 19 deletions mpas_analysis/shared/time_series/mpas_time_series_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
unicode_literals

import os
import warnings
import subprocess
from distutils.spawn import find_executable
import xarray as xr
Expand Down Expand Up @@ -42,7 +41,7 @@ class MpasTimeSeriesTask(AnalysisTask): # {{{
'''

def __init__(self, config, componentName, taskName=None,
subtaskName=None): # {{{
subtaskName=None, section='timeSeries'): # {{{
'''
Construct the analysis task for extracting time series.

Expand All @@ -62,19 +61,22 @@ def __init__(self, config, componentName, taskName=None,
subtaskName : str, optional
The name of the subtask (if any)

section : str, optional
The section of the config file from which to read the start and
end times for the time series, also added as a tag

Authors
-------
Xylar Asay-Davis
'''
self.variableList = []
self.seasons = []
self.section = section
tags = [section]

tags = ['timeSeries']

suffix = componentName[0].upper() + componentName[1:]
if taskName is None:
taskName = 'mpasTimeSeries{}'.format(suffix)
suffix = section[0].upper() + section[1:] + \
componentName[0].upper() + componentName[1:]
taskName = 'mpas{}'.format(suffix)

# call the constructor from the base class (AnalysisTask)
super(MpasTimeSeriesTask, self).__init__(
Expand Down Expand Up @@ -138,8 +140,8 @@ def setup_and_check(self): # {{{

# get a list of timeSeriesStats output files from the streams file,
# reading only those that are between the start and end dates
startDate = config.get('timeSeries', 'startDate')
endDate = config.get('timeSeries', 'endDate')
startDate = config.get(self.section, 'startDate')
endDate = config.get(self.section, 'endDate')
streamName = 'timeSeriesStatsMonthlyOutput'
self.inputFiles = self.historyStreams.readpath(
streamName, startDate=startDate, endDate=endDate,
Expand Down Expand Up @@ -200,7 +202,7 @@ def _update_time_series_bounds_from_file_names(self): # {{{
"""

config = self.config
section = 'timeSeries'
section = self.section

requestedStartYear = config.getint(section, 'startYear')
requestedEndYear = config.getint(section, 'endYear')
Expand All @@ -222,14 +224,14 @@ def _update_time_series_bounds_from_file_names(self): # {{{
endYear = years[lastIndex]

if startYear != requestedStartYear or endYear != requestedEndYear:
message = "time series start and/or end year different from " \
"requested\n" \
"requestd: {:04d}-{:04d}\n" \
"actual: {:04d}-{:04d}\n".format(requestedStartYear,
requestedEndYear,
startYear,
endYear)
warnings.warn(message)
print("Warning: {} start and/or end year different from "
"requested\n" \
"requestd: {:04d}-{:04d}\n" \
"actual: {:04d}-{:04d}\n".format(section,
requestedStartYear,
requestedEndYear,
startYear,
endYear))
config.set(section, 'startYear', str(startYear))
config.set(section, 'endYear', str(endYear))

Expand Down Expand Up @@ -280,7 +282,7 @@ def _compute_time_series_with_ncrcat(self):

with xr.open_dataset(self.outputFile) as ds:
dates = [bytes.decode(name) for name in
ds.xtime_startMonthly.values]
ds.xtime_startMonthly.values]
lastDate = dates[-1]

lastYear = int(lastDate[0:4])
Expand Down
3 changes: 1 addition & 2 deletions mpas_analysis/shared/time_series/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import xarray as xr
import numpy
import os
import warnings

from ..timekeeping.utility import days_to_datetime

Expand Down Expand Up @@ -87,7 +86,7 @@ def cache_time_series(timesInDataSet, timeSeriesCalcFunction, cacheFileName,
message = 'Deleting cache file {}, which appears to have ' \
'been corrupted.'.format(cacheFileName)
if logger is None:
warnings.warn(message)
print('Warning: {}'.format(message))
else:
logger.warning(message)
os.remove(cacheFileName)
Expand Down
3 changes: 1 addition & 2 deletions mpas_analysis/test/test_mpas_climatology_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ def test_update_climatology_bounds_from_file_names(self):
config.set('climatology', 'startDate', startDate)
config.set('climatology', 'endDate', endDate)

with pytest.warns(UserWarning):
mpasClimatologyTask._update_climatology_bounds_from_file_names()
mpasClimatologyTask._update_climatology_bounds_from_file_names()

startYear = 2
endYear = 2
Expand Down
5 changes: 4 additions & 1 deletion run_mpas_analysis
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def build_analysis_list(config): # {{{
componentName='ocean')
oceanTimeSeriesTask = MpasTimeSeriesTask(config=config,
componentName='ocean')
oceanIndexTask = MpasTimeSeriesTask(config=config,
componentName='ocean',
section='index')
analyses.append(oceanClimatolgyTask)
analyses.append(ocean.ClimatologyMapMLD(config, oceanClimatolgyTask))
analyses.append(ocean.ClimatologyMapSST(config, oceanClimatolgyTask))
Expand All @@ -81,7 +84,7 @@ def build_analysis_list(config): # {{{
analyses.append(ocean.TimeSeriesSST(config, oceanTimeSeriesTask))
analyses.append(ocean.MeridionalHeatTransport(config, oceanClimatolgyTask))
analyses.append(ocean.StreamfunctionMOC(config, oceanClimatolgyTask))
analyses.append(ocean.IndexNino34(config, oceanTimeSeriesTask))
analyses.append(ocean.IndexNino34(config, oceanIndexTask))

# Sea Ice Analyses
seaIceClimatolgyTask = MpasClimatologyTask(config=config,
Expand Down