Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Jun 19, 2024
1 parent 3252c3f commit a2e4e45
Show file tree
Hide file tree
Showing 37 changed files with 2,143 additions and 878 deletions.
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,3 @@ importance of writing tested and maintainable software.

* [How to Contribute to Open Source Guide](https://opensource.guide/how-to-contribute/)
* [Zen of Scientific Software Maintenance](https://jrleeman.github.io/ScientificSoftwareMaintenance/)


1 change: 0 additions & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,3 @@ Apache License
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

12 changes: 7 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -290,8 +287,13 @@
# (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
2 changes: 1 addition & 1 deletion docs/source/examples/usage/Config.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion docs/source/examples/usage/ContextConfig.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion docs/source/examples/usage/NetcdfStream.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion docs/source/examples/usage/NumpyStream.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion docs/source/examples/usage/PandasStream.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion docs/source/examples/usage/XarrayStream.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,4 @@
]
}
]
}
}
1 change: 0 additions & 1 deletion docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ Installation
Install with `conda <https://docs.conda.io/en/latest/>`_::

$ conda install -c conda-forge ioos_qc

1 change: 0 additions & 1 deletion docs/source/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,3 @@ Specific changes to be aware of include:
####################

See https://github.com/ioos/qartod and https://ioos.github.io/qartod/

30 changes: 19 additions & 11 deletions ioos_qc/argo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Tests based on the ARGO QC manual."""

import logging
import warnings
from numbers import Real as N
Expand All @@ -13,8 +14,10 @@
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
it does not monotonically increase.
Expand Down Expand Up @@ -44,14 +47,17 @@ def pressure_increasing_test(inp):
return flags


@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,
) -> np.ma.core.MaskedArray:
@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,
) -> np.ma.core.MaskedArray:
"""Checks that the calculated speed between two points is within reasonable bounds.
This test calculates a speed between subsequent points by
Expand Down Expand Up @@ -121,7 +127,9 @@ def speed_test(lon: Sequence[N],

# 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[1:] = np.abs(
dist[1:] / np.diff(tinp).astype("timedelta64[s]").astype(float),
)

with np.errstate(invalid="ignore"):
flag_arr[speed > suspect_threshold] = QartodFlags.SUSPECT
Expand Down
37 changes: 25 additions & 12 deletions ioos_qc/axds.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Tests based on the IOOS QARTOD manuals."""

import logging
from collections import namedtuple
from typing import Sequence, Tuple
Expand All @@ -17,14 +18,17 @@
span = namedtuple("Span", "minv maxv")


@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,
start_inclusive : bool = True,
end_inclusive : bool = False,
) -> np.ma.core.MaskedArray:
@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,
start_inclusive: bool = True,
end_inclusive: bool = False,
) -> np.ma.core.MaskedArray:
"""Checks that values are within a min/max range. This is not unlike a `qartod.gross_range_test`
with fail and suspect bounds being equal, except that here we specify the inclusive range that
should pass instead of the exclusive bounds which should fail. This also supports datetime-like
Expand Down Expand Up @@ -60,14 +64,20 @@ def valid_range_test(inp : Sequence[any],
# 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
original_shape = inp.shape

if dtype is None:
L.warning("Trying to guess data input type, try specifying the dtype parameter")
L.warning(
"Trying to guess data input type, try specifying the dtype parameter",
)
# Try to figure out the dtype so masked values can be calculated
try:
# Try datetime-like objects
Expand All @@ -77,12 +87,15 @@ def valid_range_test(inp : Sequence[any],
try:
# Try floating point numbers
inp = np.ma.masked_invalid(np.array(inp).astype(np.floating))
valid_span = np.ma.masked_invalid(np.array(valid_span).astype(np.floating))
valid_span = np.ma.masked_invalid(
np.array(valid_span).astype(np.floating),
)
except BaseException:
# Well, we tried.
msg = "Could not determine the type of input, try using the dtype parameter"
raise ValueError(
msg)
msg,
)
else:
inp = np.ma.masked_invalid(np.array(inp, dtype=dtype))
valid_span = np.ma.masked_invalid(np.array(valid_span, dtype=dtype))
Expand Down
Loading

0 comments on commit a2e4e45

Please sign in to comment.