Skip to content

Commit

Permalink
Merge pull request #32 from sfinkens/fix-ch3-encoding
Browse files Browse the repository at this point in the history
Fix channel 3 encoding
  • Loading branch information
sfinkens authored Sep 11, 2020
2 parents ceb31a8 + abc076d commit 4e52f7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
22 changes: 21 additions & 1 deletion pygac_fdr/tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
# You should have received a copy of the GNU General Public License along with
# pygac-fdr. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import unittest
from pygac_fdr.writer import NetcdfWriter
from pygac_fdr.writer import NetcdfWriter, DEFAULT_ENCODING


class NetcdfWriterTest(unittest.TestCase):
Expand All @@ -27,3 +28,22 @@ def test_get_integer_version(self):
self.assertEqual(writer._get_integer_version('1.2.3'), 123)
self.assertEqual(writer._get_integer_version('12.3.4'), 1234)
self.assertRaises(ValueError, writer._get_integer_version, '1.10.1')

def test_default_encoding(self):
bt_range = np.arange(170, 330, 1, dtype='f8')
refl_range = np.arange(0, 1.5, 0.1, dtype='f8')
test_data = {
'reflectance_channel_1': refl_range,
'reflectance_channel_2': refl_range,
'brightness_temperature_channel_3': bt_range,
'reflectance_channel_3a': refl_range,
'brightness_temperature_channel_3b': bt_range,
'brightness_temperature_channel_4': bt_range,
'brightness_temperature_channel_5': bt_range
}
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']
np.testing.assert_allclose(data_dec, data, rtol=0.1)
12 changes: 6 additions & 6 deletions pygac_fdr/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@
'_FillValue': FILL_VALUE_INT16,
'zlib': True,
'complevel': 4},
'reflectance_channel_3': {'dtype': 'int16',
'scale_factor': 0.01,
'add_offset': 0,
'_FillValue': FILL_VALUE_INT16,
'zlib': True,
'complevel': 4},
'brightness_temperature_channel_3': {'dtype': 'int16',
'scale_factor': 0.01,
'add_offset': 273.15,
'_FillValue': FILL_VALUE_INT16,
'zlib': True,
'complevel': 4},
'reflectance_channel_3a': {'dtype': 'int16',
'scale_factor': 0.01,
'add_offset': 0,
Expand Down

0 comments on commit 4e52f7d

Please sign in to comment.