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
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ matrix:
fast_finish: true
include:
- python: 2.7
env: CONDA_ENV=py27
- python: 3.5
- python: 3.6

before_install:
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget http://repo.continuum.io/miniconda/Miniconda-3.16.0-Linux-x86_64.sh -O miniconda.sh;
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
else
wget http://repo.continuum.io/miniconda/Miniconda3-3.16.0-Linux-x86_64.sh -O miniconda.sh;
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
fi
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
Expand All @@ -24,8 +25,10 @@ before_install:
- conda info -a

install:
- conda env create --file ci/requirements-$CONDA_ENV.yml
- conda create -n test_env -c conda-forge python=$TRAVIS_PYTHON_VERSION
- conda env update -n test_env -f ci/requirements.yml
- source activate test_env
- conda list

script:
- py.test
- pytest
3 changes: 1 addition & 2 deletions ci/requirements-py27.yml → ci/requirements.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: test_env
channels:
- conda-forge
dependencies:
- python=2.7
- pytest
- six
- numpy
- scipy
- lxml
Expand Down
9 changes: 6 additions & 3 deletions mpas_analysis/analysis_task_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
Xylar Asay-Davis
'''

from __future__ import absolute_import, division, print_function, \
unicode_literals

# import python modules here
import numpy
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -351,10 +354,10 @@ def _make_plot(self, plotParameter, optionalArgument=None): # {{{
# self.myArg is a copy of the argument we passed in to __init__ when we
# built the task. It is available in any method after that for us to
# use as needed.
print 'myArg:', self.myArg
print 'plotParameter:', plotParameter
print('myArg: {}'.format(self.myArg))
print('plotParameter: {}'.format(plotParameter))
if optionalArgument is not None:
print 'optionalArgument:', optionalArgument
print('optionalArgument: {}'.format(optionalArgument))

# get the file name based on the plot parameter
filePrefix = self.filePrefixes[plotParameter]
Expand Down
9 changes: 8 additions & 1 deletion mpas_analysis/configuration/MpasAnalysisConfigParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@
Xylar Asay-Davis, Phillip J. Wolfram
"""

from __future__ import absolute_import, division, print_function, \
unicode_literals

import numbers
import ast
import six
import numpy as np
from ConfigParser import ConfigParser

from six.moves.configparser import ConfigParser

if six.PY3:
xrange = range

npallow = dict(linspace=np.linspace, xrange=xrange, range=range,
arange=np.arange, pi=np.pi, Pi=np.pi, __builtins__=None)
Expand Down
12 changes: 6 additions & 6 deletions mpas_analysis/ocean/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from climatology_map import ClimatologyMapSST, ClimatologyMapMLD, \
from .climatology_map import ClimatologyMapSST, ClimatologyMapMLD, \
ClimatologyMapSSS
from time_series_ohc import TimeSeriesOHC
from time_series_sst import TimeSeriesSST
from index_nino34 import IndexNino34
from streamfunction_moc import StreamfunctionMOC
from meridional_heat_transport import MeridionalHeatTransport
from .time_series_ohc import TimeSeriesOHC
from .time_series_sst import TimeSeriesSST
from .index_nino34 import IndexNino34
from .streamfunction_moc import StreamfunctionMOC
from .meridional_heat_transport import MeridionalHeatTransport
3 changes: 3 additions & 0 deletions mpas_analysis/ocean/climatology_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
Luke Van Roekel, Xylar Asay-Davis, Milena Veneziani
"""

from __future__ import absolute_import, division, print_function, \
unicode_literals

import xarray as xr
import datetime
import numpy as np
Expand Down
6 changes: 5 additions & 1 deletion mpas_analysis/ocean/index_nino34.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, \
unicode_literals

import datetime
import xarray as xr
import pandas as pd
Expand Down Expand Up @@ -394,7 +398,7 @@ def _running_mean(self, inputData, wgts): # {{{
"""

nt = len(inputData)
sp = (len(wgts) - 1)/2
sp = (len(wgts) - 1) // 2
runningMean = inputData.copy()
for k in range(sp, nt-(sp+1)):
runningMean[k] = sum(wgts*inputData[k-sp:k+sp+1].values)
Expand Down
4 changes: 4 additions & 0 deletions mpas_analysis/ocean/meridional_heat_transport.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

from __future__ import absolute_import, division, print_function, \
unicode_literals

import xarray as xr
import numpy as np
import netCDF4
Expand Down
4 changes: 4 additions & 0 deletions mpas_analysis/ocean/streamfunction_moc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, \
unicode_literals

import xarray as xr
import numpy as np
import netCDF4
Expand Down
6 changes: 5 additions & 1 deletion mpas_analysis/ocean/time_series_ohc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, \
unicode_literals

import numpy as np
import netCDF4

Expand Down Expand Up @@ -216,7 +220,7 @@ def run_task(self): # {{{
startDate=self.startDate,
endDate=self.endDate)
# rename the variables to shorter names for convenience
renameDict = dict((v, k) for k, v in variables.iteritems())
renameDict = dict((v, k) for k, v in variables.items())
ds.rename(renameDict, inplace=True)

timeStart = string_to_datetime(self.startDate)
Expand Down
4 changes: 4 additions & 0 deletions mpas_analysis/ocean/time_series_sst.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

from __future__ import absolute_import, division, print_function, \
unicode_literals

from ..shared import AnalysisTask

from ..shared.plot.plotting import timeseries_analysis_plot
Expand Down
4 changes: 2 additions & 2 deletions mpas_analysis/sea_ice/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from climatology_map import ClimatologyMapSeaIceConc, ClimatologyMapSeaIceThick
from time_series import TimeSeriesSeaIce
from .climatology_map import ClimatologyMapSeaIceConc, ClimatologyMapSeaIceThick
from .time_series import TimeSeriesSeaIce
4 changes: 4 additions & 0 deletions mpas_analysis/sea_ice/climatology_map.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

from __future__ import absolute_import, division, print_function, \
unicode_literals

import os
import os.path

Expand Down
4 changes: 4 additions & 0 deletions mpas_analysis/sea_ice/sea_ice_analysis_task.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

from __future__ import absolute_import, division, print_function, \
unicode_literals

from ..shared.analysis_task import AnalysisTask

from ..shared.io import StreamsFile
Expand Down
8 changes: 6 additions & 2 deletions mpas_analysis/sea_ice/time_series.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

from __future__ import absolute_import, division, print_function, \
unicode_literals

import xarray as xr

from .sea_ice_analysis_task import SeaIceAnalysisTask
Expand Down Expand Up @@ -551,9 +555,9 @@ def _replicate_cycle(self, ds, dsToReplicate, calendar): # {{{

# clip dsShift to the range of ds
dsStartTime = dsShift.Time.sel(Time=ds.Time.min(),
method='nearest').values
method=str('nearest')).values
dsEndTime = dsShift.Time.sel(Time=ds.Time.max(),
method='nearest').values
method=str('nearest')).values
dsShift = dsShift.sel(Time=slice(dsStartTime, dsEndTime))

return dsShift # }}}
Expand Down
2 changes: 1 addition & 1 deletion mpas_analysis/shared/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from analysis_task import AnalysisTask
from .analysis_task import AnalysisTask
9 changes: 6 additions & 3 deletions mpas_analysis/shared/analysis_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

'''

from __future__ import absolute_import, division, print_function, \
unicode_literals

import warnings
from multiprocessing import Process, Value
import time
Expand Down Expand Up @@ -506,11 +509,11 @@ class AnalysisFormatter(logging.Formatter): # {{{

# printing error messages without a prefix because they are sometimes
# errors and sometimes only warnings sent to stderr
err_fmt = "%(msg)s"
dbg_fmt = "DEBUG: %(module)s: %(lineno)d: %(msg)s"
info_fmt = "%(msg)s"
err_fmt = info_fmt

def __init__(self, fmt="%(levelno)s: %(msg)s"):
def __init__(self, fmt=info_fmt):
logging.Formatter.__init__(self, fmt)

def format(self, record):
Expand Down Expand Up @@ -558,7 +561,7 @@ def __init__(self, logger, log_level=logging.INFO):

def write(self, buf):
for line in buf.rstrip().splitlines():
self.logger.log(self.log_level, line.rstrip())
self.logger.log(self.log_level, str(line.rstrip()))

def flush(self):
pass
Expand Down
27 changes: 15 additions & 12 deletions mpas_analysis/shared/climatology/climatology.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
Xylar Asay-Davis
"""

from __future__ import absolute_import, division, print_function, \
unicode_literals

import xarray as xr
import os
import numpy
Expand Down Expand Up @@ -327,11 +330,11 @@ def add_years_months_days_in_month(ds, calendar=None): # {{{
ds.coords['daysInMonth'] = ds.endTime - ds.startTime
else:
if calendar == 'gregorian':
print 'Warning: The MPAS run used the Gregorian calendar ' \
'but does not appear to have\n' \
'supplied start and end times. Climatologies ' \
'will be computed with\n' \
'month durations ignoring leap years.'
print('Warning: The MPAS run used the Gregorian calendar '
'but does not appear to have\n'
'supplied start and end times. Climatologies '
'will be computed with\n'
'month durations ignoring leap years.')

daysInMonth = numpy.array([constants.daysInMonth[month-1] for
month in ds.month.values], float)
Expand Down Expand Up @@ -527,8 +530,8 @@ def _setup_climatology_caching(ds, startYearClimo, endYearClimo,
dsCached = xr.open_dataset(outputFileClimo)
except IOError:
# assuming the cache file is corrupt, so deleting it.
print 'Warning: Deleting cache file {}, which appears to ' \
'have been corrupted.'.format(outputFileClimo)
print('Warning: Deleting cache file {}, which appears to '
'have been corrupted.'.format(outputFileClimo))

os.remove(outputFileClimo)

Expand Down Expand Up @@ -576,7 +579,7 @@ def _cache_individual_climatologies(ds, cacheInfo, printProgress,
dsYear = ds.where(ds.cacheIndices == cacheIndex, drop=True)

if printProgress:
print ' {}'.format(yearString)
print(' {}'.format(yearString))

totalDays = dsYear.daysInMonth.sum(dim='Time').values

Expand Down Expand Up @@ -622,8 +625,8 @@ def _cache_aggregated_climatology(startYearClimo, endYearClimo, cachePrefix,

except IOError:
# assuming the cache file is corrupt, so deleting it.
print 'Warning: Deleting cache file {}, which appears to have ' \
'been corrupted.'.format(outputFileClimo)
print('Warning: Deleting cache file {}, which appears to have '
'been corrupted.'.format(outputFileClimo))
os.remove(outputFileClimo)

if len(cacheInfo) == 1 and outputFileClimo == cacheInfo[0][0]:
Expand All @@ -641,8 +644,8 @@ def _cache_aggregated_climatology(startYearClimo, endYearClimo, cachePrefix,

if not done:
if printProgress:
print ' Computing aggregated climatology ' \
'{}...'.format(yearString)
print(' Computing aggregated climatology '
'{}...'.format(yearString))

first = True
for cacheIndex, info in enumerate(cacheInfo):
Expand Down
3 changes: 3 additions & 0 deletions mpas_analysis/shared/climatology/comparison_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
Xylar Asay-Davis
"""

from __future__ import absolute_import, division, print_function, \
unicode_literals

import numpy
import pyproj

Expand Down
9 changes: 8 additions & 1 deletion mpas_analysis/shared/climatology/mpas_climatology_task.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

from __future__ import absolute_import, division, print_function, \
unicode_literals

import xarray
import os
import warnings
Expand Down Expand Up @@ -425,8 +429,11 @@ def _compute_climatologies_with_ncclimo(self, inDirectory, outDirectory,
stdout, stderr = process.communicate()

if stdout:
self.logger.info(stdout)
stdout = stdout.decode('utf-8')
for line in stdout.split('\n'):
self.logger.info(line)
if stderr:
stderr = stderr.decode('utf-8')
for line in stderr.split('\n'):
self.logger.error(line)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

from __future__ import absolute_import, division, print_function, \
unicode_literals

import xarray as xr
import os

Expand Down
7 changes: 5 additions & 2 deletions mpas_analysis/shared/constants/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import numpy as np

"""
Constants that are common to all analysis tasks

Expand All @@ -12,6 +10,11 @@
03/15/2017
"""

from __future__ import absolute_import, division, print_function, \
unicode_literals

import numpy as np

# set parameters for default climatology comparison grid
dLongitude = 0.5
dLatitude = 0.5
Expand Down
3 changes: 3 additions & 0 deletions mpas_analysis/shared/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
10/22/2016
"""

from __future__ import absolute_import, division, print_function, \
unicode_literals

import collections
class ReadOnlyDict(collections.Mapping): #{{{
""" Read only-dictionary
Expand Down
2 changes: 1 addition & 1 deletion mpas_analysis/shared/generalized_reader/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from generalized_reader import open_multifile_dataset
from .generalized_reader import open_multifile_dataset
Loading