Skip to content

Commit

Permalink
ENH: Improve performance for xradar interface (#1621)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrover1 authored Aug 29, 2024
1 parent 4889289 commit 23ce767
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pyart/xradar/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,26 @@ def __init__(self, xradar, default_sweep="sweep_0", scan_type=None):
self.nsweeps = len(self.sweep_group_names)
self.combined_sweeps = self._combine_sweeps()
self.fields = self._find_fields(self.combined_sweeps)

# Check to see if the time is multidimensional - if it is, collapse it
if len(self.combined_sweeps.time.dims) > 1:
time = self.combined_sweeps.time.isel(range=0)
else:
time = self.combined_sweeps.time
self.time = dict(
data=(self.combined_sweeps.time - self.combined_sweeps.time.min()).astype(
"int64"
)
/ 1e9,
data=(time - time.min()).astype("int64").values / 1e9,
units=f"seconds since {pd.to_datetime(self.combined_sweeps.time.min().values).strftime('%Y-%m-%d %H:%M:%S.0')}",
calendar="gregorian",
)
self.range = dict(data=self.combined_sweeps.range.values)
self.azimuth = dict(data=self.combined_sweeps.azimuth.values)
self.elevation = dict(data=self.combined_sweeps.elevation.values)
# Check to see if the time is multidimensional - if it is, collapse it
if len(self.combined_sweeps.sweep_fixed_angle.dims) > 1:
self.combined_sweeps["sweep_fixed_angle"] = (
"sweep_number",
np.unique(self.combined_sweeps.sweep_fixed_angle),
)
self.fixed_angle = dict(data=self.combined_sweeps.sweep_fixed_angle.values)
self.antenna_transition = None
self.latitude = dict(
Expand Down Expand Up @@ -590,6 +599,10 @@ def _combine_sweeps(self):
# Stack the sweep number and azimuth together
stacked = merged.stack(gates=["sweep_number", "azimuth"]).transpose()

# Select the valid azimuths
good_azimuths = stacked.time.dropna("gates", how="all").gates
stacked = stacked.sel(gates=good_azimuths)

# Drop the missing gates
cleaned = stacked.where(stacked.time == stacked.time.dropna("gates"))

Expand Down

0 comments on commit 23ce767

Please sign in to comment.