Skip to content

Commit

Permalink
Update modis_l1b reader 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 061a75d commit 7ae70fc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
32 changes: 30 additions & 2 deletions polar2grid/readers/modis_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,17 @@

import argparse
from argparse import ArgumentParser, _ArgumentGroup
import logging
from typing import Optional

from satpy import DataQuery
from satpy import DataQuery, Scene

from polar2grid.core.script_utils import ExtendConstAction

from ._base import ReaderProxyBase

logger = logging.getLogger(__name__)

PREFERRED_CHUNK_SIZE: int = 1354 * 2 # roughly the number columns in a 500m dataset

FILTERS = {
Expand Down Expand Up @@ -199,6 +202,24 @@ 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 list(range(1, 8)) + [26]:
if modifiers:
logger.debug(f"Using visible channel modifiers: {modifiers}")
self._modified_aliases[f"{chan_num}"] = DataQuery(name=f"{chan_num}", modifiers=modifiers)
self._modified_aliases[f"vis{chan_num:02d}"] = 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 DEFAULTS
Expand All @@ -209,7 +230,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 Down Expand Up @@ -244,6 +265,13 @@ def add_reader_argument_groups(
const=VIS_PRODUCTS,
help="Add Visible products to list of products",
)
group.add_argument(
"--normalized-radiances",
dest="products",
action=ExtendConstAction,
const=["normalized_radiances"],
help="Do not apply '/ cos(SZA)' when loading visible bands.",
)
group.add_argument(
"--awips-true-color",
dest="products",
Expand Down
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,22 @@ filterwarnings = [
relative_files = true

[tool.ruff]
line-length = 120

[tool.ruff.lint]
# See https://docs.astral.sh/ruff/rules/
select = ["E", "W", "B", "D", "T10", "C90"]
# Remove D416 when all docstrings have been converted to google-style
ignore = ["D101", "D102", "D103", "D104", "D105", "D106", "D107", "E203", "D416"]
line-length = 120

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"doc/source/conf.py" = ["E501"]
"polar2grid/readers/*.py" = ["D205", "D400", "D415", "S101"] # assert allowed in tests

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
max-complexity = 10

[tool.ruff.lint.isort]
Expand Down

0 comments on commit 7ae70fc

Please sign in to comment.