Skip to content

Commit

Permalink
Merge pull request #3050 from pnuu/feature-viirs-edr-volcanic-ash
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese authored Feb 7, 2025
2 parents d8c4382 + da46066 commit d1352a4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions satpy/etc/readers/viirs_edr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ file_types:
file_reader: !!python/name:satpy.readers.viirs_edr.VIIRSJRRFileHandler
file_patterns:
- 'JRR-IceAge_{version}_{platform_shortname}_s{start_time:%Y%m%d%H%M%S%f}_e{end_time:%Y%m%d%H%M%S%f}_c{creation_time}.nc'
jrr_volcanicash:
file_reader: !!python/name:satpy.readers.viirs_edr.VIIRSJRRFileHandler
drop_variables:
- Det_QF_Size
file_patterns:
- 'JRR-VolcanicAsh_{version}_{platform_shortname}_s{start_time:%Y%m%d%H%M%S%f}_e{end_time:%Y%m%d%H%M%S%f}_c{creation_time}.nc'


datasets:
Expand Down
2 changes: 2 additions & 0 deletions satpy/readers/viirs_edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ def __init__(self, filename, filename_info, filetype_info, **kwargs):
# use entire scans as chunks
row_chunks_m = max(get_chunk_size_limit() // 4 // M_COLS, 1) # 32-bit floats
row_chunks_i = row_chunks_m * 2
drop_variables = filetype_info.get("drop_variables", None)
self.nc = xr.open_dataset(self.filename,
decode_cf=True,
mask_and_scale=True,
drop_variables=drop_variables,
chunks={
"Columns": -1,
"Rows": row_chunks_m,
Expand Down
29 changes: 29 additions & 0 deletions satpy/tests/reader_tests/test_viirs_edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,24 @@ def _create_lst_variables() -> dict[str, xr.DataArray]:
return data_vars


@pytest.fixture(scope="module")
def volcanic_ash_file(tmp_path_factory: TempPathFactory) -> Path:
"""Generate fake *partial* Volcanic Ash VIIRs EDR file."""
fn = f"JRR-VolcanicAsh_v3r0_j01_s{START_TIME:%Y%m%d%H%M%S}0_e{END_TIME:%Y%m%d%H%M%S}0_c202307231023395.nc"
data_vars = _create_continuous_variables(
("AshBeta",),
data_attrs={
"units": "1",
"_FillValue": -999.,
}
)
# The 'Det_QF_Size' variable is actually a scalar, but the there's no way to check it is dropped other than
# making it 2D
data_vars["Det_QF_Size"] = xr.DataArray(np.array([[1, 2]], dtype=np.int32),
attrs={"_FillValue": -999, "units": "1"})
return _create_fake_file(tmp_path_factory, fn, data_vars)


def _create_continuous_variables(
var_names: Iterable[str],
data_attrs: None | dict = None
Expand Down Expand Up @@ -481,6 +499,17 @@ def test_get_platformname(self, surface_reflectance_file, filename_platform, exp
scn.load(["surf_refl_I01"])
assert scn["surf_refl_I01"].attrs["platform_name"] == exp_shortname

def test_volcanic_ash_drop_variables(self, volcanic_ash_file):
"""Test that Det_QF_Size variable is dropped when reading VolcanicAsh products.
The said variable is also used as a dimension in v3r0 files, so the reading fails
if it is not dropped.
"""
from satpy import Scene
scn = Scene(reader="viirs_edr", filenames=[volcanic_ash_file])
available = scn.available_dataset_names()
assert "Det_QF_Size" not in available


def _check_surf_refl_qf_data_arr(data_arr: xr.DataArray, multiple_files: bool) -> None:
_array_checks(data_arr, dtype=np.uint8, multiple_files=multiple_files)
Expand Down

0 comments on commit d1352a4

Please sign in to comment.