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
53 changes: 30 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,44 @@ matrix:
include:
- python: 2.7
env: TEST_TARGET=default
- python: 3.4
env: TEST_TARGET=default
- python: 3.5
env: TEST_TARGET=default
- python: 3.5
env: TEST_TARGET=coding_standards
allow_failures:
- python: 3.5
- python: 3.6
env: TEST_TARGET=default
- python: 2.7
env: TEST_TARGET=doctest
- python: 3.6
env: TEST_TARGET=doctest
- python: 3.6
env: TEST_TARGET=coding_standards

before_install:
- wget http://bit.ly/miniconda -O miniconda.sh
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- conda update --all --yes
- conda config --add channels conda-forge -f
- conda create --yes -n TEST python=$TRAVIS_PYTHON_VERSION --file requirements.txt --file requirements-dev.txt
- source activate TEST
- travis_retry conda install --yes pytest # GUI
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- wget http://bit.ly/miniconda -O miniconda.sh
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- conda config --set always_yes yes --set changeps1 no --set show_channel_urls true
- conda update conda
- conda config --add channels conda-forge --force
- conda create -n TEST python=$TRAVIS_PYTHON_VERSION --file requirements.txt --file requirements-dev.txt
- source activate TEST
# GUI
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"

# Test source distribution.
install:
- python setup.py sdist && version=$(python setup.py --version) && pushd dist && pip install ctd-${version}.tar.gz && popd
- python setup.py sdist && version=$(python setup.py --version) && pushd dist && pip install ctd-${version}.tar.gz && popd

script:
- if [[ $TEST_TARGET == 'default' ]]; then
py.test -vv ;
fi
- if [[ $TEST_TARGET == 'default' ]]; then
py.test -s -rxs -v tests ;
fi

- if [[ $TEST_TARGET == 'doctest' ]]; then
py.test -s -rxs --doctest-modules -vv ctd ;
fi

- if [[ $TEST_TARGET == 'coding_standards' ]]; then
find . -type f -name "*.py" ! -name 'conf.py' | xargs flake8 --max-line-length=100 ;
fi
- if [[ $TEST_TARGET == 'coding_standards' ]]; then
flake8 --max-line-length=100 ctd ;
flake8 --max-line-length=100 tests ;
fi
23 changes: 7 additions & 16 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
The MIT License (MIT)
Copyright 2017 Filipe Fernandes

Copyright (c) 2013 Filipe
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include README.rst
include *.txt
include ctd/*.py
recursive-include ctd *.py
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ python-ctd
.. image:: http://img.shields.io/travis/pyoceans/python-ctd/master.svg?style=flat
:target: https://travis-ci.org/pyoceans/python-ctd
:alt: Build_status
.. image:: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
.. image:: http://img.shields.io/badge/license-BSD-blue.svg?style=flat
:target: https://github.com/pyoceans/python-ctd/blob/master/LICENSE.txt
:alt: license

Expand Down
60 changes: 49 additions & 11 deletions ctd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,56 @@
from __future__ import absolute_import, unicode_literals
from __future__ import (absolute_import, division, print_function)

__version__ = '0.2.3'
__version__ = '0.3.0'

from pandas import Index, Series, DataFrame
from pandas import DataFrame, Index, Series

from .ctd import asof, from_edf, from_cnv, from_fsi, rosette_summary
from .processing import (data_conversion, align, despike, lp_filter,
cell_thermal_mass, press_check, bindata, split,
movingaverage, pmel_inversion_check, smooth,
mixed_layer_depth, barrier_layer_thickness,
derive_cnv)
from .plotting import (get_maxdepth, extrap_sec, gen_topomask, plot, plot_vars,
plot_section)
from .ctd import asof, from_cnv, from_edf, from_fsi, rosette_summary
from .plotting import (
extrap_sec,
gen_topomask,
get_maxdepth,
plot,
plot_section,
plot_vars,
)
from .processing import (
barrier_layer_thickness,
bindata,
cell_thermal_mass,
derive_cnv,
despike,
lp_filter,
mixed_layer_depth,
movingaverage,
press_check,
smooth,
split,
)

__all__ = [
asof,
barrier_layer_thickness,
bindata,
cell_thermal_mass,
derive_cnv,
despike,
extrap_sec,
from_cnv,
from_edf,
from_fsi,
gen_topomask,
get_maxdepth,
lp_filter,
mixed_layer_depth,
movingaverage,
plot,
plot_section,
plot_vars,
press_check,
rosette_summary,
smooth,
split,
]

# Attach methods.
Index.asof = asof
Expand Down
26 changes: 10 additions & 16 deletions ctd/ctd.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
from __future__ import absolute_import, unicode_literals
from __future__ import (absolute_import, division, print_function)

# Standard library.
import os
import warnings

# Scientific stack.
import numpy as np

from pandas import DataFrame
from pandas import read_table

from .utilities import read_file, basename, normalize_names

data_path = os.path.join(os.path.dirname(__file__), 'tests', 'data')
from .utilities import basename, normalize_names, read_file

__all__ = ['CTD',
'asof',
'from_edf',
'from_cnv',
'from_fsi',
'rosette_summary']
data_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)), 'tests', 'data'
)


# TODO: https://github.com/nilmtk/nilmtk/issues/83
def asof(self, label):
"""FIXME: pandas index workaround."""
"""pandas index workaround."""
if label not in self:
loc = self.searchsorted(label, side='left')
if loc > 0:
Expand Down Expand Up @@ -178,7 +171,7 @@ def from_cnv(fname, compression=None, below_water=False, lon=None,
elif hemisphere == 'N':
lat = lat[0] + lat[1] / 60.
else:
raise ValueError("Latitude not recognized.")
raise ValueError('Latitude not recognized.')
if 'NMEA Longitude' in line:
hemisphere = line[-1]
lon = line.strip(hemisphere).split('=')[1].strip()
Expand All @@ -188,7 +181,7 @@ def from_cnv(fname, compression=None, below_water=False, lon=None,
elif hemisphere == 'E':
lon = lon[0] + lon[1] / 60.
else:
raise ValueError("Latitude not recognized.")
raise ValueError('Latitude not recognized.')
if line == '*END*': # Get end of header.
skiprows = k + 1
break
Expand Down Expand Up @@ -280,6 +273,7 @@ def rosette_summary(fname):
ros.set_index('nbf', drop=True, inplace=True, verify_integrity=False)
return ros


if __name__ == '__main__':
import doctest
doctest.testmod()
56 changes: 24 additions & 32 deletions ctd/plotting.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

# Scientific stack.
import numpy as np
import numpy.ma as ma
from __future__ import (absolute_import, division, print_function)

import matplotlib.pyplot as plt

import mpl_toolkits.axisartist as AA

from pandas import Series
from mpl_toolkits.axes_grid1 import host_subplot

from .utilities import extrap1d
import numpy as np
import numpy.ma as ma

__all__ = ['get_maxdepth',
'extrap_sec',
'gen_topomask',
'plot',
'plot_vars',
'plot_section']
from pandas import Series

from .utilities import extrap1d


def get_maxdepth(self):
Expand Down Expand Up @@ -159,20 +155,20 @@ def plot_vars(self, variables=None, **kwds):

# Axis location.
host_new_axis = ax0.get_grid_helper().new_fixed_axis
ax0.axis["bottom"] = host_new_axis(loc="top", axes=ax0, offset=(0, 0))
ax0.axis['bottom'] = host_new_axis(loc='top', axes=ax0, offset=(0, 0))
par_new_axis = ax1.get_grid_helper().new_fixed_axis
ax1.axis["top"] = par_new_axis(loc="bottom", axes=ax1, offset=(0, 0))
ax1.axis['top'] = par_new_axis(loc='bottom', axes=ax1, offset=(0, 0))

ax0.plot(self[variables[0]], self.index, 'r.', label='Temperature')
ax1.plot(self[variables[1]], self.index, 'b.', label='Salinity')

ax0.set_ylabel("Pressure [dbar]")
ax0.set_xlabel("Temperature [\u00b0C]")
ax1.set_xlabel("Salinity [kg g$^{-1}$]")
ax0.set_ylabel('Pressure [dbar]')
ax0.set_xlabel('Temperature [\u00b0C]')
ax1.set_xlabel('Salinity [kg g$^{-1}$]')
ax1.invert_yaxis()

try: # FIXME with metadata.
fig.suptitle(r"Station %s profile" % self.name)
try:
fig.suptitle(r'Station %s profile' % self.name)
except AttributeError:
pass

Expand Down Expand Up @@ -202,10 +198,11 @@ def plot_section(self, reverse=False, filled=False, **kw):
lat = lat[::-1]
data = data.T[::-1].T
h = h[::-1]
lon, lat = map(np.atleast_2d, (lon, lat))
x = np.append(0, np.cumsum(gsw.distance(lon, lat)[0] / 1e3))
z = self.index.values.astype(float)

if filled: # FIXME: Cause discontinuities.
if filled: # CAVEAT: this method cause discontinuities.
data = data.filled(fill_value=np.nan)
data = extrap_sec(data, x, z, w1=0.97, w2=0.03)

Expand Down Expand Up @@ -257,18 +254,13 @@ def plot_section(self, reverse=False, filled=False, **kw):
ax.xaxis.set_tick_params(tickdir='out', labelsize=labelsize, pad=1)
ax.yaxis.set_tick_params(tickdir='out', labelsize=labelsize, pad=1)

if False: # TODO: +/- Black-and-White version.
cs = ax.contour(x, z, data, colors='grey', levels=levels,
extend=extend, linewidths=1., alpha=1., zorder=2)
ax.clabel(cs, fontsize=8, colors='grey', fmt=fmt, zorder=1)
cb = None
if True: # Color version.
cs = ax.contourf(x, z, data, cmap=cmap, levels=levels, alpha=1.,
extend=extend, zorder=2) # manual=True
# Colorbar.
cb = fig.colorbar(mappable=cs, ax=ax, orientation='vertical',
aspect=aspect, shrink=shrink, fraction=fraction,
pad=pad)
# Color version.
cs = ax.contourf(x, z, data, cmap=cmap, levels=levels, alpha=1.,
extend=extend, zorder=2) # manual=True
# Colorbar.
cb = fig.colorbar(mappable=cs, ax=ax, orientation='vertical',
aspect=aspect, shrink=shrink, fraction=fraction,
pad=pad)
return fig, ax, cb


Expand Down
Loading