diff --git a/polar2grid/readers/avhrr_l1b_aapp.py b/polar2grid/readers/avhrr_l1b_aapp.py index 59019496..673ae314 100644 --- a/polar2grid/readers/avhrr_l1b_aapp.py +++ b/polar2grid/readers/avhrr_l1b_aapp.py @@ -53,11 +53,15 @@ from __future__ import annotations from argparse import ArgumentParser, _ArgumentGroup +import logging from typing import Optional -from satpy import DataQuery +from satpy import DataQuery, Scene from ._base import ReaderProxyBase +from ..core.script_utils import ExtendConstAction + +logger = logging.getLogger(__name__) FILTERS = { "day_only": { @@ -95,6 +99,25 @@ class ReaderProxy(ReaderProxyBase): is_polar2grid_reader = True + def __init__(self, scn: Scene, user_products: list[str]): + self._modified_aliases = PRODUCT_ALIASES.copy() + + try: + # they specified --normalized-radiances + user_products.remove("normalized_radiances") + apply_sunz = False + except ValueError: + apply_sunz = True + + modifiers = ("sunz_corrected",) if apply_sunz else () + for chan_name in ["1", "2", "3a", "band1_vis", "band2_vis", "band3a_vis"]: + if modifiers: + logger.debug(f"Using visible channel modifiers: {modifiers}") + self._modified_aliases[chan_name] = DataQuery( + name=chan_name, calibration="reflectance", modifiers=modifiers + ) + super().__init__(scn, user_products) + def get_default_products(self) -> list[str]: """Get products to load if users hasn't specified any others.""" return VIS_PRODUCTS + IR_PRODUCTS @@ -105,7 +128,7 @@ def get_all_products(self) -> list[str]: @property def _aliases(self) -> dict[str, DataQuery]: - return PRODUCT_ALIASES + return self._modified_aliases def add_reader_argument_groups( @@ -119,4 +142,11 @@ def add_reader_argument_groups( """ if group is None: group = parser.add_argument_group(title="AVHRR L1b AAPP Reader") + group.add_argument( + "--normalized-radiances", + dest="products", + action=ExtendConstAction, + const=["normalized_radiances"], + help="Do not apply '/ cos(SZA)' when loading visible bands.", + ) return group, None diff --git a/polar2grid/readers/mersi2_l1b.py b/polar2grid/readers/mersi2_l1b.py index 462e650f..71b303ad 100644 --- a/polar2grid/readers/mersi2_l1b.py +++ b/polar2grid/readers/mersi2_l1b.py @@ -98,9 +98,15 @@ from __future__ import annotations from argparse import ArgumentParser, _ArgumentGroup +import logging from typing import Optional +from satpy import Scene, DataQuery + from ._base import ReaderProxyBase +from ..core.script_utils import ExtendConstAction + +logger = logging.getLogger(__name__) ALL_BANDS = [str(x) for x in range(1, 26)] ALL_ANGLES = ["solar_zenith_angle", "solar_azimuth_angle", "sensor_zenith_angle", "sensor_azimuth_angle"] @@ -127,6 +133,23 @@ class ReaderProxy(ReaderProxyBase): is_polar2grid_reader = True + def __init__(self, scn: Scene, user_products: list[str]): + self._modified_aliases = PRODUCT_ALIASES.copy() + + try: + # they specified --normalized-radiances + user_products.remove("normalized_radiances") + apply_sunz = False + except ValueError: + apply_sunz = True + + modifiers = ("sunz_corrected",) if apply_sunz else () + for chan_num in range(1, 20): + if modifiers: + logger.debug(f"Using visible channel modifiers: {modifiers}") + self._modified_aliases[f"{chan_num}"] = DataQuery(name=f"{chan_num}", modifiers=modifiers) + super().__init__(scn, user_products) + def get_default_products(self) -> list[str]: """Get products to load if users hasn't specified any others.""" return DEFAULT_PRODUCTS @@ -137,11 +160,20 @@ def get_all_products(self) -> list[str]: @property def _aliases(self) -> dict: - return PRODUCT_ALIASES + return self._modified_aliases def add_reader_argument_groups( parser: ArgumentParser, group: Optional[_ArgumentGroup] = None ) -> tuple[Optional[_ArgumentGroup], Optional[_ArgumentGroup]]: """Add reader-specific command line arguments to an existing argument parser.""" - return None, None + if group is None: + group = parser.add_argument_group(title="MERSI-2 L1B Reader") + group.add_argument( + "--normalized-radiances", + dest="products", + action=ExtendConstAction, + const=["normalized_radiances"], + help="Do not apply '/ cos(SZA)' when loading visible bands.", + ) + return group, None