Skip to content

Commit

Permalink
pytest cfrad1 pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
syedhamidali committed Sep 26, 2023
1 parent a7a4ea0 commit 14cf664
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions tests/io/test_cfradial1.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
import tempfile

import xarray as xr
import xradar as xd
from open_radar_data import DATASETS

import xradar as xd


def test_compare_sweeps():
# Fetch the radar data file
filename = DATASETS.fetch("cfrad.20080604_002217_000_SPOL_v36_SUR.nc")

# Open the data tree
dtree = xd.io.open_cfradial1_datatree(filename)

# Create a temporary file to store the modified data tree
with tempfile.NamedTemporaryFile(mode="w+b") as temp_file:
# Save the modified data tree to the temporary file
xd.io.to_cfradial1(dtree.copy(), temp_file.name, calibs=True)

# Open the modified data tree
dtree1 = xd.io.open_cfradial1_datatree(temp_file.name)

# Iterate through sweep keys and compare DataArrays
for grp in dtree1.groups:
if "sweep" in grp:
data = dtree1[grp]
dtree1[grp]

# Compare the values of the DataArrays for all sweeps
for sweep_num in range(9): # Assuming there are 9 sweeps
xr.testing.assert_equal(dtree[f'sweep_{sweep_num}'].ds, dtree1[f'sweep_{sweep_num}'].ds)

xr.testing.assert_equal(
dtree[f"sweep_{sweep_num}"].ds, dtree1[f"sweep_{sweep_num}"].ds
)

0 comments on commit 14cf664

Please sign in to comment.