Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 30 additions & 1 deletion satpy/readers/amsr2_l2_gaasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@
reader appends a `_NH` and `_SH` suffix to all variable names that are
dynamically discovered from the provided files.

Data Quality Filtering
^^^^^^^^^^^^^^^^^^^^^^

Some variables can be filtered based on Quality Control (QC) variables in the
data files. At the time of writing the only supported filtering is the "WSPD"
variable from the "OCEAN" files using the "WSPD_QC" variable. Where the QC
variable is non-zero the WSPD data is set to NaN. By default no filtering is
applied. To enable filtering pass the keyword arguments to the ``Scene``::

scn = Scene(reader="amsr2_l2_gaasp", filenames=[...],
reader_kwargs={"filter_wind_speed": True})

Note that many variables in the GAASP data files already have additional
quality filtering applied by the algorithm.

"""

import datetime as dt
Expand Down Expand Up @@ -74,6 +89,11 @@ class GAASPFileHandler(BaseFileHandler):
"Number_of_low_rez_FOVs": 10000,
}

def __init__(self, filename, filename_info, filetype_info, filter_wind_speed=False):
"""Initialize file reading and store filter keyword arguments."""
super().__init__(filename, filename_info, filetype_info)
self.filter_wind_speed = filter_wind_speed

@cached_property
def nc(self):
"""Get the xarray dataset for this file."""
Expand Down Expand Up @@ -129,7 +149,8 @@ def _scale_data(self, data_arr, attrs):
add_offset = attrs.pop("add_offset", 0.)
scaling_needed = not (scale_factor == 1 and add_offset == 0)
if scaling_needed:
data_arr = data_arr * scale_factor + add_offset
new_dtype = np.float32 if np.issubdtype(data_arr.dtype, np.integer) else data_arr.dtype.type
data_arr = data_arr * new_dtype(scale_factor) + new_dtype(add_offset)
return data_arr, attrs

@staticmethod
Expand Down Expand Up @@ -165,6 +186,7 @@ def get_dataset(self, dataid, ds_info):
attrs = data_arr.attrs.copy()
data_arr, attrs = self._scale_data(data_arr, attrs)
data_arr, attrs = self._fill_data(data_arr, attrs)
data_arr = self._filter_by_qc(orig_var_name, data_arr)

attrs.update({
"platform_name": self.platform_name,
Expand All @@ -180,6 +202,13 @@ def get_dataset(self, dataid, ds_info):
data_arr.attrs = attrs
return data_arr

def _filter_by_qc(self, orig_var_name: str, data_arr: xr.DataArray) -> xr.DataArray:
if orig_var_name == "WSPD" and self.filter_wind_speed:
wspd_qc = self.nc["WSPD_QC"]
data_arr = data_arr.where(wspd_qc == 0)
return data_arr


def _available_if_this_file_type(self, configured_datasets):
for is_avail, ds_info in (configured_datasets or []):
if is_avail is not None:
Expand Down
Loading
Loading