Skip to content

Commit

Permalink
Merge pull request #129 from sfinkens/fix-encoding
Browse files Browse the repository at this point in the history
Fix netCDF encoding in tests
  • Loading branch information
sfinkens authored Oct 18, 2024
2 parents 54b5044 + c53005c commit 3b0bd5c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ jobs:
- name: Setup Conda Environment
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true
python-version: ${{ matrix.python-version }}
environment-file: continuous_integration/environment.yaml
activate-environment: test-environment

- name: Install pygac-fdr
shell: bash -l {0}
run: |
Expand Down
13 changes: 6 additions & 7 deletions pygac_fdr/tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,17 @@ def test_default_encoding(self):
}
for ch, data in test_data.items():
enc = DEFAULT_ENCODING[ch]
data_enc = ((data - enc["add_offset"]) / enc["scale_factor"]).astype(
enc["dtype"]
)
data_dec = data_enc * enc["scale_factor"] + enc["add_offset"]
offset = enc.get("add_offset", 0.0)
data_enc = ((data - offset) / enc["scale_factor"]).astype(enc["dtype"])
data_dec = data_enc * enc["scale_factor"] + offset
np.testing.assert_allclose(data_dec, data, rtol=0.1)


class TestNetcdfWriter:
@pytest.fixture
def scene_lonlats(self):
lons = [[5, 6], [7, 8]]
lats = [[1, 2], [3, 4]]
lons = [[5.0, 6.0], [7.0, 8.0]]
lats = [[1.0, 2.0], [3.0, 4.0]]
return lons, lats

@pytest.fixture(params=[True, False])
Expand Down Expand Up @@ -107,7 +106,7 @@ def scene(self, scene_dataset_attrs, scene_lonlats):
lat_id = make_dataid(name="latitude", resolution=1234.0, modifiers=())
qual_flags_id = make_dataid(name="qual_flags", resolution=1234.0, modifiers=())
scene[ch4_id] = xr.DataArray(
[[1, 2], [3, 4]],
[[1.0, 2.0], [3.0, 4.0]],
dims=("y", "x"),
coords={
"acq_time": ("y", acq_time),
Expand Down
10 changes: 0 additions & 10 deletions pygac_fdr/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,13 @@
"reflectance_channel_1": {
"dtype": "int16",
"scale_factor": 0.01,
"add_offset": 0,
"_FillValue": FILL_VALUE_INT16,
"zlib": True,
"complevel": 4,
},
"reflectance_channel_2": {
"dtype": "int16",
"scale_factor": 0.01,
"add_offset": 0,
"_FillValue": FILL_VALUE_INT16,
"zlib": True,
"complevel": 4,
Expand All @@ -84,7 +82,6 @@
"reflectance_channel_3a": {
"dtype": "int16",
"scale_factor": 0.01,
"add_offset": 0,
"_FillValue": FILL_VALUE_INT16,
"zlib": True,
"complevel": 4,
Expand Down Expand Up @@ -116,55 +113,48 @@
"latitude": {
"dtype": "int32",
"scale_factor": 0.001,
"add_offset": 0,
"_FillValue": FILL_VALUE_INT32,
"zlib": True,
"complevel": 4,
},
"longitude": {
"dtype": "int32",
"scale_factor": 0.001,
"add_offset": 0,
"_FillValue": FILL_VALUE_INT32,
"zlib": True,
"complevel": 4,
},
"sensor_azimuth_angle": {
"dtype": "int16",
"scale_factor": 0.01,
"add_offset": 0.0,
"_FillValue": FILL_VALUE_INT16,
"zlib": True,
"complevel": 4,
},
"sensor_zenith_angle": {
"dtype": "int16",
"scale_factor": 0.01,
"add_offset": 0,
"_FillValue": FILL_VALUE_INT16,
"zlib": True,
"complevel": 4,
},
"solar_azimuth_angle": {
"dtype": "int16",
"scale_factor": 0.01,
"add_offset": 0.0,
"_FillValue": FILL_VALUE_INT16,
"zlib": True,
"complevel": 4,
},
"solar_zenith_angle": {
"dtype": "int16",
"scale_factor": 0.01,
"add_offset": 0,
"_FillValue": FILL_VALUE_INT16,
"zlib": True,
"complevel": 4,
},
"sun_sensor_azimuth_difference_angle": {
"dtype": "int16",
"scale_factor": 0.01,
"add_offset": 0,
"_FillValue": FILL_VALUE_INT16,
"zlib": True,
"complevel": 4,
Expand Down

0 comments on commit 3b0bd5c

Please sign in to comment.