Skip to content

Commit

Permalink
Merge pull request #115 from mraspaud/feature-frac
Browse files Browse the repository at this point in the history
Add support for frac data
  • Loading branch information
sfinkens committed Oct 24, 2022
2 parents fe4b883 + 2ecad40 commit f4c8fd8
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 60 deletions.
5 changes: 4 additions & 1 deletion pygac/gac_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@

LOG = logging.getLogger(__name__)


class GACReader(Reader):
"""Reader for GAC data."""

# Scanning frequency (scanlines per millisecond)
scan_freq = 2.0 / 1000.0
# Max scanlines
max_scanlines = 15000

def __init__(self, *args, **kwargs):
"""Init the GAC reader."""
Expand All @@ -48,7 +51,7 @@ def __init__(self, *args, **kwargs):

@classmethod
def _validate_header(cls, header):
"""Check if the header belongs to this reader"""
"""Check if the header belongs to this reader."""
# call super to enter the Method Resolution Order (MRO)
super(GACReader, cls)._validate_header(header)
LOG.debug("validate header")
Expand Down
7 changes: 5 additions & 2 deletions pygac/lac_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@

LOG = logging.getLogger(__name__)


class LACReader(Reader):
"""Reader for LAC data."""

# Scanning frequency (scanlines per millisecond)
scan_freq = 6.0 / 1000.0
# Max scanlines
max_scanlines = 65535

def __init__(self, *args, **kwargs):
"""Init the LAC reader."""
Expand All @@ -46,13 +49,13 @@ def __init__(self, *args, **kwargs):

@classmethod
def _validate_header(cls, header):
"""Check if the header belongs to this reader"""
"""Check if the header belongs to this reader."""
# call super to enter the Method Resolution Order (MRO)
super(LACReader, cls)._validate_header(header)
LOG.debug("validate header")
data_set_name = header['data_set_name'].decode()
# split header into parts
creation_site, transfer_mode, platform_id = (
data_set_name.split('.')[:3])
if transfer_mode not in ['LHRR', 'HRPT']:
if transfer_mode not in ["LHRR", "HRPT", "FRAC"]:
raise ReaderError('Improper transfer mode "%s"!' % transfer_mode)
52 changes: 26 additions & 26 deletions pygac/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,35 @@
# rpy values from
# here:http://yyy.rsmas.miami.edu/groups/rrsl/pathfinder/Processing/proc_app_a.html
rpy_coeffs = {
'noaa7': {'roll': 0.000,
'noaa7': {'roll': 0.000,
'pitch': 0.000,
'yaw': 0.000,
},
'noaa9': {'roll': 0.000,
'pitch': 0.0025,
'yaw': 0.000,
},
'noaa10': {'roll': 0.000,
'pitch': 0.000,
'yaw': 0.000,
},
'noaa9': {'roll': 0.000,
'pitch': 0.0025,
'yaw': 0.000,
},
'noaa10': {'roll': 0.000,
'pitch': 0.000,
'yaw': 0.000,
'yaw': 0.000,
},
'noaa11': {'roll': -0.0019,
'pitch': -0.0037,
'yaw': 0.000,
'yaw': 0.000,
},
'noaa12': {'roll': 0.000,
'noaa12': {'roll': 0.000,
'pitch': 0.000,
'yaw': 0.000,
'yaw': 0.000,
},
'noaa14': {'roll': 0.000,
'noaa14': {'roll': 0.000,
'pitch': 0.000,
'yaw': 0.000,
'yaw': 0.000,
}}


class ReaderError(ValueError):
"""Raised in Reader.read if the given file does not correspond to it"""
"""Raised in Reader.read if the given file does not correspond to it."""

pass


Expand Down Expand Up @@ -134,7 +135,7 @@ def __init__(self, interpolate_coords=True, adjust_clock_drift=True,

@property
def times(self):
"""The UTCs as datetime.datetime"""
"""Get the UTCs as datetime.datetime."""
return self.to_datetime(self.utcs)

@property
Expand Down Expand Up @@ -196,7 +197,7 @@ def read_header(cls, filename, fileobj=None): # pragma: no cover

@classmethod
def _correct_data_set_name(cls, header, filename):
"""Replace invalid data_set_name from header with filename
"""Replace invalid data_set_name from header with filename.
Args:
header (struct): file header
Expand All @@ -221,7 +222,7 @@ def _correct_data_set_name(cls, header, filename):

@classmethod
def _validate_header(cls, header):
"""Check if the header belongs to this reader
"""Check if the header belongs to this reader.
Note:
according to https://www1.ncdc.noaa.gov/pub/data/satellite/
Expand Down Expand Up @@ -258,7 +259,7 @@ def _validate_header(cls, header):
% header['data_set_name'])

def _read_scanlines(self, buffer, count):
"""Read the scanlines from the given buffer
"""Read the scanlines from the given buffer.
Args:
buffer (bytes, bytearray): buffer to read from
Expand Down Expand Up @@ -304,7 +305,7 @@ def can_read(cls, filename, fileobj=None):

@classmethod
def fromfile(cls, filename, fileobj=None):
"""Create Reader from file (alternative constructor)
"""Create Reader from file, alternative constructor.
Args:
filename (str): Path to GAC/LAC file
Expand All @@ -323,14 +324,14 @@ def fromfile(cls, filename, fileobj=None):
return instance

def _get_calibrated_channels_uniform_shape(self):
"""Prepare the channels as input for gac_io.save_gac"""
"""Prepare the channels as input for gac_io.save_gac."""
channels = self.get_calibrated_channels()
assert channels.shape[-1] == 6
return channels

def save(self, start_line, end_line, output_file_prefix="PyGAC", output_dir="./",
avhrr_dir=None, qual_dir=None, sunsatangles_dir=None):
"""Convert the Reader instance content into hdf5 files"""
"""Convert the Reader instance content into hdf5 files."""
avhrr_dir = avhrr_dir or output_dir
qual_dir = qual_dir or output_dir
sunsatangles_dir = sunsatangles_dir or output_dir
Expand Down Expand Up @@ -775,7 +776,6 @@ def get_angles(self):
and different ranges.
Returns:
sat_azi: satellite azimuth angle degree clockwise from north in
range ]-180, 180]
Expand Down Expand Up @@ -894,7 +894,7 @@ def correct_scan_line_numbers(self):
'n_orig': self.scans['scan_line_number'].copy()}

# Remove scanlines whose scanline number is outside the valid range
within_range = np.logical_and(self.scans["scan_line_number"] < 15000,
within_range = np.logical_and(self.scans["scan_line_number"] < self.max_scanlines,
self.scans["scan_line_number"] >= 0)
self.scans = self.scans[within_range]

Expand Down Expand Up @@ -1131,7 +1131,7 @@ def get_tsm_pixels(self, channels): # pragma: no cover
raise NotImplementedError

def get_attitude_coeffs(self):
"""Return the roll, pitch, yaw values"""
"""Return the roll, pitch, yaw values."""
if self._rpy is None:
if "constant_yaw_attitude_error" in self.head.dtype.fields:
rpy = np.deg2rad([self.head["constant_roll_attitude_error"] / 1e3,
Expand Down
Loading

0 comments on commit f4c8fd8

Please sign in to comment.