Skip to content
Open
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
16 changes: 16 additions & 0 deletions rose-stem/app/validate_output_file_metadata/bin/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
##############################################################################
# (c) Crown copyright Met Office. All rights reserved.
# The file LICENCE, distributed with this code, contains details of the terms
# under which the code may be used.
##############################################################################
import pytest

def pytest_addoption(parser):
parser.addoption(
"--lfric_diag_file", action="store", required=True,
help="Input lfric_diagnostics.nc netCDF file"
)

@pytest.fixture
def diag_infile(request):
return request.config.getoption("--lfric_diag_file")
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
##############################################################################
# (c) Crown copyright Met Office. All rights reserved.
# The file LICENCE, distributed with this code, contains details of the terms
# under which the code may be used.
##############################################################################
"""
Module to analyse metadata structures in lfric_diagnostics output files
from LFRic.
Rules for metadata output are encoded.

"""

import netCDF4
import os
import pytest

@pytest.fixture
def load_rootgrp(diag_infile):
rootgrp = None
if os.path.exists(diag_infile):
rootgrp = netCDF4.Dataset(diag_infile, format="NETCDF4")

return rootgrp

class TestTemporalMetadata:
def test_time_centered_exists(self, load_rootgrp):
"""
Validate that the output file has a variable named 'time_instant'
"""
assert "time_centered" in load_rootgrp.variables

def test_time_counter_not_exists(self, load_rootgrp):
"""
Validate that the output file does not have a variable named 'time_counter'
"""
assert "time_counter" not in load_rootgrp.variables

class TestSpatialMetadata:
def test_Mesh2d_node_x_exists(self, load_rootgrp):
"""
Validate that the output file has a variable named 'Mesh2d_node_x'
"""
assert "Mesh2d_node_x" in load_rootgrp.variables

def test_Mesh2d_node_x_stdname(self, load_rootgrp):
"""
Validate that the output file x variable has longitude standard_name
"""
assert load_rootgrp.variables.get("Mesh2d_node_x").standard_name == 'longitude'

def test_Mesh2d_node_x_units(self, load_rootgrp):
"""
Validate that the output file x variable has degrees_east units
"""
assert load_rootgrp.variables.get("Mesh2d_node_x").units == 'degrees_east'

def test_Mesh2d_node_y_exists(self, load_rootgrp):
"""
Validate that the output file has a variable named 'Mesh2d_node_y'
"""
assert "Mesh2d_node_y" in load_rootgrp.variables

def test_Mesh2d_node_y_stdname(self, load_rootgrp):
"""
Validate that the output file y variable has latitude standard_name
"""
assert load_rootgrp.variables.get("Mesh2d_node_y").standard_name == 'latitude'

def test_Mesh2d_node_y_units(self, load_rootgrp):
"""
Validate that the output file y variable has degrees_north units
"""
assert load_rootgrp.variables.get("Mesh2d_node_y").units == 'degrees_north'
2 changes: 2 additions & 0 deletions rose-stem/app/validate_output_file_metadata/rose-app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[command]
default=pytest $CYLC_WORKFLOW_RUN_DIR/app/validate_output_file_metadata/bin --lfric_diag_file=$INPUT_RESULTS_DIR/lfric_diagnostics.nc
2 changes: 2 additions & 0 deletions rose-stem/site/common/lfric_atm/tasks_lfric_atm.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"tsteps": 144,
"crun": 2,
"crun_compare": false,
"metadata_test": true,
"mpi_parts": 6,
"kgo_checks": ["checksum"],
"plot_str": "plot_map.py $NODAL_DATA_DIR/lfric_diagnostics.nc $PLOT_DIR",
Expand Down Expand Up @@ -291,6 +292,7 @@
"tsteps": 144,
"crun": 2,
"crun_compare": false,
"metadata_test": true,
"mpi_parts": 6,
"kgo_checks": ["checksum"],
"plot_str": "plot_map.py $NODAL_DATA_DIR/lfric_diagnostics.nc $PLOT_DIR",
Expand Down
1 change: 1 addition & 0 deletions rose-stem/templates/common_macros.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"plot",
"memory_plot_ex",
"check",
"metadata_test",
"publish",
"phystest",
"fcm_make",
Expand Down
13 changes: 13 additions & 0 deletions rose-stem/templates/graph/populate_crun_graph.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@
crun_task,
plot_task]) %}
{% endif %}

{% if metadatatest %}
{% set metadatatest_task = "metadata_test_"~
task_values["task_family"]~
"-crun"~restart_no %}
{% if metadatatest_task not in tasks_to_run %}
{% do tasks_to_run.update({metadatatest_task: crun_values }) %}
{% endif %}
{% do graph_sections.append([
crun_task,
metadatatest_task]) %}
{% endif %}

{% endif %}
{% endif %}
{% endfor %}
Expand Down
22 changes: 22 additions & 0 deletions rose-stem/templates/graph/populate_graph_sections.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
{% set phystest = false %}
{% endif %}

{# metadatatest settings #}
{% if "metadata_test" in task_values %}
{% set metadatatest = true %}
{% else %}
{% set metadatatest = false %}
{% endif %}

{# If the task has a restart and has set crun_compare=false, there is no #}
{# nrun-crun comparison to be made, so don't run the nrun test #}
{% set running_nrun = true %}
Expand Down Expand Up @@ -292,6 +299,21 @@
application_run_task,
app_perftools_export_task]) %}
{% endif %}

{% if metadatatest %}
{% set metadatatest_task = "metadata_test_"~
task_ns.application~"_"~
task_ns.conf_name~"_"~
task_ns.platform~"_"~
task_ns.compiler~"_"~
task_ns.extras %}
{% if metadatatest_task not in tasks_to_run %}
{% do tasks_to_run.update({metadatatest_task: task_values }) %}
{% endif %}
{% do graph_sections.append([
application_run_task,
metadatatest_task]) %}
{% endif %}
{% endif %}

{# lfric_coupled graphs require fcm_make tasks before the application run #}
Expand Down
3 changes: 2 additions & 1 deletion rose-stem/templates/runtime/generate_runtime.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
{% elif task.startswith("check") or
task.startswith("rose_ana") or
task.startswith("pert_compare") or
task.startswith("phystest") %}
task.startswith("phystest") or
task.startswith("metadata_test") %}

{% include "templates/runtime/generate_runtime_check.cylc" %}

Expand Down
13 changes: 13 additions & 0 deletions rose-stem/templates/runtime/generate_runtime_check.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@
[[[directives]]]
{{ set_task_resources(task_values["tech-tests_cpus"], task_values["tech-tests_memory"]) }}

{% elif task.startswith("metadata_test") %}
{% for family in task_values["plot_families"] %}
{% set inherit.str = inherit.str~","~family|upper %}
{% endfor %}

[[{{task}}]]
inherit = {{inherit.str|upper}}
script = rose task-run --app-key=validate_output_file_metadata
[[[environment]]]
INPUT_RESULTS_DIR = {{task_output_dir}}/results
[[[directives]]]
{{ set_task_resources(task_values["tech-tests_cpus"], task_values["tech-tests_memory"]) }}

{% endif %}

{% do LOG.debug("Finished in templates/runtime/generate_runtime_check.cylc") %}
Loading