Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Mar 8, 2024
1 parent 7bc992c commit f0c382e
Showing 1 changed file with 44 additions and 19 deletions.
63 changes: 44 additions & 19 deletions satpy/readers/sar_c_safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,39 +735,64 @@ def load(self, dataset_keys, **kwargs):

def create_storage_items(self, files, **kwargs):
"""Create the storage items."""
filenames = files
self.files_by_type = self._get_files_by_type(files)
image_shapes = self._get_image_shapes()
calibrators = self._create_calibrators(image_shapes)
denoisers = self._create_denoisers(image_shapes)
measurement_handlers = self._create_measurement_handlers(calibrators, denoisers)

self.storage_items = measurement_handlers


def _get_files_by_type(self, files):
files_by_type = defaultdict(list)
for file_type, type_info in self.config["file_types"].items():
files_by_type[file_type].extend(self.filename_items_for_filetype(filenames, type_info))
files_by_type[file_type].extend(self.filename_items_for_filetype(files, type_info))
return files_by_type


def _get_image_shapes(self):
image_shapes = dict()
for annotation_file, annotation_info in files_by_type["safe_annotation"]:
for annotation_file, annotation_info in self.files_by_type["safe_annotation"]:
annotation_fh = SAFEXMLAnnotation(annotation_file,
filename_info=annotation_info,
filetype_info=None)
image_shapes[annotation_info["polarization"]] = annotation_fh.image_shape
return image_shapes


calibration_handlers = dict()
for calibration_file, calibration_info in files_by_type["safe_calibration"]:
def _create_calibrators(self, image_shapes):
calibrators = dict()
for calibration_file, calibration_info in self.files_by_type["safe_calibration"]:
polarization = calibration_info["polarization"]
calibration_handlers[polarization] = Calibrator(calibration_file,
filename_info=calibration_info,
filetype_info=None,
image_shape=image_shapes[polarization])
calibrators[polarization] = Calibrator(calibration_file,
filename_info=calibration_info,
filetype_info=None,
image_shape=image_shapes[polarization])

noise_handlers = dict()
for noise_file, noise_info in files_by_type["safe_noise"]:
return calibrators


def _create_denoisers(self, image_shapes):
denoisers = dict()
for noise_file, noise_info in self.files_by_type["safe_noise"]:
polarization = noise_info["polarization"]
noise_handlers[polarization] = Denoiser(noise_file,
filename_info=noise_info,
filetype_info=None,
image_shape=image_shapes[polarization])
denoisers[polarization] = Denoiser(noise_file,
filename_info=noise_info,
filetype_info=None,
image_shape=image_shapes[polarization])

return denoisers


def _create_measurement_handlers(self, calibrators, denoisers):
measurement_handlers = dict()
for measurement_file, measurement_info in files_by_type["safe_measurement"]:
for measurement_file, measurement_info in self.files_by_type["safe_measurement"]:
polarization = measurement_info["polarization"]
measurement_handlers[polarization] = SAFEGRD(measurement_file,
filename_info=measurement_info,
calibrator=calibration_handlers[polarization],
denoiser=noise_handlers[polarization],
calibrator=calibrators[polarization],
denoiser=denoisers[polarization],
filetype_info=None)
self.storage_items = measurement_handlers

return measurement_handlers

0 comments on commit f0c382e

Please sign in to comment.