Skip to content

Commit

Permalink
Allow overriding which header to use for pod
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Mar 18, 2024
1 parent d7569ca commit 5dc92fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
35 changes: 19 additions & 16 deletions pygac/pod_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def read(self, filename, fileobj=None):
# choose the right header depending on the date
with file_opener(fileobj or filename) as fd_:
self.tbm_head, self.head = self.read_header(
filename, fileobj=fd_)
filename, fileobj=fd_, eosip_header=self.eosip_header)
if self.tbm_head:
tbm_offset = tbm_header.itemsize
else:
Expand All @@ -302,12 +302,13 @@ def read(self, filename, fileobj=None):
return self.head, self.scans

@classmethod
def read_header(cls, filename, fileobj=None):
def read_header(cls, filename, fileobj=None, eosip_header=False):
"""Read the file header.
Args:
filename (str): Path to GAC/LAC file
fileobj: An open file object to read from. (optional)
eosip_header: if the format to read is eosip, use only the latest header format, independently of the date.
Returns:
archive_header (struct): archive header
Expand All @@ -332,20 +333,22 @@ def read_header(cls, filename, fileobj=None):
fd_.seek(0)
tbm_head = None
tbm_offset = 0
# read header
head0, = np.frombuffer(
fd_.read(header0.itemsize),
dtype=header0, count=1)
year, jday, _ = cls.decode_timestamps(head0["start_time"])
start_date = (datetime.date(year, 1, 1) +
datetime.timedelta(days=int(jday) - 1))
if start_date < datetime.date(1992, 9, 8):
header = header1
elif start_date <= datetime.date(1994, 11, 15):
header = header2
else:
header = header3
fd_.seek(tbm_offset, 0)
header = header3
if not eosip_header:

Check warning on line 337 in pygac/pod_reader.py

View check run for this annotation

Codecov / codecov/patch

pygac/pod_reader.py#L336-L337

Added lines #L336 - L337 were not covered by tests
# choose the appropriate header
head0, = np.frombuffer(

Check warning on line 339 in pygac/pod_reader.py

View check run for this annotation

Codecov / codecov/patch

pygac/pod_reader.py#L339

Added line #L339 was not covered by tests
fd_.read(header0.itemsize),
dtype=header0, count=1)
year, jday, _ = cls.decode_timestamps(head0["start_time"])
start_date = (datetime.date(year, 1, 1) +

Check warning on line 343 in pygac/pod_reader.py

View check run for this annotation

Codecov / codecov/patch

pygac/pod_reader.py#L342-L343

Added lines #L342 - L343 were not covered by tests
datetime.timedelta(days=int(jday) - 1))
if start_date < datetime.date(1992, 9, 8):
header = header1
elif start_date <= datetime.date(1994, 11, 15):
header = header2

Check warning on line 348 in pygac/pod_reader.py

View check run for this annotation

Codecov / codecov/patch

pygac/pod_reader.py#L345-L348

Added lines #L345 - L348 were not covered by tests
else:
header = header3
fd_.seek(tbm_offset, 0)

Check warning on line 351 in pygac/pod_reader.py

View check run for this annotation

Codecov / codecov/patch

pygac/pod_reader.py#L350-L351

Added lines #L350 - L351 were not covered by tests
# need to copy frombuffer to have write access on head
head, = np.frombuffer(
fd_.read(header.itemsize),
Expand Down
3 changes: 2 additions & 1 deletion pygac/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Reader(six.with_metaclass(ABCMeta)):

def __init__(self, interpolate_coords=True, adjust_clock_drift=True,
tle_dir=None, tle_name=None, tle_thresh=7, creation_site=None,
custom_calibration=None, calibration_file=None):
custom_calibration=None, calibration_file=None, eosip_header=False):
"""Init the reader.
Args:
Expand All @@ -122,6 +122,7 @@ def __init__(self, interpolate_coords=True, adjust_clock_drift=True,
self.creation_site = (creation_site or 'NSS').encode('utf-8')
self.custom_calibration = custom_calibration
self.calibration_file = calibration_file
self.eosip_header = eosip_header
self.head = None
self.scans = None
self.spacecraft_name = None
Expand Down

0 comments on commit 5dc92fc

Please sign in to comment.