Skip to content

Commit deed643

Browse files
Merge pull request #96 from BengtRydberg/vgac_time_units_fix
vgac time units
2 parents 0b7b95d + f060e48 commit deed643

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

level1c4pps/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,11 @@ def get_band_encoding(dataset, bandnames, pps_tagnames, chunks=None):
320320
'complevel': 4, '_FillValue': -32001.0}
321321
elif name in ['scanline_timestamps']:
322322
# pygac scanline_timestamps
323-
enc = {'dtype': 'int64', 'zlib': True,
324-
'units': 'Milliseconds since 1970-01-01',
325-
'complevel': 4, '_FillValue': -1.0}
323+
enc = {'dtype': 'int64',
324+
'zlib': True,
325+
'units': 'milliseconds since 1970-01-01',
326+
'complevel': 4,
327+
'_FillValue': -1.0}
326328
if not enc:
327329
raise ValueError('Unsupported band: {}'.format(name))
328330
return name, enc

level1c4pps/tests/test_eumgacfdr2pps.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_get_encoding(self):
8282
'qual_flags': {'dtype': 'int16', 'zlib': True,
8383
'complevel': 4, '_FillValue': -32001.0},
8484
'scanline_timestamps': {'dtype': 'int64', 'zlib': True,
85-
'units': 'Milliseconds since 1970-01-01',
85+
'units': 'milliseconds since 1970-01-01',
8686
'complevel': 4, '_FillValue': -1.0},
8787
}
8888
encoding = eumgacfdr2pps.get_encoding_gac(self.scene)

level1c4pps/tests/test_gac2pps.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_get_encoding(self):
8181
'qual_flags': {'dtype': 'int16', 'zlib': True,
8282
'complevel': 4, '_FillValue': -32001.0},
8383
'scanline_timestamps': {'dtype': 'int64', 'zlib': True,
84-
'units': 'Milliseconds since 1970-01-01',
84+
'units': 'milliseconds since 1970-01-01',
8585
'complevel': 4, '_FillValue': -1.0},
8686
}
8787
encoding = gac2pps.get_encoding_gac(self.scene)

level1c4pps/tests/test_vgac2pps.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ def test_get_encoding(self):
8080
'add_offset': 273.15},
8181
'qual_flags': {'dtype': 'int16', 'zlib': True,
8282
'complevel': 4, '_FillValue': -32001.0},
83-
'scanline_timestamps': {'dtype': 'int64', 'zlib': True,
84-
'units': 'Milliseconds since 1970-01-01',
85-
'complevel': 4, '_FillValue': -1.0},
83+
'scanline_timestamps': {'dtype': 'int64',
84+
'zlib': True,
85+
'units': 'milliseconds since 1970-01-01',
86+
'complevel': 4,
87+
'_FillValue': -1.0},
8688
}
8789
encoding = vgac2pps.get_encoding_viirs(self.scene)
8890
self.assertDictEqual(encoding, encoding_exp)
@@ -121,6 +123,10 @@ def test_process_one_scene(self):
121123

122124
np.testing.assert_almost_equal(pps_nc.variables['image1'].sun_earth_distance_correction_factor,
123125
1.0, decimal=4)
126+
assert (
127+
pps_nc.variables["scanline_timestamps"].units == "milliseconds since 1970-01-01"
128+
and pps_nc.variables["scanline_timestamps"].dtype == "int"
129+
)
124130

125131
def test_process_one_scene_n19(self):
126132
"""Test process one scene for one example file."""

level1c4pps/vgac2pps_lib.py

+8
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,13 @@ def split_scene_at_midnight(scene):
456456
return [scene]
457457

458458

459+
def fix_timestamp_datatype(scene, encoding):
460+
"""Fix time datatype."""
461+
param = "scanline_timestamps"
462+
if "milliseconds" in encoding[param]["units"]:
463+
scene[param].data = scene[param].data.astype('datetime64[ms]')
464+
465+
459466
def process_one_scene(scene_files, out_path, engine="h5netcdf",
460467
all_channels=False, pps_channels=False, orbit_n=0,
461468
noaa19_sbaf_version=None, avhrr_channels=False,
@@ -506,6 +513,7 @@ def process_one_scene(scene_files, out_path, engine="h5netcdf",
506513

507514
filename = compose_filename(scn_, out_path, instrument=sensor, band=irch)
508515
encoding = get_encoding_viirs(scn_)
516+
fix_timestamp_datatype(scn_, encoding)
509517

510518
scn_.save_datasets(writer="cf",
511519
filename=filename,

0 commit comments

Comments
 (0)