Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes to comp_z #1562

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions pyart/retrieve/comp_z.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
from netCDF4 import num2date
from pandas import to_datetime
from scipy.interpolate import interp2d
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old import should be removed

from scipy.interpolate import RectBivariateSpline

from pyart.core import Radar


def composite_reflectivity(radar, field="reflectivity", gatefilter=None):
def composite_reflectivity(radar, field="reflectivity", gatefilter=None,same_nyquist=True,nyquist_vector_idx=0):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between between the comment and same_

"""
Composite Reflectivity

Expand Down Expand Up @@ -41,6 +42,14 @@ def composite_reflectivity(radar, field="reflectivity", gatefilter=None):
gatefilter : GateFilter
GateFilter instance. None will result in no gatefilter mask being
applied to data.
same_nyquist: bool
During a volume scan (i.e., file) the PRF (nyqust velocity) can change.
This can create some odd artifacts at times with if data quality is low on certain scans.
To get around this, you can change the code to only take the max of scans with the same nyquist +/- 1 m/s.
Defult this will be on (True), but folks can turn this off.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defult to Default

nyquist_vector_idx: int
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space around colon

This integer works alongside the same_nyquist parameter. Do you want to match all the nyquists to sweep 0? use idx 0, sweep 1, use idx 1.
By default it is set to 0.

Returns
-------
Expand All @@ -58,6 +67,7 @@ def composite_reflectivity(radar, field="reflectivity", gatefilter=None):
# Determine the lowest sweep (used for metadata and such)
minimum_sweep = np.min(radar.sweep_number["data"])


# loop over all measured sweeps
for sweep in sorted(radar.sweep_number["data"]):
# get start and stop index numbers
Expand All @@ -66,6 +76,9 @@ def composite_reflectivity(radar, field="reflectivity", gatefilter=None):
# grab radar data
z = radar.get_field(sweep, field)
z_dtype = z.dtype

#get the nyquist, so we know which sweeps are the same sens.
nyquist = np.asarray([np.round(radar.get_nyquist_vel(sweep=sweep))])

# Use gatefilter
if gatefilter is not None:
Expand Down Expand Up @@ -102,18 +115,29 @@ def composite_reflectivity(radar, field="reflectivity", gatefilter=None):
lat_0[-1, :] = lat_0[0, :]

else:
# Configure the intperpolator
z_interpolator = interp2d(ranges, az, z, kind="linear")
# Configure the intperpolator
z_interpolator = RectBivariateSpline(az, ranges, z)


# Apply the interpolation
z = z_interpolator(ranges, azimuth_final)
z = z_interpolator(azimuth_final,ranges)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after comma


# if first sweep, create new dim, otherwise concat them up
if sweep == minimum_sweep:
z_stack = copy.deepcopy(z[np.newaxis, :, :])
nyquist_stack = copy.deepcopy(nyquist[np.newaxis,:])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after comma

else:
z_stack = np.concatenate([z_stack, z[np.newaxis, :, :]])
nyquist_stack = np.concatenate([nyquist_stack, nyquist[np.newaxis,:]])

#only stack up sweeps with the same nyquist
if same_nyquist:
left = np.where(nyquist_stack >= nyquist_stack[nyquist_vector_idx]-1)[0]
right = np.where(nyquist_stack <= nyquist_stack[nyquist_vector_idx]+1)[0]
same_ny = np.intersect1d(left,right)

z_stack = z_stack[same_ny]

# now that the stack is made, take max across vertical
compz = z_stack.max(axis=0).astype(z_dtype)

Expand Down Expand Up @@ -190,4 +214,4 @@ def composite_reflectivity(radar, field="reflectivity", gatefilter=None):
azimuth,
elevation,
instrument_parameters=instrument_parameters,
)
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove no newline

Loading