Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --clip-negative-radiances flag to ABI L1b reader #637

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions polar2grid/core/script_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
import sys
from collections import defaultdict

try:
from argparse import BooleanOptionalAction
except ImportError:
BooleanOptionalAction = None

LOG = logging.getLogger(__name__)


Expand Down Expand Up @@ -310,53 +305,4 @@
action="store_true",
help="exit on first error including non-fatal errors",
)
return parser

Check notice on line 308 in polar2grid/core/script_utils.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Excess Number of Function Arguments

_BooleanOptionalAction.__init__ is no longer above the threshold for number of arguments


# Backport of BooleanOptionalAction (added in Python 3.9)
class _BooleanOptionalAction(argparse.Action):
def __init__(
self,
option_strings,
dest,
const=None,
default=None,
type=None,
choices=None,
required=False,
help=None,
metavar=None,
):
_option_strings = []
for option_string in option_strings:
_option_strings.append(option_string)

if option_string.startswith("--"):
option_string = "--no-" + option_string[2:]
_option_strings.append(option_string)

if help is not None and default is not None:
help += f" (default: {default})"

super().__init__(
option_strings=_option_strings,
dest=dest,
nargs=0,
default=default,
type=type,
choices=choices,
required=required,
help=help,
metavar=metavar,
)

def __call__(self, parser, namespace, values, option_string=None):
if option_string in self.option_strings:
setattr(namespace, self.dest, not option_string.startswith("--no-"))

def format_usage(self):
return " | ".join(self.option_strings)


if BooleanOptionalAction is None:
BooleanOptionalAction = _BooleanOptionalAction
8 changes: 7 additions & 1 deletion polar2grid/readers/abi_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

from __future__ import annotations

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

from ._base import ReaderProxyBase
Expand Down Expand Up @@ -142,4 +142,10 @@ def add_reader_argument_groups(
"""
if group is None:
group = parser.add_argument_group(title="ABI L1b Reader")
group.add_argument(
"--clip-negative-radiances",
action=BooleanOptionalAction,
default=True,
help="Clip negative radiances for IR bands. Default is to perform the clipping.",
)
return group, None
3 changes: 1 addition & 2 deletions polar2grid/readers/ahi_hsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@

from __future__ import annotations

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

from ..core.script_utils import BooleanOptionalAction
from ._base import ReaderProxyBase

PREFERRED_CHUNK_SIZE: int = 2200 # one segment
Expand Down
2 changes: 1 addition & 1 deletion polar2grid/writers/awips_tiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@

"""
import logging
from argparse import BooleanOptionalAction

from polar2grid.core.script_utils import BooleanOptionalAction
from polar2grid.utils.legacy_compat import convert_p2g_pattern_to_satpy

LOG = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion polar2grid/writers/geotiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
import argparse
import logging
import os
from argparse import BooleanOptionalAction

from polar2grid.core.dtype import NUMPY_DTYPE_STRS, int_or_float, str_to_dtype
from polar2grid.core.script_utils import BooleanOptionalAction, NumpyDtypeList
from polar2grid.core.script_utils import NumpyDtypeList
from polar2grid.utils.legacy_compat import convert_p2g_pattern_to_satpy

LOG = logging.getLogger(__name__)
Expand Down
Loading