Skip to content

Commit

Permalink
#208 Merge pull request from deshima-dev/issue150
Browse files Browse the repository at this point in the history
Add signal spike removal
  • Loading branch information
astropenguin authored Sep 1, 2024
2 parents 66a695b + 77c85a6 commit 4e60087
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions decode/qlook.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,10 @@ def pswsc(
frequency_units=frequency_units,
)

da_despiked = despike(da)

# make spectrum
da_scan = select.by(da, "state", ["ON", "OFF"])
da_scan = select.by(da_despiked, "state", ["ON", "OFF"])
da_sub = da_scan.groupby("scan").map(subtract_per_scan)
spec = da_sub.mean("scan")

Expand All @@ -379,7 +381,7 @@ def pswsc(
fig, axes = plt.subplots(1, 2, figsize=DEFAULT_FIGSIZE)

ax = axes[0] # type: ignore
plot.data(da.scan, ax=ax)
plot.data(da_despiked.scan, ax=ax)

ax = axes[1] # type: ignore
plot.data(spec, x="frequency", s=5, hue=None, ax=ax)
Expand Down Expand Up @@ -1094,6 +1096,21 @@ def _scan(
return save_qlook(fig, file, overwrite=overwrite, **options)


def despike(dems: xr.DataArray, /) -> xr.DataArray:
is_spike = (
xr.zeros_like(dems.time, bool)
.reset_coords(drop=True)
.groupby(utils.phaseof(dems.beam))
.map(flag_spike)
)
return dems.where(~is_spike, drop=True)


def flag_spike(index: xr.DataArray, /) -> xr.DataArray:
index[:1] = index[-1:] = True
return index


def mean_in_time(dems: xr.DataArray) -> xr.DataArray:
"""Similar to DataArray.mean but keeps middle time."""
middle = dems[len(dems) // 2 : len(dems) // 2 + 1]
Expand Down

0 comments on commit 4e60087

Please sign in to comment.