Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scale factor and offset [viirs_l1b] #3016

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions satpy/readers/viirs_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ def get_dataset(self, dataset_id, ds_info):
if factors[0] != 1 or factors[1] != 0:
data *= factors[0]
data += factors[1]

# remove scale_factor and scale_offset
data.attrs.pop("scale_factor", None)
data.attrs.pop("add_offset", None)

# rename dimensions to correspond to satpy's 'y' and 'x' standard
if "number_of_lines" in data.dims:
data = data.rename({"number_of_lines": "y", "number_of_pixels": "x"})
Expand Down
21 changes: 21 additions & 0 deletions satpy/tests/reader_tests/test_viirs_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,27 @@ def test_load_dnb_angles(self):
assert v.attrs["area"].lats.attrs["rows_per_scan"] == 2
assert v.attrs["sensor"] == "viirs"

def test_scale_factor_and_offset_update(self):
"""Test if scale_factor and add_offset are removed correctly."""
from satpy.readers import load_reader
from satpy.tests.utils import make_dataid
r = load_reader(self.reader_configs)
loadables = r.select_files_from_pathnames([
"VL1BM_snpp_d20161130_t012400_c20161130054822.nc",
"VGEOM_snpp_d20161130_t012400_c20161130054822.nc",
])
r.create_filehandlers(loadables)
datasets = r.load(["M01",
"M12",
"I04",
make_dataid(name="M01", calibration="radiance"),
make_dataid(name="M12", calibration="radiance"),
make_dataid(name="I04", calibration="radiance"),
])
for v in datasets.values():
assert ("scale_factor" not in v.attrs)
assert ("add_offset" not in v.attrs)


class TestVIIRSL1BReaderDayNight(TestVIIRSL1BReaderDay):
"""Test VIIRS L1b with night data.
Expand Down
Loading