-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
981 additions
and
45 deletions.
There are no files selected for viewing
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,15 @@ | ||
[run] | ||
source = | ||
gpm_api | ||
omit = | ||
*dev* | ||
*docs* | ||
*tutorials* | ||
gpm_api/tests/* | ||
gpm_api/cli/* | ||
|
||
[report] | ||
exclude_lines = | ||
pragma: no cover | ||
def __repr__ | ||
def __str__ |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import numpy as np | ||
import pytest | ||
import h5py | ||
import os | ||
from gpm_api import open_dataset | ||
from gpm_api.dataset.granule import _open_granule | ||
|
||
import xarray as xr | ||
|
||
|
||
class SaneEqualityArray(np.ndarray): | ||
"""Wrapper class for numpy array allowing deep equality tests on objects containing numpy arrays. | ||
From https://stackoverflow.com/a/14276901 | ||
""" | ||
|
||
def __new__(cls, array): | ||
"""Create a new SaneEqualityArray from array only (instead of shape + type + array).""" | ||
|
||
if isinstance(array, list): # No need to wrap regular lists | ||
return array | ||
|
||
return np.asarray(array).view(cls) | ||
|
||
def __eq__(self, other): | ||
# Only use equal_nan for floats dtypes | ||
equal_nan = np.issubdtype(self.dtype, np.floating) | ||
return ( | ||
isinstance(other, np.ndarray) | ||
and self.shape == other.shape | ||
and np.array_equal(self, other, equal_nan=equal_nan) | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
def sample_dataset() -> xr.Dataset: | ||
"""Return a sample dataset to use for testing | ||
Dataset is a 2A DPR file from 2022-07-05 that has been generated with | ||
test_granule_creation.py to maintain structure but remove data | ||
""" | ||
|
||
# os.path.join( | ||
# os.getcwd(), | ||
# "gpm_api", | ||
# "tests", | ||
# "resources", | ||
# "GPM", | ||
# "RS", | ||
# "V07", | ||
# "PMW", | ||
# "1C-MHS-METOPB", | ||
# "2020", | ||
# "08", | ||
# "01", | ||
# "1C.METOPB.MHS.XCAL2016-V.20200801-S102909-E121030.040841.V07A.HDF5", | ||
# ) | ||
# ) | ||
|
||
# ds = open_dataset( | ||
# start_time="2022-07-01T10:29:09", | ||
# end_time="2022-08-01T12:10:30", | ||
# product="1C-MHS-METOPB", | ||
# ) | ||
|
||
ds = _open_granule( | ||
os.path.join( | ||
os.getcwd(), | ||
"gpm_api", | ||
"tests", | ||
"resources", | ||
"GPM", | ||
"RS", | ||
"V07", | ||
"PMW", | ||
"1C-MHS-METOPB", | ||
"2020", | ||
"08", | ||
"01", | ||
"1C.METOPB.MHS.XCAL2016-V.20200801-S102909-E121030.040841.V07A.HDF5", | ||
) | ||
) | ||
|
||
return ds | ||
|
||
|
||
def pytest_configure(): | ||
pytest.SaneEqualityArray = SaneEqualityArray |
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,34 @@ | ||
from gpm_api.dataset.decoding import attrs as at | ||
import pytest | ||
import numpy as np | ||
|
||
|
||
def test_convert_string_to_number() -> None: | ||
"""Test that a string is converted to a number""" | ||
|
||
assert at.convert_string_to_number("1") == 1 | ||
assert at.convert_string_to_number("1.0") == 1.0 | ||
assert at.convert_string_to_number("1.0e-3") == 1.0e-3 | ||
assert at.convert_string_to_number("1.0e3") == 1.0e3 | ||
assert at.convert_string_to_number("1.0e+3") == 1.0e3 | ||
assert at.convert_string_to_number("1.0e+03") == 1.0e3 | ||
assert at.convert_string_to_number("-999") == -999 | ||
|
||
with pytest.raises(ValueError): | ||
assert at.convert_string_to_number("notanumber") | ||
|
||
|
||
def test_ensure_dtype_name() -> None: | ||
"""Test that a dtype is returned as a string name""" | ||
|
||
# Test with dtype | ||
assert at.ensure_dtype_name(np.dtype("float32")) == "float32" | ||
assert at.ensure_dtype_name(np.dtype("int32")) == "int32" | ||
assert at.ensure_dtype_name(np.dtype("uint8")) == "uint8" | ||
|
||
# Test normal string | ||
assert at.ensure_dtype_name("notadtype") == "notadtype" | ||
|
||
# Test not a dtype | ||
with pytest.raises(TypeError): | ||
assert at.ensure_dtype_name(np.dtype("float31")) |
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,38 @@ | ||
import pytest | ||
from typing import List | ||
from gpm_api.dataset.decoding import coordinates as co | ||
|
||
|
||
def test_ensure_valid_coords(): | ||
# TODO: Requires sample ds to work | ||
pass | ||
|
||
|
||
def test_get_pmw_frequency_dict() -> None: | ||
"""Test that a dictionary is returned""" | ||
|
||
res = co.get_pmw_frequency_dict() | ||
|
||
assert isinstance(res, dict), "Dictionary not returned" | ||
|
||
|
||
def test_get_pmw_frequency_corra( | ||
products: List[str], | ||
) -> None: | ||
# Try products hardcoded in function | ||
res = co.get_pmw_frequency_corra("2B-GPM-CORRA") | ||
assert len(res) > 0 | ||
assert res == co.get_pmw_frequency("GMI", scan_mode="S1") + co.get_pmw_frequency( | ||
"GMI", scan_mode="S2" | ||
) | ||
|
||
res = co.get_pmw_frequency_corra("2B-TRMM-CORRA") | ||
assert len(res) > 0 | ||
assert res == co.get_pmw_frequency("TMI", scan_mode="S1") | ||
|
||
# Test other non-corra products fail | ||
for product in products: | ||
if "corra" not in product.lower(): | ||
with pytest.raises(UnboundLocalError): | ||
res = co.get_pmw_frequency_corra(product) | ||
assert len(res) == 0 |
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,11 @@ | ||
import os | ||
|
||
|
||
assets_dir_path = "assets" | ||
|
||
# Change current working directory to the directory of this script | ||
os.chdir(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
# Create the assets directory | ||
if not os.path.exists(assets_dir_path): | ||
os.makedirs(assets_dir_path) |
Oops, something went wrong.