Skip to content

Commit

Permalink
Merge pull request #69 from ninahakansson/fix_image_numbering
Browse files Browse the repository at this point in the history
Fix image numbering
  • Loading branch information
ninahakansson authored Mar 2, 2022
2 parents 681809d + 320a4a6 commit 27bb643
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
24 changes: 20 additions & 4 deletions level1c4pps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@
# package is not installed
pass

PPS_TAGNAMES_TO_IMAGE_NR = {'ch_r06': 'image1',
'ch_r09': 'image2',
'ch_tb11': 'image3',
'ch_tb12': 'image4',
'ch_tb37': 'image5',
'ch_r16': 'image6',
'ch_tb85': 'image7',
'ch_r13': 'image8',
'ch_r22': 'image9',
'ch_r21': 'image10',
'ch_tb67': 'image11',
'ch_tb73': 'image12',
'ch_tb133': 'image13'}

ATTRIBUTES_TO_DELETE_FROM_CHANNELS = [
'_satpy_id',
'_satpy_id_calibration',
Expand Down Expand Up @@ -351,7 +365,6 @@ def adjust_lons_to_valid_range(scene):

def set_header_and_band_attrs_defaults(scene, BANDNAMES, PPS_TAGNAMES, REFL_BANDS, irch, orbit_n=0):
"""Add some default values for band attributes."""
nimg = 0 # name of first dataset is image0
# Set some header attributes:
scene.attrs['history'] = "Created by level1c4pps."
scene.attrs['history'] += irch.attrs.pop('history', "")
Expand Down Expand Up @@ -389,6 +402,7 @@ def set_header_and_band_attrs_defaults(scene, BANDNAMES, PPS_TAGNAMES, REFL_BAND
scene.attrs[attr] = irch.attrs[attr]

# bands
nimg = 20 # name of first dataset id_tag ch_rxx or ch_tbxx is image20
for band in BANDNAMES:
if band not in scene:
continue
Expand All @@ -404,7 +418,11 @@ def set_header_and_band_attrs_defaults(scene, BANDNAMES, PPS_TAGNAMES, REFL_BAND
scene[band].attrs['sun_earth_distance_correction_applied'] = 'True'
scene[band].attrs['wavelength'] = scene[band].attrs['wavelength'][0:3]
scene[band].attrs['sun_zenith_angle_correction_applied'] = 'False'
scene[band].attrs['name'] = "image{:d}".format(nimg)
if idtag in PPS_TAGNAMES_TO_IMAGE_NR:
scene[band].attrs['name'] = PPS_TAGNAMES_TO_IMAGE_NR[idtag]
else:
scene[band].attrs['name'] = "image{:d}".format(nimg)
nimg += 1
scene[band].attrs['coordinates'] = 'lon lat'
if band in REFL_BANDS:
scene[band].attrs['valid_range'] = np.array([0, 20000], dtype='int16')
Expand Down Expand Up @@ -434,8 +452,6 @@ def set_header_and_band_attrs_defaults(scene, BANDNAMES, PPS_TAGNAMES, REFL_BAND
del scene[band].coords[coord_name]
except KeyError:
pass

nimg += 1
return nimg


Expand Down
4 changes: 2 additions & 2 deletions level1c4pps/tests/test_eumgacfdr2pps.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_process_one_file(self):
expected_vars = ['satzenith', 'azimuthdiff',
'satazimuth', 'sunazimuth', 'sunzenith',
'time', 'y', 'num_flags', 'lon', 'lat', 'qual_flags',
'image1', 'image3', 'image0', 'image2',
'image1', 'image3', 'image2', 'image5',
'midnight_line', 'overlap_free_end',
'overlap_free_start', 'x',
'equator_crossing_longitude',
Expand All @@ -127,7 +127,7 @@ def test_process_one_file(self):
self.assertEqual(sorted(pps_nc.variables.keys()),
sorted(expected_vars))

np.testing.assert_almost_equal(pps_nc.variables['image0'].sun_earth_distance_correction_factor,
np.testing.assert_almost_equal(pps_nc.variables['image1'].sun_earth_distance_correction_factor,
0.9975245, decimal=4)


Expand Down
8 changes: 4 additions & 4 deletions level1c4pps/tests/test_gac2pps.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_process_one_file(self):
self.assertTrue(key in sorted(pps_nc.__dict__.keys()))
expected_vars = ['satzenith', 'azimuthdiff', 'satazimuth', 'sunazimuth', 'sunzenith',
'time', 'y', 'num_flags', 'lon', 'lat', 'qual_flags',
'image1', 'image3', 'image0', 'image2',
'image1', 'image5', 'image3', 'image2',
'scanline_timestamps', 'time_bnds']
optional = ['bands_1d', 'acq_time']
for var in optional:
Expand All @@ -139,7 +139,7 @@ def test_process_one_file(self):
self.assertEqual(sorted(pps_nc.variables.keys()),
sorted(expected_vars))

np.testing.assert_almost_equal(pps_nc.variables['image0'].sun_earth_distance_correction_factor,
np.testing.assert_almost_equal(pps_nc.variables['image1'].sun_earth_distance_correction_factor,
0.9666, decimal=4)

def test_process_one_file_netcdf4(self):
Expand All @@ -161,7 +161,7 @@ def test_process_one_file_netcdf4(self):

expected_vars = ['satzenith', 'azimuthdiff', 'satazimuth', 'sunazimuth', 'sunzenith',
'time', 'y', 'num_flags', 'lon', 'lat', 'qual_flags',
'image1', 'image3', 'image0', 'image2',
'image1', 'image5', 'image3', 'image2',
'scanline_timestamps', 'time_bnds']
optional = ['bands_1d', 'acq_time']
for var in optional:
Expand All @@ -170,7 +170,7 @@ def test_process_one_file_netcdf4(self):
self.assertEqual(sorted(pps_nc.variables.keys()),
sorted(expected_vars))

np.testing.assert_almost_equal(pps_nc.variables['image0'].sun_earth_distance_correction_factor,
np.testing.assert_almost_equal(pps_nc.variables['image1'].sun_earth_distance_correction_factor,
0.9666, decimal=4)


Expand Down
2 changes: 1 addition & 1 deletion level1c4pps/viirs2pps_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"I03": 'ch_r16',
"I04": 'ch_tb37',
# Not used by pps:
"M11": 'ch_r21',
"M11": 'ch_r22',
"I05": 'ch_tbxx',
"M01": 'ch_rxx',
"M02": 'ch_rxx',
Expand Down

0 comments on commit 27bb643

Please sign in to comment.