Skip to content

Commit 3b0bd5c

Browse files
authored
Merge pull request #129 from sfinkens/fix-encoding
Fix netCDF encoding in tests
2 parents 54b5044 + c53005c commit 3b0bd5c

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@ jobs:
2424
- name: Setup Conda Environment
2525
uses: conda-incubator/setup-miniconda@v3
2626
with:
27-
miniforge-variant: Mambaforge
2827
miniforge-version: latest
29-
use-mamba: true
3028
python-version: ${{ matrix.python-version }}
3129
environment-file: continuous_integration/environment.yaml
3230
activate-environment: test-environment
33-
3431
- name: Install pygac-fdr
3532
shell: bash -l {0}
3633
run: |

pygac_fdr/tests/test_writer.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,17 @@ def test_default_encoding(self):
5252
}
5353
for ch, data in test_data.items():
5454
enc = DEFAULT_ENCODING[ch]
55-
data_enc = ((data - enc["add_offset"]) / enc["scale_factor"]).astype(
56-
enc["dtype"]
57-
)
58-
data_dec = data_enc * enc["scale_factor"] + enc["add_offset"]
55+
offset = enc.get("add_offset", 0.0)
56+
data_enc = ((data - offset) / enc["scale_factor"]).astype(enc["dtype"])
57+
data_dec = data_enc * enc["scale_factor"] + offset
5958
np.testing.assert_allclose(data_dec, data, rtol=0.1)
6059

6160

6261
class TestNetcdfWriter:
6362
@pytest.fixture
6463
def scene_lonlats(self):
65-
lons = [[5, 6], [7, 8]]
66-
lats = [[1, 2], [3, 4]]
64+
lons = [[5.0, 6.0], [7.0, 8.0]]
65+
lats = [[1.0, 2.0], [3.0, 4.0]]
6766
return lons, lats
6867

6968
@pytest.fixture(params=[True, False])
@@ -107,7 +106,7 @@ def scene(self, scene_dataset_attrs, scene_lonlats):
107106
lat_id = make_dataid(name="latitude", resolution=1234.0, modifiers=())
108107
qual_flags_id = make_dataid(name="qual_flags", resolution=1234.0, modifiers=())
109108
scene[ch4_id] = xr.DataArray(
110-
[[1, 2], [3, 4]],
109+
[[1.0, 2.0], [3.0, 4.0]],
111110
dims=("y", "x"),
112111
coords={
113112
"acq_time": ("y", acq_time),

pygac_fdr/writer.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,13 @@
6060
"reflectance_channel_1": {
6161
"dtype": "int16",
6262
"scale_factor": 0.01,
63-
"add_offset": 0,
6463
"_FillValue": FILL_VALUE_INT16,
6564
"zlib": True,
6665
"complevel": 4,
6766
},
6867
"reflectance_channel_2": {
6968
"dtype": "int16",
7069
"scale_factor": 0.01,
71-
"add_offset": 0,
7270
"_FillValue": FILL_VALUE_INT16,
7371
"zlib": True,
7472
"complevel": 4,
@@ -84,7 +82,6 @@
8482
"reflectance_channel_3a": {
8583
"dtype": "int16",
8684
"scale_factor": 0.01,
87-
"add_offset": 0,
8885
"_FillValue": FILL_VALUE_INT16,
8986
"zlib": True,
9087
"complevel": 4,
@@ -116,55 +113,48 @@
116113
"latitude": {
117114
"dtype": "int32",
118115
"scale_factor": 0.001,
119-
"add_offset": 0,
120116
"_FillValue": FILL_VALUE_INT32,
121117
"zlib": True,
122118
"complevel": 4,
123119
},
124120
"longitude": {
125121
"dtype": "int32",
126122
"scale_factor": 0.001,
127-
"add_offset": 0,
128123
"_FillValue": FILL_VALUE_INT32,
129124
"zlib": True,
130125
"complevel": 4,
131126
},
132127
"sensor_azimuth_angle": {
133128
"dtype": "int16",
134129
"scale_factor": 0.01,
135-
"add_offset": 0.0,
136130
"_FillValue": FILL_VALUE_INT16,
137131
"zlib": True,
138132
"complevel": 4,
139133
},
140134
"sensor_zenith_angle": {
141135
"dtype": "int16",
142136
"scale_factor": 0.01,
143-
"add_offset": 0,
144137
"_FillValue": FILL_VALUE_INT16,
145138
"zlib": True,
146139
"complevel": 4,
147140
},
148141
"solar_azimuth_angle": {
149142
"dtype": "int16",
150143
"scale_factor": 0.01,
151-
"add_offset": 0.0,
152144
"_FillValue": FILL_VALUE_INT16,
153145
"zlib": True,
154146
"complevel": 4,
155147
},
156148
"solar_zenith_angle": {
157149
"dtype": "int16",
158150
"scale_factor": 0.01,
159-
"add_offset": 0,
160151
"_FillValue": FILL_VALUE_INT16,
161152
"zlib": True,
162153
"complevel": 4,
163154
},
164155
"sun_sensor_azimuth_difference_angle": {
165156
"dtype": "int16",
166157
"scale_factor": 0.01,
167-
"add_offset": 0,
168158
"_FillValue": FILL_VALUE_INT16,
169159
"zlib": True,
170160
"complevel": 4,

0 commit comments

Comments
 (0)