Skip to content

Commit

Permalink
Merge pull request ARM-Development#59 from zssherman/open_radar
Browse files Browse the repository at this point in the history
ENH: Add open_radar_data for testing and examples.
  • Loading branch information
mgrover1 authored Jan 5, 2024
2 parents b0f2993 + 657483e commit 1fbd577
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 29 deletions.
2 changes: 2 additions & 0 deletions continuous_integration/environment_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ dependencies:
- coveralls
- pre-commit
- pip
- pip:
- git+https://github.com/openradar/open-radar-data
2 changes: 2 additions & 0 deletions continuous_integration/environment_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ dependencies:
- sphinx-gallery
- sphinx-rtd-theme
- urllib3
- pip:
- git+https://github.com/openradar/open-radar-data
4 changes: 3 additions & 1 deletion examples/plot_cfad.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

import matplotlib.pyplot as plt
from act.io.armfiles import read_netcdf
from open_radar_data import DATASETS

import radtraq

# Read in example data
ds = read_netcdf(radtraq.tests.sample_files.EXAMPLE_KAZR)
filename = DATASETS.fetch('sgpkazrgeC1.a1.20190529.000002.cdf')
ds = read_netcdf(filename)

# Calculate CFAD histogram
data_array = radtraq.plotting.cfad.calc_cfad(ds, 'reflectivity_copol')
Expand Down
4 changes: 3 additions & 1 deletion examples/plot_cloud_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

import act
import matplotlib.pyplot as plt
from open_radar_data import DATASETS

import radtraq

# Read in sample data using ACT
ds = act.io.armfiles.read_netcdf(radtraq.tests.sample_files.EXAMPLE_KAZR)
filename = DATASETS.fetch('sgpkazrgeC1.a1.20190529.000002.cdf')
ds = act.io.armfiles.read_netcdf(filename)

# Resample data for ease of processing
ds = ds.resample(time='1min').nearest()
Expand Down
5 changes: 3 additions & 2 deletions examples/plot_corner_reflector_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
"""


import matplotlib.pyplot as plt
from act.io.armfiles import read_netcdf
from open_radar_data import DATASETS

import radtraq

# Read in sample data using ACT
ds = read_netcdf(radtraq.tests.sample_files.EXAMPLE_RASTER)
filename = DATASETS.fetch('sgpkasacrcrrasterC1.a1.20130419.012153.nc')
ds = read_netcdf(filename)

# Process and plot raster file
data = radtraq.plotting.corner_reflector.plot_cr_raster(
Expand Down
22 changes: 12 additions & 10 deletions examples/plot_mask_vpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
import matplotlib.pyplot as plt
import numpy as np
from act.io.armfiles import read_netcdf
from open_radar_data import DATASETS

import radtraq

# Read in Example KAZR File using ACT
obj = read_netcdf(radtraq.tests.sample_files.EXAMPLE_KAZR)
filename = DATASETS.fetch('sgpkazrgeC1.a1.20190529.000002.cdf')
ds = read_netcdf(filename)

# Resample to 1-minute to simplify processing
obj = obj.resample(time='1min').nearest()
ds = ds.resample(time='1min').nearest()

# Process cloud mask in order to properly produce average VPT profiles through cloud
obj = radtraq.proc.cloud_mask.calc_cloud_mask(obj, 'reflectivity_copol')
ds = radtraq.proc.cloud_mask.calc_cloud_mask(ds, 'reflectivity_copol')

# Variables to calculate average profiles
variable = ['reflectivity_copol', 'mean_doppler_velocity_copol', 'reflectivity_xpol']
Expand All @@ -31,17 +33,17 @@
ygrid = np.arange(first_height, 15000, 50)

# Calculate average profiles
obj = radtraq.proc.profile.calc_avg_profile(
obj, variable=variable, first_height=first_height, ygrid=ygrid
ds = radtraq.proc.profile.calc_avg_profile(
ds, variable=variable, first_height=first_height, ygrid=ygrid
)

# Showing how to do this for multiple radars
# Set up dictionary for profile comparison plotting
rad_dict = {
'sgpkazrgeC1.b1': {'object': obj, 'variable': variable[0]},
'sgpkazrge2C1.b1': {'object': obj, 'variable': variable[0]},
'sgpkazrmdC1.b1': {'object': obj, 'variable': 'reflectivity_xpol'},
'sgpkazrmd2C1.b1': {'object': obj, 'variable': 'reflectivity_xpol'},
'sgpkazrgeC1.b1': {'object': ds, 'variable': variable[0]},
'sgpkazrge2C1.b1': {'object': ds, 'variable': variable[0]},
'sgpkazrmdC1.b1': {'object': ds, 'variable': 'reflectivity_xpol'},
'sgpkazrmd2C1.b1': {'object': ds, 'variable': 'reflectivity_xpol'},
}

# Plot up profiles and perform comparisons from data in dictionary
Expand All @@ -51,4 +53,4 @@
plt.show()

# Close out object
obj.close()
ds.close()
4 changes: 3 additions & 1 deletion examples/plot_self_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

import matplotlib.pyplot as plt
from act.io.armfiles import read_netcdf
from open_radar_data import DATASETS

import radtraq

# Read in example data
ds = read_netcdf(radtraq.tests.sample_files.EXAMPLE_CSAPR)
filename = DATASETS.fetch('csapr.nc')
ds = read_netcdf(filename)

# Set thresholds of RhoHv > 0.99
thresh = {'copol_correlation_coeff': 0.99}
Expand Down
4 changes: 3 additions & 1 deletion examples/plot_zdr_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

import matplotlib.pyplot as plt
from act.io.armfiles import read_netcdf
from open_radar_data import DATASETS

import radtraq

# Read in example data
ds = read_netcdf(radtraq.tests.sample_files.EXAMPLE_XSAPR)
filename = DATASETS.fetch('sgpxsaprcfrvptI4.a1.20200205.100827.nc')
ds = read_netcdf(filename)
thresh = {'cross_correlation_ratio_hv': [0.995, 1], 'reflectivity': [10, 30], 'range': [1000, 3000]}
# Call RadTraQ function
results = radtraq.proc.calc_zdr_offset(ds, zdr_var='differential_reflectivity', thresh=thresh)
Expand Down
Binary file removed radtraq/tests/data/csapr.nc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
22 changes: 13 additions & 9 deletions radtraq/tests/sample_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
:toctree: generated/
EXAMPLE_KAZR
"""
import os
EXAMPLE_RASTER
EXAMPLE_PPI
EXAMPLE_RHI
EXAMPLE_XSAPR
EXAMPLE_CSAPR
DATA_PATH = os.path.join(os.path.dirname(__file__), 'data')
"""
from open_radar_data import DATASETS

EXAMPLE_KAZR = os.path.join(DATA_PATH, 'sgpkazrgeC1.a1.20190529.000002.cdf')
EXAMPLE_RASTER = os.path.join(DATA_PATH, 'sgpkasacrcrrasterC1.a1.20130419.012153.nc')
EXAMPLE_PPI = os.path.join(DATA_PATH, 'houkasacrcfrM1.a1.20210922.150006.nc')
EXAMPLE_RHI = os.path.join(DATA_PATH, 'houkasacrcfrM1.a1.20211122.164124.nc')
EXAMPLE_XSAPR = os.path.join(DATA_PATH, 'sgpxsaprcfrvptI4.a1.20200205.100827.nc')
EXAMPLE_CSAPR = os.path.join(DATA_PATH, 'csapr.nc')
EXAMPLE_KAZR = DATASETS.fetch('sgpkazrgeC1.a1.20190529.000002.cdf')
EXAMPLE_RASTER = DATASETS.fetch('sgpkasacrcrrasterC1.a1.20130419.012153.nc')
EXAMPLE_PPI = DATASETS.fetch('houkasacrcfrM1.a1.20210922.150006.nc')
EXAMPLE_RHI = DATASETS.fetch('houkasacrcfrM1.a1.20211122.164124.nc')
EXAMPLE_XSAPR = DATASETS.fetch('sgpxsaprcfrvptI4.a1.20200205.100827.nc')
EXAMPLE_CSAPR = DATASETS.fetch('csapr.nc')
8 changes: 4 additions & 4 deletions radtraq/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from act.io.armfiles import read_netcdf
from matplotlib.figure import Figure

import radtraq
from radtraq.plotting.cfad import calc_cfad, plot_cfad
from radtraq.plotting.corner_reflector import plot_cr_raster
from radtraq.plotting.self_consistency import plot_self_consistency
from radtraq.tests.sample_files import EXAMPLE_CSAPR, EXAMPLE_KAZR, EXAMPLE_RASTER


@pytest.mark.mpl_image_compare(tolerance=10)
def test_plotting():
obj = read_netcdf(EXAMPLE_KAZR)
obj = read_netcdf(radtraq.tests.sample_files.EXAMPLE_KAZR)

np.seterr(divide='ignore')
data_array = calc_cfad(obj, 'reflectivity_copol')
Expand All @@ -23,7 +23,7 @@ def test_plotting():

@pytest.mark.mpl_image_compare(tolerance=10)
def test_corner_reflector():
obj = read_netcdf(EXAMPLE_RASTER)
obj = read_netcdf(radtraq.tests.sample_files.EXAMPLE_RASTER)
data = plot_cr_raster(obj, target_range=478.0, el_limits=[-0.5, 2.5], noplot=False)

np.testing.assert_almost_equal(data['max'], 12.09, decimal=2)
Expand All @@ -41,7 +41,7 @@ def test_corner_reflector():

@pytest.mark.mpl_image_compare(tolerance=10)
def test_self_consistency():
obj = read_netcdf(EXAMPLE_CSAPR)
obj = read_netcdf(radtraq.tests.sample_files.EXAMPLE_CSAPR)
thresh = {'copol_correlation_coeff': 0.99}
# Set up dictionary of variables to plot
var_dict = {
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ xarray
matplotlib
netcdf4
pint
open_radar_data

0 comments on commit 1fbd577

Please sign in to comment.