Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #55

Closed
wants to merge 4 commits into from
Closed

Dev #55

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
62 changes: 44 additions & 18 deletions cc_plugin_glider/glider_dac.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class GliderCheck(BaseNCCheck):
_cc_display_headers = {3: "Required", 2: "Recommended", 1: "Suggested"}
acceptable_platform_types = {"Seaglider", "Spray Glider", "Slocum Glider"}

def __init__(self):
def __init__(self, options=None):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jr3cermak do you want a generic options kw or should we name this skip_variables? I may not be understanding what you want to do but it seems that it is the latter, right?

# Pass through testing options for gliderdac
self.options = options
# try to get the sea names table
ncei_base_table_url = "https://gliders.ioos.us/ncei_authority_tables/"
# might refactor if the authority tables names change
Expand Down Expand Up @@ -201,7 +203,11 @@ def check_lat_lon_attributes(self, dataset):

check_vars = ["lat", "lon"]
for var in check_vars:
stat, num_checks, msgs = util._check_variable_attrs(dataset, var)
stat, num_checks, msgs = util._check_variable_attrs(
dataset,
var,
options=self.options,
)
score += int(stat)
out_of += num_checks
messages.extend(msgs)
Expand Down Expand Up @@ -236,7 +242,11 @@ def check_pressure_depth_attributes(self, dataset):

check_vars = ["pressure", "depth"]
for var in check_vars:
stat, num_checks, msgs = util._check_variable_attrs(dataset, var)
stat, num_checks, msgs = util._check_variable_attrs(
dataset,
var,
options=self.options,
)
score += int(stat)
out_of += num_checks
messages.extend(msgs)
Expand All @@ -261,7 +271,11 @@ def check_ctd_variable_attributes(self, dataset):

check_vars = ["temperature", "conductivity", "salinity", "density"]
for var in check_vars:
stat, num_checks, msgs = util._check_variable_attrs(dataset, var)
stat, num_checks, msgs = util._check_variable_attrs(
dataset,
var,
options=self.options,
)
score += int(stat)
out_of += num_checks
messages.extend(msgs)
Expand Down Expand Up @@ -289,7 +303,11 @@ def check_profile_variable_attributes_and_types(self, dataset):
"v",
]
for var in check_vars:
stat, num_checks, msgs = util._check_variable_attrs(dataset, var)
stat, num_checks, msgs = util._check_variable_attrs(
dataset,
var,
options=self.options,
)
score += int(stat)
out_of += num_checks
messages.extend(msgs)
Expand Down Expand Up @@ -596,7 +614,11 @@ def check_container_variables(self, dataset):
"instrument_ctd",
]
for var in check_vars:
stat, num_checks, msgs = util._check_variable_attrs(dataset, var)
stat, num_checks, msgs = util._check_variable_attrs(
dataset,
var,
options=self.options,
)
score += int(stat)
out_of += num_checks
messages.extend(msgs)
Expand Down Expand Up @@ -653,8 +675,7 @@ def check_qartod(self, dataset):
dtype = flag_values.dtype
test_ctx.assert_true(
util.compare_dtype(dtype, np.dtype("|i1")),
f"attribute {qartod_var}:flag_values has an illegal data-type, must "
"be byte",
f"attribute {qartod_var}:flag_values has an illegal data-type, must be byte",
)

valid_min_dtype = getattr(valid_min, "dtype", None)
Expand Down Expand Up @@ -692,10 +713,7 @@ def check_ancillary_variables(self, dataset):
test = acv in dataset.variables
score += int(test)
if not test:
msg = (
f"Invalid ancillary_variables attribute for {var}, "
f"{acv} is not a variable"
)
msg = f"Invalid ancillary_variables attribute for {var}, {acv} is not a variable"
messages.append(msg)

return self.make_result(level, score, out_of, "Ancillary Variables", messages)
Expand Down Expand Up @@ -746,8 +764,7 @@ def check_valid_min_dtype(self, dataset):
if valid_min is not None:
test_ctx.assert_true(
util.compare_dtype(np.dtype(valid_min_dtype), ncvar.dtype),
f"{var_name}:valid_min has a different data type, {valid_min_dtype}, than variable {var_name}, "
f"{str(ncvar.dtype)}",
f"{var_name}:valid_min has a different data type, {valid_min_dtype}, than variable {var_name}, {ncvar.dtype}",
)

return test_ctx.to_result()
Expand All @@ -774,8 +791,7 @@ def check_valid_max_dtype(self, dataset):
if valid_max is not None:
test_ctx.assert_true(
util.compare_dtype(np.dtype(valid_max_dtype), ncvar.dtype),
f"{var_name}:valid_max has a different data type, {valid_max_dtype}, than variable {str(ncvar.dtype)} "
f"{var_name}",
f"{var_name}:valid_max has a different data type, {valid_max_dtype}, than variable {ncvar.dtype} {var_name}",
)

return test_ctx.to_result()
Expand Down Expand Up @@ -814,8 +830,18 @@ def check_valid_lon(self, dataset):
return

longitude = dataset.variables["lon"]
valid_min = longitude.valid_min
valid_max = longitude.valid_max
valid_min = getattr(longitude, "valid_min", None)
if valid_min is None:
test_ctx.assert_true(
False,
"valid_min attribute for longitude should be defined",
)
valid_max = getattr(longitude, "valid_max", None)
if valid_min is None:
test_ctx.assert_true(
False,
"valid_max attribute for longitude should be defined",
)
test_ctx.assert_true(
not (valid_min == -90 and valid_max == 90),
"Longitude's valid_min and valid_max are [-90, 90], it's likely this was a mistake",
Expand Down
7 changes: 5 additions & 2 deletions cc_plugin_glider/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _check_dtype(dataset, var_name):
if not compare_dtype(var.dtype, np.dtype(expected_dtype)):
messages.append(
f"Variable {var_name} is expected to have a dtype of "
f"{var.dtype}, instead has a dtype of {expected_dtype}"
f"{expected_dtype}, instead has a dtype of {var.dtype}"
"",
)
score -= 1
Expand All @@ -58,7 +58,7 @@ def _check_dtype(dataset, var_name):
return (score, out_of, messages)


def _check_variable_attrs(dataset, var_name, required_attributes=None):
def _check_variable_attrs(dataset, var_name, required_attributes=None, options=None):
"""
Convenience method to check a variable attributes based on the
expected_vars dict
Expand All @@ -74,6 +74,9 @@ def _check_variable_attrs(dataset, var_name, required_attributes=None):

# Get the expected attrs to check
check_attrs = required_attributes or required_var_attrs.get(var_name, {})
if not options is None:
if "ancillary_variables" in check_attrs and "no_ancillary_variables" in options:
del check_attrs["ancillary_variables"]
var_attrs = set(var.ncattrs())
for attr in check_attrs:
if attr == "dtype":
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ tag_regex = "^(?P<prefix>v)?(?P<version>[^\\+]+)(?P<suffix>.*)?$"
target-version = "py38"
line-length = 79

lint.select = [
"A", # flake8-builtins
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"F", # flakes
"I", # import sorting
"T20", # flake8-print
"UP", # upgrade
]
select = [
"A", # flake8-builtins
"B", # flake8-bugbear
Expand Down
Loading