Skip to content

Commit

Permalink
fix(l1b): add smoothing phase in init
Browse files Browse the repository at this point in the history
  • Loading branch information
j-haacker committed Dec 5, 2024
1 parent e4c99d0 commit bf4c6fe
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions cryoswath/l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def noise_floor(noise):
# find and store POCAs and swath-starts
tmp = append_poca_and_swath_idxs(tmp)
# use lowpass-filtered phase difference at POCA
tmp = append_smoothed_complex_phase(tmp)
tmp["ph_diff_waveform_20_ku"] = xr.where(
tmp.ns_20_ku==tmp.poca_idx,
xr.apply_ufunc(np.angle, tmp.ph_diff_complex_smoothed),
Expand Down Expand Up @@ -315,12 +316,6 @@ def append_elev_diff_to_ref(self):
return self
__all__.append("append_elev_diff_to_ref")

def append_smoothed_complex_phase(self):
self["ph_diff_complex_smoothed"] = gauss_filter_DataArray(np.exp(1j*self.ph_diff_waveform_20_ku),
dim="ns_20_ku", window_extent=21, std=5)
return self
__all__.append("append_smoothed_complex_phase")

@classmethod
def from_id(cls, track_id: str|pd.Timestamp, **kwargs) -> Self:
track_id = pd.to_datetime(track_id)
Expand Down Expand Up @@ -357,8 +352,6 @@ def get_rgi_o2(self) -> str:
__all__.append("get_rgi_o2")

def phase_jump(self):
if not "ph_diff_complex_smoothed" in self.data_vars:
self = self.append_smoothed_complex_phase()
ph_diff_diff = self.ph_diff_complex_smoothed.diff("ns_20_ku")
# ! implement choosing tolerance
ph_diff_diff_tolerance = .1
Expand All @@ -378,8 +371,6 @@ def phase_outlier(self, tol: float|None = None):
# 0s below: set to an arbitrary off nadir angle at which the x_width should actually have the defined value
tol = (np.arctan(np.tan(np.deg2rad(0))+temp_x_width/temp_H)-np.deg2rad(0)) \
* 2*np.pi / np.tan(speed_of_light/Ku_band_freq/antenna_baseline)
if not "ph_diff_complex_smoothed" in self.data_vars:
self = self.append_smoothed_complex_phase()
# ph_diff_tol is small, so approx equal to secant length
return np.abs(np.exp(1j*self.ph_diff_waveform_20_ku) - self.ph_diff_complex_smoothed) > tol
__all__.append("phase_outlier")
Expand Down Expand Up @@ -656,6 +647,13 @@ def find_poca_idx_and_swath_start_idx(smooth_coh, coh_thr):
cs_l1b_ds["exclude_mask"] = xr.where(cs_l1b_ds.ns_20_ku<cs_l1b_ds.swath_start, True, cs_l1b_ds.exclude_mask)
return cs_l1b_ds
__all__.append("append_poca_and_swath_idxs")


def append_smoothed_complex_phase(cs_l1b_ds: "L1bData") -> "L1bData":
cs_l1b_ds["ph_diff_complex_smoothed"] = gauss_filter_DataArray(np.exp(1j*cs_l1b_ds.ph_diff_waveform_20_ku),
dim="ns_20_ku", window_extent=21, std=5)
return cs_l1b_ds
__all__.append("append_smoothed_complex_phase")


def build_flag_mask(cs_l1b_flag: xr.DataArray, flag_val_list: list) -> xr.DataArray:
Expand Down

0 comments on commit bf4c6fe

Please sign in to comment.