Skip to content

Commit

Permalink
ADD: Add scan_name to nexrad datatree attributes (#238)
Browse files Browse the repository at this point in the history
* adding scan_name to nexrad datatree attributes

* adding test to furuno backend

* adding test to nexradlevel2 backend

* adding test for open_datatree in iris backend

* adding changes to history.md file

* adding changes to history.md file

* Update docs/history.md

Co-authored-by: Max Grover <mgroverwx@gmail.com>

* adding test to open_datatree for datamet backend

* adding test to open_datatree for gamic backend

* adding test to open_datatree for hpl backend

* adding test to open_datatree for metek backend

* adding test to open_datatree for odim backend

* adding test to open_datatree for rainbow backend

* updating history.md file

---------

Co-authored-by: Max Grover <mgroverwx@gmail.com>
  • Loading branch information
aladinor and mgrover1 authored Nov 13, 2024
1 parent 18aad31 commit 2273a48
Show file tree
Hide file tree
Showing 11 changed files with 1,134 additions and 8 deletions.
4 changes: 4 additions & 0 deletions docs/history.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# History

## 0.8.1 (Unreleased)

* ENH: Adding test to `open_datatree` function for all backends. Adding "scan_name" to nexradlevel2 datatree attributes ({pull}`238`) by [@aladinor](https://github.com/aladinor)

## 0.8.0 (2024-11-04)

This is the first version which uses datatree directly from xarray. Thus, xarray is pinned to version >= 2024.10.0.
Expand Down
73 changes: 72 additions & 1 deletion tests/io/test_datamet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import tarfile

import pytest
from xarray import DataTree

from xradar.io.backends import datamet
from xradar.io.backends import datamet, open_datamet_datatree
from xradar.util import _get_data_file


Expand Down Expand Up @@ -58,3 +59,73 @@ def test_moment_metadata(data):
)
def test_moment_data(data, moment, expected_value):
assert data.data[0][moment][(4, 107)] == expected_value


def test_open_datamet_datatree(datamet_file):
# Define kwargs to pass into the function
kwargs = {
"sweep": [0, 1], # Test with specific sweeps
"first_dim": "auto",
"reindex_angle": {
"start_angle": 0.0,
"stop_angle": 360.0,
"angle_res": 1.0,
"direction": 1, # Set a valid direction within reindex_angle
},
"site_coords": True,
}

# Call the function with an actual DataMet file
dtree = open_datamet_datatree(datamet_file, **kwargs)

assert isinstance(dtree, DataTree), "Expected a DataTree instance"
assert "/" in dtree.subtree, "Root group should be present in the DataTree"
assert (
"/radar_parameters" in dtree.subtree
), "Radar parameters group should be in the DataTree"
assert (
"/georeferencing_correction" in dtree.subtree
), "Georeferencing correction group should be in the DataTree"
assert (
"/radar_calibration" in dtree.subtree
), "Radar calibration group should be in the DataTree"

# Check if at least one sweep group is attached (e.g., "/sweep_0")
sweep_groups = [key for key in dtree.match("sweep_*")]
assert len(sweep_groups) == 2, "Expected four sweep groups in the DataTree"

# Verify a sample variable in one of the sweep groups (adjust based on expected variables)
sample_sweep = sweep_groups[0]
assert (
len(dtree[sample_sweep].data_vars) == 13
), f"Expected data variables in {sample_sweep}"
assert dtree[sample_sweep]["DBZH"].shape == (360, 493)
assert (
"DBZH" in dtree[sample_sweep].data_vars
), f"DBZH should be a data variable in {sample_sweep}"
assert (
"VRADH" in dtree[sample_sweep].data_vars
), f"VRADH should be a data variable in {sample_sweep}"

# Validate coordinates are attached correctly in the root dataset
assert (
"latitude" in dtree[sample_sweep]
), "Latitude should be attached to the root dataset"
assert (
"longitude" in dtree[sample_sweep]
), "Longitude should be attached to the root dataset"
assert (
"altitude" in dtree[sample_sweep]
), "Altitude should be attached to the root dataset"

# Validate attributes
assert len(dtree.attrs) == 10
assert (
dtree.attrs["instrument_name"] == "ILMONTE"
), "Instrument name should match expected value"
assert dtree.attrs["source"] == "Datamet", "Source should match expected value"
assert (
dtree.attrs["scan_name"] == "VOLUMETRICA"
), "Scan name should match expected value"

# Verify a sample variable in on
Loading

0 comments on commit 2273a48

Please sign in to comment.