-
Notifications
You must be signed in to change notification settings - Fork 9
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
test: cf checker #127
Merged
Merged
test: cf checker #127
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c5e4bfe
chore: refactor to stop using the cache (#95)
renaudjester e3c889a
trying how the github handles the compiance checker
uriii3 e404c10
chore: adding compliance-checker to the conda environment
uriii3 15cce07
chore: removing the coliance checker from the actual toolbox
uriii3 cede168
chore: updating poetry lock
uriii3 e2fd350
chore: refining the tests and adding a new id
uriii3 86a93b0
chore: refining the output of the checker
uriii3 e017b0a
fix: without the print
uriii3 3414b0c
some change to commit again
uriii3 7fb2a2a
some change to commit again
uriii3 e5996dc
fix: conventions are the ones from the dataset
uriii3 23de953
fix: update the snapshots
uriii3 cc64105
fix: solve valid_min_max problems
uriii3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# serializer version: 1 | ||
# name: TestCFCompliance.test_subset_open | ||
'cmems_mod_nws_bgc-pft_my_7km-3D-pico_P1M-m' | ||
# --- | ||
# name: TestCFCompliance.test_subset_open.1 | ||
160 | ||
# --- | ||
# name: TestCFCompliance.test_subset_open.2 | ||
160 | ||
# --- | ||
# name: TestCFCompliance.test_subset_open.3 | ||
list([ | ||
]) | ||
# --- | ||
# name: TestCFCompliance.test_subset_with_warns | ||
'cmems_obs-sst_med_phy-sst_nrt_diurnal-oi-0.0625deg_PT1H-m' | ||
# --- | ||
# name: TestCFCompliance.test_subset_with_warns.1 | ||
135 | ||
# --- | ||
# name: TestCFCompliance.test_subset_with_warns.2 | ||
136 | ||
# --- | ||
# name: TestCFCompliance.test_subset_with_warns.3 | ||
list([ | ||
'§2.6 Attributes', | ||
list([ | ||
'§2.6.1 Conventions global attribute does not contain "CF-1.6"', | ||
]), | ||
]) | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import json | ||
|
||
import xarray | ||
|
||
from copernicusmarine import subset | ||
from tests.test_utils import execute_in_terminal | ||
|
||
|
||
class TestCFCompliance: | ||
def test_subset_open(self, tmp_path, snapshot): | ||
dataset_id = "cmems_mod_nws_bgc-pft_my_7km-3D-pico_P1M-m" | ||
self.if_I_subset_a_dataset(dataset_id, tmp_path, "output_1.nc", "pico") | ||
self.then_it_is_cf_compliant( | ||
dataset_id, tmp_path, snapshot, "output_1" | ||
) | ||
|
||
def test_subset_with_warns(self, tmp_path, snapshot): | ||
dataset_id = ( | ||
"cmems_obs-sst_med_phy-sst_nrt_diurnal-oi-0.0625deg_PT1H-m" | ||
) | ||
self.if_I_subset_a_dataset( | ||
dataset_id, | ||
tmp_path, | ||
"output_2.nc", | ||
"analysed_sst", | ||
) | ||
self.then_it_is_cf_compliant( | ||
dataset_id, tmp_path, snapshot, "output_2" | ||
) | ||
|
||
def if_I_subset_a_dataset( | ||
self, dataset_id, tmp_path, output_filename, variable | ||
): | ||
subset( | ||
dataset_id=dataset_id, | ||
variables=[variable], | ||
output_directory=tmp_path, | ||
output_filename=output_filename, | ||
start_datetime="2022-01-01T00:00:00", | ||
end_datetime="2022-01-05T00:00:00", | ||
force_download=True, | ||
) | ||
assert (tmp_path / output_filename).exists() | ||
|
||
def then_it_is_cf_compliant( | ||
self, dataset_id, tmp_path, snapshot, output_filename | ||
): | ||
dataset_id = dataset_id | ||
dataset = xarray.open_dataset(f"{tmp_path}/{output_filename}.nc") | ||
CF_convention = dataset.attrs["Conventions"][-3:] | ||
if CF_convention < "1.6": | ||
CF_convention = "1.6" | ||
command = [ | ||
"compliance-checker", | ||
f"--test=cf:{CF_convention}", | ||
f"{tmp_path}/{output_filename}.nc", | ||
"-f", | ||
"json", | ||
"-o", | ||
f"{tmp_path}/{output_filename}_checked.json", | ||
] | ||
execute_in_terminal(command) | ||
|
||
f = open(f"{tmp_path}/{output_filename}_checked.json") | ||
data = json.load(f) | ||
|
||
list_msgs = [] | ||
for diccionari in data[f"cf:{CF_convention}"]["all_priorities"]: | ||
if len(diccionari["msgs"]) > 0: | ||
list_msgs.append(diccionari["name"]) | ||
list_msgs.append(diccionari["msgs"]) | ||
|
||
assert dataset_id == snapshot | ||
assert data[f"cf:{CF_convention}"]["scored_points"] == snapshot | ||
assert data[f"cf:{CF_convention}"]["possible_points"] == snapshot | ||
assert list_msgs == snapshot |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! maybe you should talk with Guille anyway about this if the valid minmax that comes from arco is different then the variable normal value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, all of them have the same format (if int, int, if float, float) but the precision might be different... I'll ask anyway, yes!