Skip to content

Commit

Permalink
ruff auto fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Jun 18, 2024
1 parent 26130aa commit 69f5893
Show file tree
Hide file tree
Showing 25 changed files with 1,635 additions and 1,654 deletions.
71 changes: 35 additions & 36 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# ioos_qc documentation build configuration file, created by
# sphinx-quickstart on Thu Aug 18 10:56:41 2016.
Expand All @@ -21,7 +20,7 @@
import sys

p = os.path.abspath(
os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
)
sys.path.insert(0, p)

Expand All @@ -35,13 +34,13 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.napoleon',
'sphinx.ext.todo',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx_autodoc_typehints',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx_autodoc_typehints",
"nbsphinx",
]

Expand All @@ -59,25 +58,25 @@
napoleon_use_rtype = True

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = ['.rst']
source_suffix = [".rst"]

# The encoding of source files.
#
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'ioos_qc'
copyright = '2022, IOOS'
author = 'IOOS'
project = "ioos_qc"
copyright = "2022, IOOS"
author = "IOOS"

# The version info for the project yo're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -108,8 +107,8 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns += ['examples/usage/*.ipynb']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
exclude_patterns += ["examples/usage/*.ipynb"]

# The reST default role (used for this markup: `text`) to use for all
# documents.
Expand All @@ -131,7 +130,7 @@
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
Expand All @@ -148,17 +147,17 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
'description': 'IOOS QARTOD and other Quality Control tests implemented in Python',
'github_user': 'ioos',
'github_repo': 'ioos_qc',
'github_button': 'true',
"description": "IOOS QARTOD and other Quality Control tests implemented in Python",
"github_user": "ioos",
"github_repo": "ioos_qc",
"github_button": "true",
}

# Add any paths that contain custom themes here, relative to this directory.
Expand Down Expand Up @@ -187,7 +186,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
Expand Down Expand Up @@ -267,7 +266,7 @@
# html_search_scorer = 'scorer.js'

# Output file base name for HTML help builder.
htmlhelp_basename = 'ioos_qcdoc'
htmlhelp_basename = "ioos_qcdoc"

# -- Options for LaTeX output ---------------------------------------------

Expand All @@ -293,8 +292,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'ioos_qc.tex', 'ioos_qc Documentation',
'IOOS', 'manual'),
(master_doc, "ioos_qc.tex", "ioos_qc Documentation",
"IOOS", "manual"),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -337,11 +336,11 @@
man_pages = [
(
master_doc,
'ioos_qc',
'ioos_qc Documentation',
"ioos_qc",
"ioos_qc Documentation",
[author],
1
)
1,
),
]

# If true, show URL addresses after external links.
Expand All @@ -357,12 +356,12 @@
texinfo_documents = [
(
master_doc,
'ioos_qc',
'ioos_qc Documentation',
"ioos_qc",
"ioos_qc Documentation",
author,
'ioos_qc',
'Collection of utilities, scripts and tests to assist in automated quality assurance and quality control for oceanographic datasets and observing systems.',
'Miscellaneous'
"ioos_qc",
"Collection of utilities, scripts and tests to assist in automated quality assurance and quality control for oceanographic datasets and observing systems.",
"Miscellaneous",
),
]

Expand Down
1 change: 0 additions & 1 deletion ioos_qc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding=utf-8

try:
from ._version import __version__
Expand Down
42 changes: 22 additions & 20 deletions ioos_qc/argo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# coding=utf-8
"""Tests based on the ARGO QC manual."""
import logging
import warnings
Expand All @@ -9,29 +8,30 @@
import numpy as np

from ioos_qc.qartod import QartodFlags
from ioos_qc.utils import add_flag_metadata
from ioos_qc.utils import great_circle_distance
from ioos_qc.utils import mapdates
from ioos_qc.utils import add_flag_metadata, great_circle_distance, mapdates

L = logging.getLogger(__name__) # noqa
L = logging.getLogger(__name__)


@add_flag_metadata(stanard_name='pressure_increasing_test_quality_flag',
long_name='Pressure Increasing Test Quality Flag')
@add_flag_metadata(stanard_name="pressure_increasing_test_quality_flag",
long_name="Pressure Increasing Test Quality Flag")
def pressure_increasing_test(inp):
"""
Returns an array of flag values where each input is flagged with SUSPECT if
"""Returns an array of flag values where each input is flagged with SUSPECT if
it does not monotonically increase
Ref: ARGO QC Manual: 8. Pressure increasing test
Args:
----
inp: Pressure values as a numeric numpy array or a list of numbers.
Returns:
-------
A masked array of flag values equal in size to that of the input.
"""
delta = np.diff(inp)
flags = np.ones_like(inp, dtype='uint8') * QartodFlags.GOOD
flags = np.ones_like(inp, dtype="uint8") * QartodFlags.GOOD

# Correct for downcast vs upcast by flipping the sign if it's decreasing
sign = np.sign(np.mean(delta))
Expand All @@ -44,13 +44,13 @@ def pressure_increasing_test(inp):
return flags


@add_flag_metadata(standard_name='speed_test_quality_flag',
long_name='Speed Test Quality Flag')
@add_flag_metadata(standard_name="speed_test_quality_flag",
long_name="Speed Test Quality Flag")
def speed_test(lon: Sequence[N],
lat: Sequence[N],
tinp: Sequence[N],
suspect_threshold: float,
fail_threshold: float
fail_threshold: float,
) -> np.ma.core.MaskedArray:
"""Checks that the calculated speed between two points is within reasonable bounds.
Expand All @@ -67,6 +67,7 @@ def speed_test(lon: Sequence[N],
Ref: ARGO QC Manual: 5. Impossible speed test
Args:
----
lon: Longitudes as a numeric numpy array or a list of numbers.
lat: Latitudes as a numeric numpy array or a list of numbers.
tinp: Time data as a sequence of datetime objects compatible with pandas DatetimeIndex.
Expand All @@ -79,17 +80,18 @@ def speed_test(lon: Sequence[N],
Speeds exceeding this will be flagged as FAIL.
Returns:
-------
A masked array of flag values equal in size to that of the input.
"""
"""
with warnings.catch_warnings():
warnings.simplefilter("ignore")
lat = np.ma.masked_invalid(np.array(lat).astype(np.float64))
lon = np.ma.masked_invalid(np.array(lon).astype(np.float64))
tinp = mapdates(tinp)

if lon.shape != lat.shape or lon.shape != tinp.shape:
raise ValueError(f'Lon ({lon.shape}) and lat ({lat.shape}) and tinp ({tinp.shape}) must be the same shape')
raise ValueError(f"Lon ({lon.shape}) and lat ({lat.shape}) and tinp ({tinp.shape}) must be the same shape")

# Save original shape
original_shape = lon.shape
Expand All @@ -102,7 +104,7 @@ def speed_test(lon: Sequence[N],
return np.ma.masked_array([])

# Start with everything as passing
flag_arr = QartodFlags.GOOD * np.ma.ones(lon.size, dtype='uint8')
flag_arr = QartodFlags.GOOD * np.ma.ones(lon.size, dtype="uint8")

# If either lon or lat are masked we just set the flag to MISSING
mloc = lon.mask & lat.mask
Expand All @@ -117,13 +119,13 @@ def speed_test(lon: Sequence[N],
dist = great_circle_distance(lat, lon)

# calculate speed in m/s
speed = np.ma.zeros(tinp.size, dtype='float')
speed[1:] = np.abs(dist[1:] / np.diff(tinp).astype('timedelta64[s]').astype(float))
speed = np.ma.zeros(tinp.size, dtype="float")
speed[1:] = np.abs(dist[1:] / np.diff(tinp).astype("timedelta64[s]").astype(float))

with np.errstate(invalid='ignore'):
with np.errstate(invalid="ignore"):
flag_arr[speed > suspect_threshold] = QartodFlags.SUSPECT

with np.errstate(invalid='ignore'):
with np.errstate(invalid="ignore"):
flag_arr[speed > fail_threshold] = QartodFlags.FAIL

# first value is unknown, since we have no speed data for the first point
Expand Down
31 changes: 14 additions & 17 deletions ioos_qc/axds.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
#!/usr/bin/env python
# coding=utf-8
"""Tests based on the IOOS QARTOD manuals."""
import logging
from typing import Tuple, Sequence
from collections import namedtuple
from typing import Sequence, Tuple

import numpy as np

from ioos_qc.utils import (
isnan,
add_flag_metadata,
mapdates
)
from ioos_qc.qartod import QartodFlags
from ioos_qc.utils import add_flag_metadata, isnan, mapdates

L = logging.getLogger(__name__) # noqa
L = logging.getLogger(__name__)

FLAGS = QartodFlags # Default name for all check modules
NOTEVAL_VALUE = QartodFlags.UNKNOWN

span = namedtuple('Span', 'minv maxv')
span = namedtuple("Span", "minv maxv")


@add_flag_metadata(standard_name='gross_range_test_quality_flag',
long_name='Gross Range Test Quality Flag')
@add_flag_metadata(standard_name="gross_range_test_quality_flag",
long_name="Gross Range Test Quality Flag")
def valid_range_test(inp : Sequence[any],
valid_span : Tuple[any, any],
dtype : np.dtype = None,
Expand All @@ -41,6 +36,7 @@ def valid_range_test(inp : Sequence[any],
behavior you can use the parameters `start_inclusive` and `end_inclusive`.
Args:
----
inp (Sequence[any]): Data as a sequence of objects compatible with the fail_span objects
fail_span (Tuple[any, any]): 2-tuple range which to flag outside data as FAIL. Objects
should be of equal format to that of the inp parameter as they will be checked for
Expand All @@ -53,17 +49,18 @@ def valid_range_test(inp : Sequence[any],
exclusive (False).
Returns:
-------
np.ma.core.MaskedArray: A masked array of flag values equal in size to that of the input.
"""
"""
# Numpy array inputs
if dtype is None and hasattr(inp, 'dtype'):
if dtype is None and hasattr(inp, "dtype"):
dtype = inp.dtype
# Pandas column inputs
# This is required because we don't want to restrict a user from using a pd.Series
# directly with this function. If the data was coming from a Store, it would
# always be a numpy array.
elif dtype is None and hasattr(inp, 'values') and hasattr(inp.values, 'dtype'):
elif dtype is None and hasattr(inp, "values") and hasattr(inp.values, "dtype"):
dtype = inp.values.dtype

# Save original shape
Expand Down Expand Up @@ -92,18 +89,18 @@ def valid_range_test(inp : Sequence[any],
inp = inp.flatten()

# Start with everything as passing (1)
flag_arr = np.ma.ones(inp.size, dtype='uint8')
flag_arr = np.ma.ones(inp.size, dtype="uint8")

# Set fail on either side of the bounds, inclusive and exclusive
if not isnan(valid_span[0]):
with np.errstate(invalid='ignore'):
with np.errstate(invalid="ignore"):
if start_inclusive is True:
flag_arr[inp < valid_span[0]] = QartodFlags.FAIL
else:
flag_arr[inp <= valid_span[0]] = QartodFlags.FAIL

if not isnan(valid_span[1]):
with np.errstate(invalid='ignore'):
with np.errstate(invalid="ignore"):
if end_inclusive is True:
flag_arr[inp > valid_span[1]] = QartodFlags.FAIL
else:
Expand Down
Loading

0 comments on commit 69f5893

Please sign in to comment.