Skip to content

Commit

Permalink
Merge branch 'MPAS-Dev/MPAS-Analysis/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xylar committed Sep 13, 2022
2 parents 67a19c0 + 11205a9 commit a28d8d2
Show file tree
Hide file tree
Showing 25 changed files with 78 additions and 76 deletions.
2 changes: 1 addition & 1 deletion ci/recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set name = "MPAS-Analysis" %}
{% set version = "1.7.0" %}
{% set version = "1.7.1" %}

package:
name: {{ name|lower }}
Expand Down
3 changes: 3 additions & 0 deletions docs/versions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Documentation On GitHub
`v1.6.0`_ `1.6.0`_
`v1.6.1`_ `1.6.1`_
`v1.7.0`_ `1.7.0`_
`v1.7.1`_ `1.7.1`_
================ ===============

.. _`stable`: ../stable/index.html
Expand All @@ -30,6 +31,7 @@ Documentation On GitHub
.. _`v1.6.0`: ../1.6.0/index.html
.. _`v1.6.1`: ../1.6.1/index.html
.. _`v1.7.0`: ../1.7.0/index.html
.. _`v1.7.1`: ../1.7.1/index.html
.. _`master`: https://github.com/MPAS-Dev/MPAS-Analysis/tree/master
.. _`develop`: https://github.com/MPAS-Dev/MPAS-Analysis/tree/develop
.. _`1.2.6`: https://github.com/MPAS-Dev/MPAS-Analysis/tree/1.2.6
Expand All @@ -42,3 +44,4 @@ Documentation On GitHub
.. _`1.6.0`: https://github.com/MPAS-Dev/MPAS-Analysis/tree/1.6.0
.. _`1.6.1`: https://github.com/MPAS-Dev/MPAS-Analysis/tree/1.6.1
.. _`1.7.0`: https://github.com/MPAS-Dev/MPAS-Analysis/tree/1.7.0
.. _`1.7.1`: https://github.com/MPAS-Dev/MPAS-Analysis/tree/1.7.1
2 changes: 1 addition & 1 deletion mpas_analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import matplotlib as mpl
mpl.use('Agg')

__version_info__ = (1, 7, 0)
__version_info__ = (1, 7, 1)
__version__ = '.'.join(str(vi) for vi in __version_info__)
2 changes: 1 addition & 1 deletion mpas_analysis/ocean/index_nino34.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def _compute_nino34_index(self, regionSST, calendar):
regionSST : xarray.DataArray object
values of SST in the nino region
calendar: {'gregorian', 'gregorian_noleap'}
calendar: {'gregorian', 'noleap'}
The name of the calendars used in the MPAS run
Returns
Expand Down
9 changes: 3 additions & 6 deletions mpas_analysis/ocean/regional_ts_diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, config, mpasClimatologyTask, regionMasksTask,
regionMasksTask : ``ComputeRegionMasks``
A task for computing region masks
controlconfig : mpas_tools.config.MpasConfigParser, optional
controlConfig : mpas_tools.config.MpasConfigParser, optional
Configuration options for a control run (if any)
"""
# Authors
Expand Down Expand Up @@ -658,12 +658,9 @@ def _write_mpas_t_s(self, config):

ds = ds.where(cellMask, drop=True)

self.logger.info("Don't worry about the following dask "
"warnings.")
depthMask = numpy.logical_and(ds.zMid >= zmin,
ds.zMid <= zmax)
depthMask.compute()
self.logger.info("Dask warnings should be done.")
ds['depthMask'] = depthMask

for var in variableList:
Expand Down Expand Up @@ -715,7 +712,7 @@ def _write_obs_t_s(self, obsDict, zmin, zmax):
xarray.open_dataset(regionMaskFileName).chunk(chunk).stack(
nCells=(obsDict['latVar'], obsDict['lonVar']))
dsRegionMask = dsRegionMask.reset_index('nCells').drop_vars(
[obsDict['latVar'], obsDict['lonVar']])
[obsDict['latVar'], obsDict['lonVar'], 'nCells'])

maskRegionNames = decode_strings(dsRegionMask.regionNames)
regionIndex = maskRegionNames.index(self.regionName)
Expand Down Expand Up @@ -745,7 +742,7 @@ def _write_obs_t_s(self, obsDict, zmin, zmax):
ds = xarray.open_dataset(obsFileName, chunks=chunk)
ds = ds.stack(nCells=(obsDict['latVar'], obsDict['lonVar']))
ds = ds.reset_index('nCells').drop_vars(
[obsDict['latVar'], obsDict['lonVar']])
[obsDict['latVar'], obsDict['lonVar'], 'nCells'])

ds = ds.where(cellMask, drop=True)

Expand Down
4 changes: 2 additions & 2 deletions mpas_analysis/ocean/time_series_ocean_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ def run_task(self):
xarray.open_dataset(regionMaskFileName).stack(
nCells=(obsDict['latVar'], obsDict['lonVar']))
dsRegionMask = dsRegionMask.reset_index('nCells').drop_vars(
[obsDict['latVar'], obsDict['lonVar']])
[obsDict['latVar'], obsDict['lonVar'], 'nCells'])

maskRegionNames = decode_strings(dsRegionMask.regionNames)
regionIndex = maskRegionNames.index(self.regionName)
Expand Down Expand Up @@ -956,7 +956,7 @@ def run_task(self):
dsMonth = dsMonth.stack(nCells=(obsDict['latVar'],
obsDict['lonVar']))
dsMonth = dsMonth.reset_index('nCells').drop_vars(
[obsDict['latVar'], obsDict['lonVar']])
[obsDict['latVar'], obsDict['lonVar'], 'nCells'])

dsMonth = dsMonth.where(cellMask, drop=True)

Expand Down
2 changes: 1 addition & 1 deletion mpas_analysis/sea_ice/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def _replicate_cycle(self, ds, dsToReplicate, calendar):
length of dsToReplicate plus the time between the first two time
values (typically one year total).
calendar : {'gregorian', 'gregorian_noleap'}
calendar : {'gregorian', 'noleap'}
The name of one of the calendars supported by MPAS cores
Returns:
Expand Down
8 changes: 4 additions & 4 deletions mpas_analysis/shared/climatology/climatology.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def compute_monthly_climatology(ds, calendar=None, maskVaries=True):
A data set with a ``Time`` coordinate expressed as days since
0001-01-01 or ``month`` coordinate
calendar : {'gregorian', 'gregorian_noleap'}, optional
calendar : {'gregorian', 'noleap'}, optional
The name of one of the calendars supported by MPAS cores, used to
determine ``month`` from ``Time`` coordinate, so must be supplied if
``ds`` does not already have a ``month`` coordinate or data array
Expand Down Expand Up @@ -201,7 +201,7 @@ def compute_climatology(ds, monthValues, calendar=None,
monthValues : int or array-like of ints
A single month or an array of months to be averaged together
calendar : {'gregorian', 'gregorian_noleap'}, optional
calendar : {'gregorian', 'noleap'}, optional
The name of one of the calendars supported by MPAS cores, used to
determine ``month`` from ``Time`` coordinate, so must be supplied if
``ds`` does not already have a ``month`` coordinate or data array
Expand Down Expand Up @@ -242,7 +242,7 @@ def add_years_months_days_in_month(ds, calendar=None):
"""
Add ``year``, ``month`` and ``daysInMonth`` as data arrays in ``ds``.
The number of days in each month of ``ds`` is computed either using the
``startTime`` and ``endTime`` if available or assuming ``gregorian_noleap``
``startTime`` and ``endTime`` if available or assuming ``noleap``
calendar and ignoring leap years. ``year`` and ``month`` are computed
accounting correctly for the the calendar.
Expand All @@ -252,7 +252,7 @@ def add_years_months_days_in_month(ds, calendar=None):
A data set with a ``Time`` coordinate expressed as days since
0001-01-01
calendar : {'gregorian', 'gregorian_noleap'}, optional
calendar : {'gregorian', 'noleap'}, optional
The name of one of the calendars supported by MPAS cores, used to
determine ``year`` and ``month`` from ``Time`` coordinate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ def get_start_and_end(self):
startDate = '{:04d}-01-01_00:00:00'.format(startYear)
endDate = '{:04d}-12-31_23:59:59'.format(endYear)

config.set('climatology', 'startYear', str(startYear))
config.set('climatology', 'startDate', startDate)
config.set('climatology', 'endYear', str(endYear))
config.set('climatology', 'endDate', endDate)
# using "user=True" so these changes take priority over user config
# options
config.set('climatology', 'startYear', str(startYear), user=True)
config.set('climatology', 'startDate', startDate, user=True)
config.set('climatology', 'endYear', str(endYear), user=True)
config.set('climatology', 'endDate', endDate, user=True)

return startYear, endYear

Expand Down
4 changes: 2 additions & 2 deletions mpas_analysis/shared/generalized_reader/generalized_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def open_multifile_dataset(fileNames, calendar, config,
fileNames : list of strings
A lsit of file paths to read
calendar : {``'gregorian'``, ``'gregorian_noleap'``}, optional
calendar : {``'gregorian'``, ``'noleap'``}, optional
The name of one of the calendars supported by MPAS cores
config : mpas_tools.config.MpasConfigParser
Expand Down Expand Up @@ -186,7 +186,7 @@ def _preprocess(ds, calendar, simulationStartTime, timeVariableName,
an xarray time coordinate and with variable names to be
substituted.
calendar : {'gregorian', 'gregorian_noleap'}
calendar : {'gregorian', 'noleap'}
The name of one of the calendars supported by MPAS cores
The name of the time variable (typically 'Time' if using a variableMap
Expand Down
4 changes: 2 additions & 2 deletions mpas_analysis/shared/io/mpas_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def open_mpas_dataset(fileName, calendar,
fileName : str
File path to read
calendar : {``'gregorian'``, ``'gregorian_noleap'``}, optional
calendar : {``'gregorian'``, ``'noleap'``}, optional
The name of one of the calendars supported by MPAS cores
timeVariableNames : str or list of 2 str, optional
Expand Down Expand Up @@ -120,7 +120,7 @@ def _parse_dataset_time(ds, inTimeVariableName, calendar,
inTimeVariableName is typically
``['xtime_startMonthly', 'xtime_endMonthly']``.
calendar : {'gregorian', 'gregorian_noleap'}
calendar : {'gregorian', 'noleap'}
The name of one of the calendars supported by MPAS cores
outTimeVariableName : str
Expand Down
2 changes: 1 addition & 1 deletion mpas_analysis/shared/io/namelist_streams_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def readpath(self, streamName, startDate=None, endDate=None,
and added to endDate because the file date might be the first
or last date contained in the file (or anything in between).
calendar : {'gregorian', 'gregorian_noleap'}, optional
calendar : {'gregorian', 'noleap'}, optional
The name of one of the calendars supported by MPAS cores, and is
required if startDate and/or endDate are supplied
Expand Down
6 changes: 3 additions & 3 deletions mpas_analysis/shared/mpas_xarray/mpas_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def open_multifile_dataset(fileNames, calendar,
fileNames : list of strings
A lsit of file paths to read
calendar : {``'gregorian'``, ``'gregorian_noleap'``}, optional
calendar : {'gregorian', 'noleap'}, optional
The name of one of the calendars supported by MPAS cores
simulationStartTime : string, optional
Expand Down Expand Up @@ -181,7 +181,7 @@ def preprocess(ds, calendar, simulationStartTime, timeVariableName,
The data set containing an MPAS time variable to be used to build
an xarray time coordinate.
calendar : {``'gregorian'``, ``'gregorian_noleap'``}
calendar : {'gregorian', 'noleap'}
The name of one of the calendars supported by MPAS cores
simulationStartTime : string, optinal
Expand Down Expand Up @@ -376,7 +376,7 @@ def _parse_dataset_time(ds, inTimeVariableName, calendar,
determine the value of the time coordinate. In such cases,
inTimeVariableName is typically {['xtime_start', 'xtime_end']}.
calendar : {'gregorian', 'gregorian_noleap'}
calendar : {'gregorian', 'noleap'}
The name of one of the calendars supported by MPAS cores
Expand Down
2 changes: 1 addition & 1 deletion mpas_analysis/shared/time_series/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def cache_time_series(timesInDataSet, timeSeriesCalcFunction, cacheFileName,
The absolute path to the cache file where the times series will be
stored
calendar : {'gregorian', 'gregorian_noleap'}
calendar : {'gregorian', 'noleap'}
The name of one of the calendars supported by MPAS cores, used to
determine ``year`` and ``month`` from ``Time`` coordinate
Expand Down
6 changes: 3 additions & 3 deletions mpas_analysis/shared/timekeeping/MpasRelativeDelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MpasRelativeDelta(relativedelta):

def __init__(self, dt1=None, dt2=None, years=0, months=0, days=0,
hours=0, minutes=0, seconds=0, calendar='gregorian'):
if calendar not in ['gregorian', 'gregorian_noleap']:
if calendar not in ['gregorian', 'noleap', 'gregorian_noleap']:
raise ValueError('Unsupported MPAs calendar {}'.format(calendar))
self.calendar = calendar
super(MpasRelativeDelta, self).__init__(dt1=dt1, dt2=dt2, years=years,
Expand Down Expand Up @@ -79,15 +79,15 @@ def __add__(self, other):

if self.calendar == 'gregorian':
daysInMonth = monthrange(year, month)[1]
elif self.calendar == 'gregorian_noleap':
elif self.calendar in ['noleap', 'gregorian_noleap']:
# use year 0001, which is not a leapyear
daysInMonth = monthrange(1, month)[1]

day = min(daysInMonth, other.day)
repl = {"year": year, "month": month, "day": day}

days = self.days
if self.calendar == 'gregorian_noleap' and isleap(year):
if self.calendar in ['noleap', 'gregorian_noleap'] and isleap(year):
if month == 2 and day + days >= 29:
# skip forward over the leap day
days += 1
Expand Down
14 changes: 7 additions & 7 deletions mpas_analysis/shared/timekeeping/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def string_to_relative_delta(dateString, calendar='gregorian'):
Note: either underscores or spaces can be used to separate the date
from the time portion of the string.
calendar: {'gregorian', 'gregorian_noleap'}, optional
calendar: {'gregorian', 'noleap'}, optional
The name of one of the calendars supported by MPAS cores
Returns
Expand Down Expand Up @@ -189,7 +189,7 @@ def string_to_days_since_date(dateString, calendar='gregorian',
Note: either underscores or spaces can be used to separate the date
from the time portion of the string.
calendar: {'gregorian', 'gregorian_noleap'}, optional
calendar: {'gregorian', 'noleap'}, optional
The name of one of the calendars supported by MPAS cores
referenceDate : str, optional
Expand Down Expand Up @@ -232,14 +232,14 @@ def string_to_days_since_date(dateString, calendar='gregorian',
def days_to_datetime(days, calendar='gregorian', referenceDate='0001-01-01'):
"""
Covert days to ``datetime.datetime`` objects given a reference date and an
MPAS calendar (either 'gregorian' or 'gregorian_noleap').
MPAS calendar (either 'gregorian' or 'noleap').
Parameters
----------
days : float or array-like of floats
The number of days since the reference date.
calendar : {'gregorian', 'gregorian_noleap'}, optional
calendar : {'gregorian', 'noleap'}, optional
A calendar to be used to convert days to a ``datetime.datetime``
object.
Expand Down Expand Up @@ -293,7 +293,7 @@ def datetime_to_days(dates, calendar='gregorian', referenceDate='0001-01-01'):
The date(s) to be converted to days since ``referenceDate`` on the
given ``calendar``.
calendar : {'gregorian', 'gregorian_noleap'}, optional
calendar : {'gregorian', 'noleap'}, optional
A calendar to be used to convert days to a ``datetime.datetime`` object.
referenceDate : str, optional
Expand Down Expand Up @@ -342,7 +342,7 @@ def date_to_days(year=1, month=1, day=1, hour=0, minute=0, second=0,
The date to be converted to days since ``referenceDate`` on the
given ``calendar``.
calendar : {'gregorian', 'gregorian_noleap'}, optional
calendar : {'gregorian', 'noleap'}, optional
A calendar to be used to convert days to a ``datetime.datetime``
object.
Expand Down Expand Up @@ -469,7 +469,7 @@ def _mpas_to_netcdf_calendar(calendar):

if calendar == 'gregorian_noleap':
calendar = 'noleap'
elif calendar != 'gregorian':
if calendar not in ['gregorian', 'noleap']:
raise ValueError('Unsupported calendar {}'.format(calendar))
return calendar

Expand Down
4 changes: 2 additions & 2 deletions mpas_analysis/test/test_climatology.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def test_get_observations_remapper(self):

def test_compute_climatology(self):
config = self.setup_config()
calendar = 'gregorian_noleap'
calendar = 'noleap'
ds = self.open_test_ds(config, calendar)

assert('month' not in ds.coords.keys())
Expand Down Expand Up @@ -237,7 +237,7 @@ def test_compute_climatology(self):

def test_compute_monthly_climatology(self):
config = self.setup_config()
calendar = 'gregorian_noleap'
calendar = 'noleap'
ds = self.open_test_ds(config, calendar)

monthlyClimatology = compute_monthly_climatology(ds, calendar)
Expand Down
6 changes: 3 additions & 3 deletions mpas_analysis/test/test_generalized_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_variableMap(self):
'refBottomDepth', 'daysSinceStartOfSim']

config = self.setup_config()
for calendar in ['gregorian', 'gregorian_noleap']:
for calendar in ['gregorian', 'noleap']:
# preprocess_mpas will use variableMap to map the variable names
# from their values in the file to the desired values in
# variableList
Expand All @@ -80,7 +80,7 @@ def test_open_dataset_fn(self):
['time_avg_avgValueWithinOceanRegion_avgSurfaceTemperature']

config = self.setup_config()
for calendar in ['gregorian', 'gregorian_noleap']:
for calendar in ['gregorian', 'noleap']:
ds = open_multifile_dataset(
fileNames=fileName,
calendar=calendar,
Expand All @@ -97,7 +97,7 @@ def test_start_end(self):
['time_avg_avgValueWithinOceanRegion_avgSurfaceTemperature']

config = self.setup_config()
for calendar in ['gregorian', 'gregorian_noleap']:
for calendar in ['gregorian', 'noleap']:
# all dates
ds = open_multifile_dataset(
fileNames=fileName,
Expand Down
2 changes: 1 addition & 1 deletion mpas_analysis/test/test_mpas_climatology_task/mpas-o_in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
config_ocean_run_mode = 'forward'
/
&time_management
config_calendar_type = 'gregorian_noleap'
config_calendar_type = 'noleap'
config_do_restart = .true.
config_restart_timestamp_name = 'rpointer.ocn'
config_start_time = 'file'
Expand Down
Loading

0 comments on commit a28d8d2

Please sign in to comment.