Skip to content

Commit

Permalink
Update avhrr_l1b_aapp and mers2_l1b readers with real reflectances
Browse files Browse the repository at this point in the history
Adds --normalized-radiances command line option
  • Loading branch information
djhoese committed Sep 27, 2024
1 parent 7ae70fc commit ecd791d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
34 changes: 32 additions & 2 deletions polar2grid/readers/avhrr_l1b_aapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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
36 changes: 34 additions & 2 deletions polar2grid/readers/mersi2_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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
Expand All @@ -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

0 comments on commit ecd791d

Please sign in to comment.