Skip to content

Commit

Permalink
Switch to noleap instead of gregorian_noleap
Browse files Browse the repository at this point in the history
For backwards compatibility, namelists withh a `gregorian_noleap`
calendar are still supported but `noleap` is used for testing
and listed in docstrings.
  • Loading branch information
xylar committed Sep 12, 2022
1 parent 2669d9d commit 8740d12
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 62 deletions.
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
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
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
12 changes: 6 additions & 6 deletions mpas_analysis/test/test_mpas_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TestMpasXarray(TestCase):

def test_subset_variables(self):
fileName = str(self.datadir.join('example_jan.nc'))
calendar = 'gregorian_noleap'
calendar = 'noleap'
timestr = ['xtime_start', 'xtime_end']
variableList = \
['time_avg_avgValueWithinOceanRegion_avgSurfaceTemperature']
Expand Down Expand Up @@ -63,7 +63,7 @@ def test_subset_variables(self):

def test_iselvals(self):
fileName = str(self.datadir.join('example_jan.nc'))
calendar = 'gregorian_noleap'
calendar = 'noleap'
simulationStartTime = '0001-01-01'
timestr = 'time_avg_daysSinceStartOfSim'
variableList = \
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_iselvals(self):

def test_no_units(self):
fileName = str(self.datadir.join('example_no_units_jan.nc'))
calendar = 'gregorian_noleap'
calendar = 'noleap'
simulationStartTime = '0001-01-01'
timestr = 'time_avg_daysSinceStartOfSim'
variableList = \
Expand All @@ -117,7 +117,7 @@ def test_no_units(self):

def test_bad_selvals(self):
fileName = str(self.datadir.join('example_jan.nc'))
calendar = 'gregorian_noleap'
calendar = 'noleap'
simulationStartTime = '0001-01-01'
timestr = 'time_avg_daysSinceStartOfSim'
variableList = \
Expand All @@ -138,7 +138,7 @@ def test_bad_selvals(self):

def test_selvals(self):
fileName = str(self.datadir.join('example_jan.nc'))
calendar = 'gregorian_noleap'
calendar = 'noleap'
simulationStartTime = '0001-01-01'
timestr = 'time_avg_daysSinceStartOfSim'
variableList = \
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_selvals(self):

def test_remove_repeated_time_index(self):
fileName = str(self.datadir.join('example_jan*.nc'))
calendar = 'gregorian_noleap'
calendar = 'noleap'
timestr = ['xtime_start', 'xtime_end']
variableList = \
['time_avg_avgValueWithinOceanRegion_avgSurfaceTemperature']
Expand Down
10 changes: 5 additions & 5 deletions mpas_analysis/test/test_namelist_streams_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_read_streamsfile(self):
files = self.sf.readpath('output',
startDate='0001-01-02',
endDate='0001-12-30',
calendar='gregorian_noleap')
calendar='noleap')
expectedFiles = []
for date in ['0001-01-02', '0001-02-01']:
expectedFiles.append('{}/output/output.{}_00.00.00.nc'
Expand All @@ -78,7 +78,7 @@ def test_read_streamsfile(self):

files = self.sf.readpath('output',
startDate='0001-01-02',
calendar='gregorian_noleap')
calendar='noleap')
expectedFiles = []
for date in ['0001-01-02', '0001-02-01', '0002-01-01']:
expectedFiles.append('{}/output/output.{}_00.00.00.nc'
Expand All @@ -87,7 +87,7 @@ def test_read_streamsfile(self):

files = self.sf.readpath('output',
endDate='0001-12-30',
calendar='gregorian_noleap')
calendar='noleap')
expectedFiles = []
for date in ['0001-01-01', '0001-01-02', '0001-02-01']:
expectedFiles.append('{}/output/output.{}_00.00.00.nc'
Expand All @@ -97,7 +97,7 @@ def test_read_streamsfile(self):
files = self.sf.readpath('restart',
startDate='0001-01-01',
endDate='0001-12-31',
calendar='gregorian_noleap')
calendar='noleap')
expectedFiles = []
for seconds in ['00010', '00020']:
expectedFiles.append('{}/restarts/restart.0001-01-01_{}.nc'
Expand All @@ -111,6 +111,6 @@ def test_read_streamsfile(self):
files = self.sf.readpath('mesh',
startDate='0001-01-01',
endDate='0001-12-31',
calendar='gregorian_noleap')
calendar='noleap')
expectedFiles = ['{}/mesh.nc'.format(self.sf.streamsdir)]
self.assertEqual(files, expectedFiles)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
config_start_time = '0000-01-01_00:00:00'
config_stop_time = 'none'
config_run_duration = '1000_00:00:00'
config_calendar_type = 'gregorian_noleap'
config_calendar_type = 'noleap'
/
&time_integration
config_dt = '00:10:00'
Expand Down
Loading

0 comments on commit 8740d12

Please sign in to comment.