-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor omPriorVerify.py
into tests
#14
Conversation
omPriorVerify.py
into tests
This reverts commit 819f890.
…rify-emissions-test # Conflicts: # tests/test_download_data.py # tests/test_om_prior.py
# TODO Update this test when file structure is clear. | ||
# This test ensures that the grid size for all input files is 10 km. | ||
def test_006_grid_size_for_geo_files(root_dir, monkeypatch) : | ||
expected_cell_size = 10000 |
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.
I am not sure what exactly to test here. Right now the test ensure that the grid size for geo_em.d01.nc
, GRIDCRO2D_1
, GRIDDOT2D_1
is 10 km.
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.
My initial thought was lat/lons, but then I realised that the GRIDCRO/GRIDDOT are a subset of the WRF domain.
That could be a test for after omCreateDomainInfo.py
is run, but not applicable here
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.
Looks good. There are a few suggestions for other things to test. Whether this comes in the PR or later is up to you.
tests/test_om_prior.py
Outdated
|
||
def test_full_process(num_regression, root_dir, monkeypatch): | ||
os.remove(filepath) |
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.
Given that filepath uses the tmpdir
fixture, the files are automatically cleaned up so don't need to be removed. Therefore this line isn't needed
If you really wanted to be sure that something is cleaned up after the test you should put it in a try finally block. Otherwise the test might exit early before the remove
call. Or you could have a fixture that uses yield like you did above
try:
create_file()
this_might_fail()
finally:
# This is always called even if an exception is raised in `this_migh_fail()`
if filepath.exists():
filepath.remove()
|
||
|
||
# Fixture to download and later remove all input files | ||
@pytest.fixture(scope="session") |
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.
This fixture can probably move into conftest.py
as it could be used in other places. Also since it is session scoped even if you use it in multiple test modules it will still only run once
# TODO Update this test when file structure is clear. | ||
# This test ensures that the grid size for all input files is 10 km. | ||
def test_006_grid_size_for_geo_files(root_dir, monkeypatch) : | ||
expected_cell_size = 10000 |
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.
My initial thought was lat/lons, but then I realised that the GRIDCRO/GRIDDOT are a subset of the WRF domain.
That could be a test for after omCreateDomainInfo.py
is run, but not applicable here
tests/test_om_prior.py
Outdated
|
||
@pytest.fixture(scope="session") | ||
def output_domain_file(root_dir, | ||
input_files |
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.
This doesn't look ruffed
tests/test_om_prior.py
Outdated
filepath_in_domain = os.path.join(root_dir, "inputs/om-domain-info.nc") | ||
|
||
# Generated by scripts/omPrior.py | ||
filepath_out_domain = os.path.join(root_dir, "outputs/out-om-domain-info.nc") |
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.
Can we add a new test that verifies that this output file has the same lat/lons that are in the CRO/DOT files. filepath_in_domain
should have the same dimensions as well.
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.
Is it possible that GRIDCRO2D_1
and GRIDDOT2D_1
have different dimensions?
In this test I compare COL
and ROW
of GRIDCRO2D_1
and GRIDDOT2D_1
with inputs/om-domain-info.nc
.
The number of columns and rows in GRIDCRO2D_1
is one below the number of columns and rows in GRIDDOT2D_1
:
GRIDCRO2D_1
contains the attributes ROW: 430, COL: 454
and
GRIDDOT2D_1
contains the attributes ROW: 431, COL: 455
.
In om-domain-info.nc
there are the attributes ROW: 430
and ROW_D: 431
.
So I can compare ROW
with GRIDCRO2D_1
and ROW_D
with GRIDDOT2D_1
?
The test that I am adding looks like this. It's passing, but I am not sure if the test makes sense.
def test_007_compare_in_domain_with_cro_dot_files(input_domain_xr, cro_xr, dot_xr):
assert dot_xr.NCOLS == input_domain_xr.COL_D.size
assert dot_xr.NROWS == input_domain_xr.ROW_D.size
assert cro_xr.NCOLS == input_domain_xr.COL.size
assert cro_xr.NROWS == input_domain_xr.ROW.size
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.
WRF and CMAQ use a staggered grid (https://amps-backup.ucar.edu/information/configuration/wrf_grid_structure.html) where depending on the quantity that you are measuring the grid points are slightly different. Things like temperature/pressure are defined at the center of a grid cell, where as other quantities such as wind are defined at the edges of a grid cell. If you count the number of edges in a grid along a x or y it is one larger than the number of cells in x or y.
The CRO/DOT files are generated by MCIP (?) from the WRF domain and define the domain used by CMAQ.
The CRO files define the latitude centers where as the DOT files define the corners hence why ROW_D = ROW + 1
. I don't know why they are named as they are 🤷
The CMAQ domain is a little smaller than the WRF domain because the 5 grid cells around the edge of the domain are excluded. I can talk you through why that is another day.
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.
According to this website, CRO is short for cross and dot.
An image of the CMAQ grid: https://www.cmascenter.org/ioapi/documentation/all_versions/html/GRIDS.jpg
and the interaction between the grid and "thickened boundary" https://www.cmascenter.org/ioapi/documentation/all_versions/html/THKBDY.jpg. The outside is the WRF domain, but the inner cells labelled "main grid" is the CMAQ grid
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.
Ok thanks. I think I have understood it to some degree.
Is the difference between CMAQ domain and WRF domain (the thickened boundary) unrelated to the mass grid / staggered grid problem? And it wouldn't be relevant to the tests here anyway, would it?
I've added the tests 007 and 008.
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.
Correct. It is unrelated. If you compared the grid sizes in the raw input domain geo_em.d01.nc
you would see that they don't align with the CMAQ grid
I'm worried about hard coding a 10km test since subdomains will be
finer resolution
--
Peter Rayner (he/him)
My work days are Monday-Thursday, responses at other times might be slow.
The Superpower Institute <https://www.superpowerinstitute.com.au/>
Level 3 105 Victoria St. Fitzroy 3065
Transparent, actionable and auditable data on Australia's methane emissions <https://openmethane.org>
mobile +61 402 752 379
zoom id 4431343191, join at <https://unimelb.zoom.us/j/4431343191?pwd=a1E5Z3JEOTRVQUJsaVdRbVUvR1QyZz09>
mail-to: ***@***.***
google scholar: <https://scholar.google.com.au/citations?user=H3up71wAAAAJ&hl=en>
I acknowledge the Traditional Custodians of the land on which I work, the Wurundjeri people of the Kulin nation, and pay my respect to their Elders, past and present
I am sending this email when convenient for me, please only respond when convenient for you
|
Co-authored-by: Jared Lewis <[email protected]>
@prayner In this case we are testing that the example domain that is checked into the repo is consistent. These tests aren't run for every new domain (maybe they should eventually) |
Description
omPriorVerify.py
call fromomPrior.py
omPriorVerify.py
in test suite - see tests 005 and 006Checklist
Please confirm that this pull request has done the following:
Notes