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
1 change: 0 additions & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/action@v2.0.0

17 changes: 9 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ repos:
hooks:
- id: check-ast
- id: end-of-file-fixer
exclude: github_deploy_key.enc
- id: check-docstring-first
- id: check-added-large-files
- id: requirements-txt-fixer
Expand All @@ -14,18 +15,18 @@ repos:
- id: debug-statements

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
rev: 3.9.0
hooks:
- id: flake8
exclude: docs/source/conf.py
args: [--max-line-length=105]
args: [--max-line-length=105, "--ignore=E203,W503"]

- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.7.0
- repo: https://github.com/pycqa/isort
rev: 5.7.0
hooks:
- id: isort
additional_dependencies: [toml]
args: [--project=oceans, --multi-line=3, --lines-after-imports=2, --lines-between-types=1, --trailing-comma, --force-grid-wrap=0, --use-parentheses, --line-width=88]
- id: isort
additional_dependencies: [toml]
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/psf/black
rev: 20.8b1
Expand All @@ -43,4 +44,4 @@ repos:
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.1.0
hooks:
- id: add-trailing-comma
- id: add-trailing-comma
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ matrix:
env: PY=3.8
- name: "doctests"
env: PY=3
- name: "coding_standards"
env: PY=3
- name: "tarball"
env: PY=3
- name: "docs"
Expand Down Expand Up @@ -60,10 +58,6 @@ script:
- if [[ $TRAVIS_JOB_NAME == doctests ]]; then
pytest -vv oceans --doctest-modules ;
fi

- if [[ $TRAVIS_JOB_NAME == 'coding_standards' ]]; then
pytest --flake8 -m flake8 ;
fi

- |
if [[ $TRAVIS_JOB_NAME == 'docs' ]]; then
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ Version 0.1.0

Version 0.0.1

* Initial release.
* Initial release.
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ help:
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
2 changes: 1 addition & 1 deletion docs/source/RPSstuff.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
.. automodule:: oceans.RPSstuff
:members:
:undoc-members:
:show-inheritance:
:show-inheritance:
2 changes: 1 addition & 1 deletion docs/source/colormaps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
.. automodule:: oceans.colormaps
:members:
:undoc-members:
:show-inheritance:
:show-inheritance:
4 changes: 1 addition & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
Expand All @@ -25,7 +24,6 @@

from oceans._version import get_versions


version = release = get_versions()["version"]
del get_versions

Expand Down Expand Up @@ -116,7 +114,7 @@
"relations.html", # needs 'show_related': True theme option to display
"searchbox.html",
"donate.html",
]
],
}


Expand Down
2 changes: 1 addition & 1 deletion docs/source/datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
.. automodule:: oceans.datasets
:members:
:undoc-members:
:show-inheritance:
:show-inheritance:
2 changes: 1 addition & 1 deletion docs/source/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
.. automodule:: oceans.filters
:members:
:undoc-members:
:show-inheritance:
:show-inheritance:
2 changes: 1 addition & 1 deletion docs/source/ocfis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
.. automodule:: oceans.ocfis
:members:
:undoc-members:
:show-inheritance:
:show-inheritance:
2 changes: 1 addition & 1 deletion docs/source/plotting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
.. automodule:: oceans.plotting
:members:
:undoc-members:
:show-inheritance:
:show-inheritance:
1 change: 0 additions & 1 deletion oceans/RPSstuff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import numpy as np
import numpy.ma as ma


earth_radius = 6371.0e3


Expand Down
1 change: 0 additions & 1 deletion oceans/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ._version import get_versions # noqa


__version__ = get_versions()["version"]
del get_versions
32 changes: 11 additions & 21 deletions oceans/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ def decorate(f):
return decorate


def run_command(
commands, args, cwd=None, verbose=False, hide_stderr=False, env=None
):
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None):
"""Call the given command(s)."""
assert isinstance(commands, list)
p = None
Expand All @@ -86,7 +84,7 @@ def run_command(
stderr=(subprocess.PIPE if hide_stderr else None),
)
break
except EnvironmentError:
except OSError:
e = sys.exc_info()[1]
if e.errno == errno.ENOENT:
continue
Expand All @@ -96,7 +94,7 @@ def run_command(
return None, None
else:
if verbose:
print("unable to find command, tried %s" % (commands,))
print(f"unable to find command, tried {commands}")
return None, None
stdout = p.communicate()[0].strip()
if sys.version_info[0] >= 3:
Expand Down Expand Up @@ -135,7 +133,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
if verbose:
print(
"Tried directories %s but none started with prefix %s"
% (str(rootdirs), parentdir_prefix)
% (str(rootdirs), parentdir_prefix),
)
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")

Expand All @@ -149,7 +147,7 @@ def git_get_keywords(versionfile_abs):
# _version.py.
keywords = {}
try:
f = open(versionfile_abs, "r")
f = open(versionfile_abs)
for line in f.readlines():
if line.strip().startswith("git_refnames ="):
mo = re.search(r'=\s*"(.*)"', line)
Expand All @@ -164,7 +162,7 @@ def git_get_keywords(versionfile_abs):
if mo:
keywords["date"] = mo.group(1)
f.close()
except EnvironmentError:
except OSError:
pass
return keywords

Expand Down Expand Up @@ -243,9 +241,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"]

out, rc = run_command(
GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True
)
out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True)
if rc != 0:
if verbose:
print("Directory %s not under git control" % root)
Expand Down Expand Up @@ -297,9 +293,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
if not mo:
# unparseable. Maybe git-describe is misbehaving?
pieces["error"] = (
"unable to parse git-describe output: '%s'" % describe_out
)
pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
return pieces

# tag
Expand All @@ -308,7 +302,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
if verbose:
fmt = "tag '%s' doesn't start with prefix '%s'"
print(fmt % (full_tag, tag_prefix))
pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (
pieces["error"] = "tag '{}' doesn't start with prefix '{}'".format(
full_tag,
tag_prefix,
)
Expand All @@ -324,9 +318,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
else:
# HEX: no tags
pieces["closest-tag"] = None
count_out, rc = run_command(
GITS, ["rev-list", "HEAD", "--count"], cwd=root
)
count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], cwd=root)
pieces["distance"] = int(count_out) # total number of commits

# commit date: see ISO-8601 comment in git_versions_from_keywords()
Expand Down Expand Up @@ -523,9 +515,7 @@ def get_versions():
verbose = cfg.verbose

try:
return git_versions_from_keywords(
get_keywords(), cfg.tag_prefix, verbose
)
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, verbose)
except NotThisMethod:
pass

Expand Down
7 changes: 2 additions & 5 deletions oceans/colormaps.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import os

from colorsys import hsv_to_rgb
from glob import glob

import matplotlib.pyplot as plt
import numpy as np

from matplotlib import colors


cmap_path = os.path.join(os.path.dirname(__file__), "cmap_data")


Expand All @@ -26,7 +23,7 @@ def get_color(color):
for hue in range(color):
hue = 1.0 * hue / color
col = [int(x) for x in hsv_to_rgb(hue, 1.0, 230)]
yield "#{0:02x}{1:02x}{2:02x}".format(*col)
yield "#{:02x}{:02x}{:02x}".format(*col)


def cmat2cmpl(rgb, reverse=False):
Expand Down Expand Up @@ -160,7 +157,7 @@ def demo():
data = np.outer(np.arange(0, 1, 0.01), np.ones(10))
fig = plt.figure(figsize=(10, 5))
fig.subplots_adjust(top=0.8, bottom=0.05, left=0.01, right=0.99)
cmaps = sorted((m for m in cm.keys() if not m.endswith("_r")))
cmaps = sorted(m for m in cm.keys() if not m.endswith("_r"))
length = len(cmaps)
for k, cmap in enumerate(cmaps):
plt.subplot(1, length + 1, k + 1)
Expand Down
21 changes: 7 additions & 14 deletions oceans/datasets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import warnings

import numpy as np

from netCDF4 import Dataset

from oceans.ocfis import get_profile, wrap_lon180
Expand All @@ -21,7 +20,7 @@ def _woa_variable(variable):
v = _VAR.get(variable)
if not v:
raise ValueError(
f'Unrecognizable variable. Expected one of {list(_VAR.keys())}, got "{variable}".'
f'Unrecognizable variable. Expected one of {list(_VAR.keys())}, got "{variable}".',
)
return v

Expand All @@ -35,7 +34,7 @@ def _woa_url(variable, time_period, resolution):
pref = "woa09"
warnings.warn(
f'The variable "{variable}" is only available at 1 degree resolution, '
f'annual time period, and "{pref}".'
f'annual time period, and "{pref}".',
)
return f"{base}/" f"{pref}/" f"{variable}_annual_1deg.nc"
else:
Expand All @@ -50,7 +49,7 @@ def _woa_url(variable, time_period, resolution):
grid = grids.get(resolution)
if not grid:
raise ValueError(
f'Unrecognizable resolution. Expected one of {list(grids.keys())}, got "{resolution}".'
f'Unrecognizable resolution. Expected one of {list(grids.keys())}, got "{resolution}".',
)
res = grid[0]
gg = grid[1]
Expand Down Expand Up @@ -90,7 +89,7 @@ def _woa_url(variable, time_period, resolution):
if not tt:
raise ValueError(
f"Unrecognizable time_period. "
f'Expected one of {list(time_periods.keys())}, got "{time_period}".'
f'Expected one of {list(time_periods.keys())}, got "{time_period}".',
)

url = (
Expand All @@ -102,9 +101,7 @@ def _woa_url(variable, time_period, resolution):
return url


def woa_profile(
lon, lat, variable="temperature", time_period="annual", resolution="1"
):
def woa_profile(lon, lat, variable="temperature", time_period="annual", resolution="1"):
"""
Return an iris.cube instance from a World Ocean Atlas variable at a
given lon, lat point.
Expand Down Expand Up @@ -143,9 +140,7 @@ def woa_profile(
"""
import iris

url = _woa_url(
variable=variable, time_period=time_period, resolution=resolution
)
url = _woa_url(variable=variable, time_period=time_period, resolution=resolution)

with warnings.catch_warnings():
warnings.simplefilter("ignore")
Expand Down Expand Up @@ -222,9 +217,7 @@ def woa_subset(
url = _woa_url(variable, time_period, resolution)
cubes = iris.load_raw(url)
cubes = [
cube.intersection(
longitude=(bbox[0], bbox[1]), latitude=(bbox[2], bbox[3])
)
cube.intersection(longitude=(bbox[0], bbox[1]), latitude=(bbox[2], bbox[3]))
for cube in cubes
]

Expand Down
Loading