Skip to content

Commit

Permalink
LDDS-490 - Add Subset-band-name regression tests suite.
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Roosevelt Purification <[email protected]>
Co-authored-by: Christine Brown-Stevenson <[email protected]>
Co-authored-by: Matt Savoie <[email protected]>
Co-authored-by: Matt Savoie <[email protected]>
  • Loading branch information
5 people authored Oct 30, 2024
1 parent 27fdc3a commit 6719f5a
Show file tree
Hide file tree
Showing 11 changed files with 348 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
test/nsidc-icesat2/reference_files/*.h5 filter=lfs diff=lfs merge=lfs -text
test/subset-band-name/reference_data/*.hdf filter=lfs diff=lfs merge=lfs -text
5 changes: 5 additions & 0 deletions .github/workflows/build-all-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ jobs:
-
image: "regridder"
notebook: "Regridder_Regression.ipynb"
-
image: "subset-band-name"
notebook: "SubsetBandName_Regression.ipynb"
shared-utils: "true"
lfs: "true"
-
image: "swath-projector"
notebook: "SwathProjector_Regression.ipynb"
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ versioning. Rather than a static releases, this repository contains of a number
of regression tests that are each semi-independent. This CHANGELOG file should be used
to document pull requests to this repository.

## 2024-10-29 ([#95](https://github.com/nasa/harmony-regression-tests/pull/95))

- Adds LAADS DAAC subset-band-name test suite with subsetting EV_250_Aggr500_RefSB
variable MOD02HKM collection as a starter test
- Utilizes functions from `shared_utils`

## 2024-10-16 ([#105](https://github.com/nasa/harmony-regression-tests/pull/105))

- Updates the HyBIG regression test suite to include a test specifying a variable
Expand Down
2 changes: 1 addition & 1 deletion script/test-in-bamboo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ echo "harmony host url: ${harmony_host_url}"
## e.g. if REGRESSION_TESTS_N2Z_IMAGE environment was set, the value would be used instead of the default.

image_names=()
all_tests=(harmony harmony-regression hoss hga n2z nsidc-icesat2 swath-projector trajectory-subsetter variable-subsetter regridder hybig geoloco net2cog)
all_tests=(harmony harmony-regression hoss hga n2z nsidc-icesat2 swath-projector trajectory-subsetter variable-subsetter regridder hybig geoloco net2cog subset-band-name)
for image in "${all_tests[@]}"; do
image_names+=($(image_name "$image" true))
done
Expand Down
12 changes: 10 additions & 2 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ n2z-image: Dockerfile n2z/environment.yaml

nsidc-icesat2-image: Dockerfile nsidc-icesat2/environment.yaml
docker build -t ghcr.io/nasa/regression-tests-nsidc-icesat2:latest -f ./Dockerfile \
--build-arg notebook=NSIDC-ICESAT2_Regression.ipynb --build-arg sub_dir=nsidc-icesat2 --build-arg shared_utils=true .
--build-arg notebook=NSIDC-ICESAT2_Regression.ipynb --build-arg sub_dir=nsidc-icesat2 \
--build-arg shared_utils=true .

regridder-image: Dockerfile regridder/environment.yaml
docker build -t ghcr.io/nasa/regression-tests-regridder:latest -f ./Dockerfile \
Expand All @@ -34,9 +35,15 @@ swath-projector-image: Dockerfile swath-projector/environment.yaml
docker build -t ghcr.io/nasa/regression-tests-swath-projector:latest -f ./Dockerfile \
--build-arg notebook=SwathProjector_Regression.ipynb --build-arg sub_dir=swath-projector .

subset-band-name-image: Dockerfile subset-band-name/environment.yaml
docker build -t ghcr.io/nasa/regression-tests-subset-band-name:latest -f ./Dockerfile \
--build-arg notebook=SubsetBandName_Regression.ipynb --build-arg sub_dir=subset-band-name \
--build-arg shared_utils=true .

trajectory-subsetter-image: Dockerfile trajectory-subsetter/environment.yaml
docker build -t ghcr.io/nasa/regression-tests-trajectory-subsetter:latest -f ./Dockerfile \
--build-arg notebook=TrajectorySubsetter_Regression.ipynb --build-arg sub_dir=trajectory-subsetter --build-arg shared_utils=true .
--build-arg notebook=TrajectorySubsetter_Regression.ipynb --build-arg sub_dir=trajectory-subsetter \
--build-arg shared_utils=true .

variable-subsetter-image: Dockerfile variable-subsetter/environment.yaml
docker build -t ghcr.io/nasa/regression-tests-variable-subsetter:latest -f ./Dockerfile \
Expand All @@ -58,6 +65,7 @@ images: harmony-image \
n2z-image \
nsidc-icesat2-image \
regridder-image \
subset-band-name-image \
swath-projector-image \
trajectory-subsetter-image \
variable-subsetter-image \
Expand Down
2 changes: 1 addition & 1 deletion test/run_notebooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ echo "Running regression tests"

# Specify the test images to run, by default all built by the Makefile. If
# the script is invoked with a list of images, only run those.
all_images=(harmony harmony-regression hoss hga n2z nsidc-icesat2 swath-projector trajectory-subsetter variable-subsetter regridder hybig geoloco net2cog)
all_images=(harmony harmony-regression hoss hga n2z nsidc-icesat2 swath-projector trajectory-subsetter variable-subsetter regridder hybig geoloco net2cog subset-band-name)
specified_images=()
# Parse command line arguments
while [[ $# -gt 0 ]]; do
Expand Down
265 changes: 265 additions & 0 deletions test/subset-band-name/SubsetBandName_Regression.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "cfc3aea0-3e7c-42b0-a013-f8b9897fc707",
"metadata": {},
"source": [
"# LAADS DAAC Subset-Band-Name Regression Tests\n",
"\n",
"This notebook contains contains a suite of regression tests against LAADS DAAC Subset-Band-Name Harmony Service against reference data generated on premises. \n",
"\n",
"Subset-Band-name ideally operates on Levels 1B, 2, 3 and 4 data; HDF4 only.\n",
"\n",
"## Prerequisites\n",
"\n",
"The dependencies for this notebook are listed in the environment.yaml. To test or install locally, create the papermill environment used in the automated regression testing suite:\n",
"\n",
"`conda env create -f ./environment.yaml && conda activate papermill-subsetbandname`\n",
"\n",
"A `.netrc` file must also be located in the test directory of this repository."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "509a1aa5-2a5f-4223-9bfe-f6c222ffffb2",
"metadata": {},
"outputs": [],
"source": [
"## Import shared utility routines:\n",
"import sys\n",
"\n",
"sys.path.append('../shared_utils')\n",
"from utilities import (\n",
" print_error,\n",
" print_success,\n",
" submit_and_download,\n",
")\n",
"\n",
"from harmony import Client, Collection, Environment, Request\n",
"\n",
"from subset_band_name_utitlities import (\n",
" remove_results_files,\n",
" compare_data,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "e0caf2f1-1a52-4db3-8a6c-bc5c2911fb5e",
"metadata": {},
"source": [
"## Set Default Parameters\n",
"\n",
"`papermill` requires default values for parameters used on the workflow. In this case, `harmony_host_url`\n",
"\n",
"The following are the valid values\n",
"- Production: https://harmony.earthdata.nasa.gov\n",
"- UAT: https://harmony.uat.earthdata.nasa.gov\n",
"- SIT: https://harmony.sit.earthdata.nasa.gov\n",
"- Local: http://localhost:3000"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "68b5e491-086c-48c0-b9bd-42ae068aa8f4",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"harmony_host_url = 'https://harmony.uat.earthdata.nasa.gov'\n",
"# harmony_host_url = 'https://harmony.sit.earthdata.nasa.gov'\n",
"# harmony_host_url = 'http://localhost:3000'\n",
"# harmony_host_url = 'https://harmony.earthdata.nasa.gov'"
]
},
{
"cell_type": "markdown",
"id": "37cfa0f5-aa39-453b-b69e-1398472154b7",
"metadata": {},
"source": [
"## Identify Harmony Environment"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9e8b905a-b08c-4288-80b2-42af52ed0241",
"metadata": {},
"outputs": [],
"source": [
"host_environment = {\n",
" 'http://localhost:3000': Environment.LOCAL,\n",
" 'https://harmony.sit.earthdata.nasa.gov': Environment.SIT,\n",
" 'https://harmony.uat.earthdata.nasa.gov': Environment.UAT,\n",
" 'https://harmony.earthdata.nasa.gov': Environment.PROD,\n",
"}\n",
"\n",
"\n",
"harmony_environment = host_environment.get(harmony_host_url)\n",
"\n",
"if harmony_environment is not None:\n",
" harmony_client = Client(env=harmony_environment)"
]
},
{
"cell_type": "markdown",
"id": "4ce4a5f7-7f82-455c-b693-52715eed525d",
"metadata": {},
"source": [
"## Setting up Collection Environment Variables\n",
"\n",
"The cell below sets up the Collection, Granule and other necessary variables for each tested dataset. The datasets provided are in the `UAT` environment. There is currently one dataset for Level 1B.\n",
"\n",
"- Level 1B: MOD021KM\n",
"- Variable: EV_250_Aggr500_RefSB"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "da8fbd43-8232-496b-a57a-6156447a965c",
"metadata": {},
"outputs": [],
"source": [
"mod02hkm_non_production_info = {\n",
" 'collection': Collection(id='C1260442414-LAADSCDUAT'),\n",
" 'granule_id': 'G1261680941-LAADSCDUAT',\n",
" 'variable': ['EV_250_Aggr500_RefSB'],\n",
"}\n",
"\n",
"mod02hkm_production_info = {\n",
" 'collection': Collection(id='C1378577630-LAADS'),\n",
" 'granule_id': 'G2796405746-LAADS',\n",
" 'variable': ['EV_250_Aggr500_RefSB'],\n",
"}\n",
"\n",
"file_indicators = {'MOD02HKM': 'MOD02HKM.EV_250_Aggr500_RefSB_output.hdf'}\n",
"\n",
"reference_data = {\n",
" 'MOD02HKM': 'reference_data/MOD02HKM.A2023309.2305.061.pscs_001729112207.hdf'\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "722b554f-d69d-45bf-acfe-2ad255f875c0",
"metadata": {},
"source": [
"These selected collections and granules are only available in UAT environment."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9864c2f7-2263-467f-8b33-4810e609cd41",
"metadata": {},
"outputs": [],
"source": [
"mod02hkm_subsetbandname_env = {\n",
" Environment.LOCAL: mod02hkm_non_production_info,\n",
" Environment.UAT: mod02hkm_non_production_info,\n",
" Environment.SIT: mod02hkm_non_production_info,\n",
" # Environment.PROD: mod02hkm_production_info,\n",
"}\n",
"\n",
"mod02hkm_subsetbandname_info = mod02hkm_subsetbandname_env.get(harmony_environment)"
]
},
{
"cell_type": "markdown",
"id": "4640dde7-36cc-4c98-881d-9cbe6ec63d14",
"metadata": {},
"source": [
"## Variable Subsetting Test\n",
"In the cell below, variable subsetting is tested by subsetting EV_250_Aggr500_RefSB variable from the MOD02HKM granule. The results are then compared against the reference data file."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ad598301-433b-41ae-850e-3caa8968a873",
"metadata": {},
"outputs": [],
"source": [
"mod02hkm_test = True\n",
"\n",
"if mod02hkm_subsetbandname_info is not None:\n",
"\n",
" mod02hkm_request = Request(\n",
" collection=mod02hkm_subsetbandname_info['collection'],\n",
" granule_id=mod02hkm_subsetbandname_info['granule_id'],\n",
" variables=mod02hkm_subsetbandname_info['variable'],\n",
" )\n",
"\n",
" submit_and_download(harmony_client, mod02hkm_request, file_indicators['MOD02HKM'])\n",
"\n",
" if not compare_data(\n",
" reference_data['MOD02HKM'], file_indicators['MOD02HKM'], 'EV_250_Aggr500_RefSB'\n",
" ):\n",
" print_error('MOD02HKM data mismatch.')\n",
" mod02hkm_test = False\n",
"\n",
" remove_results_files()"
]
},
{
"cell_type": "markdown",
"id": "8abafe2f-2183-43aa-909c-fc845eb8b04a",
"metadata": {},
"source": [
"## Complete Test Suite With Pass/Fail/Skip"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c2904175-3266-4fe7-9ce1-eb7eaf8423d0",
"metadata": {},
"outputs": [],
"source": [
"subsetbandname_tests = mod02hkm_test\n",
"\n",
"if mod02hkm_subsetbandname_info is not None:\n",
" if subsetbandname_tests:\n",
" print_success('Subset-Band-Name test suite PASSED.')\n",
" else:\n",
" raise Exception('Subset-Band-Name test suite FAILED')\n",
"else:\n",
" print(\n",
" f'Subset-Band-Name is not configured for this environment: \"{harmony_environment}\" - skipping tests.'\n",
" )"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
14 changes: 14 additions & 0 deletions test/subset-band-name/environment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: papermill-subset-band-name
channels:
- conda-forge
- nodefaults
dependencies:
- python=3.11.10
- notebook=7.2.2
- numpy=1.26.4
- papermill=2.6.0
- hdf4=4.2.15
- pyhdf=0.11.3
- pip:
- harmony-py==0.4.15
- xarray==2024.9.0
Git LFS file not shown
Loading

0 comments on commit 6719f5a

Please sign in to comment.