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

silence missing DEM tiles during geolocation #481

Open
kjurka opened this issue Nov 17, 2023 · 1 comment
Open

silence missing DEM tiles during geolocation #481

kjurka opened this issue Nov 17, 2023 · 1 comment

Comments

@kjurka
Copy link
Contributor

kjurka commented Nov 17, 2023

We have SICDs from all over the place (inland, littoral, ocean, ...). When doing geolocation, we want the best possible accuracy and specify a DEM source for image_to_ground operations. When our imagery is not near land we get a ton of warnings from the below code as there is not DEM data available.

msg = 'Missing expected DEM files for squares with lower left lat/lon corner {}'.format(missing_boxes)

For us this is a totally expected situation. There appears to be a missing_error option in DTEDList to specify that you want this elevated to an error, but we'd like the opposite, for it to be silenced.

Would it be reasonable to change missing_error to missing_action with options of ('error', 'warning', 'silent') with the default being the existing warning?

@pressler-vsc
Copy link
Collaborator

Thanks for writing this up! I too find the presence of missing_error in the interface and its behavior a bit odd. That said, I would be hesitant to change/complicate an interface if there is a workable resolution that is possibly extensible to other logging records throughout SarPy. Is filtering the logging a feasible approach for your use case?

filter logging stubs
# module_with_warning.py
import logging

logger = logging.getLogger(__name__)

def func(msg):
    logger.warning(f'Missing expected DEM files for squares with lower left\n{msg}\n')
# main.py
import contextlib
import logging

import module_with_warning


@contextlib.contextmanager
def temp_filter(logger, filt):
    try:
        logger.addFilter(filt)
        yield logger
    finally:
        logger.removeFilter(filt)


def suppress_missing_dem_warning(rec):
    return not (rec.levelname == 'WARNING' and rec.msg.startswith('Missing expected DEM files for squares'))


module_with_warning.func('This warning is not suppressed')


with temp_filter(logging.getLogger('module_with_warning'), suppress_missing_dem_warning):
    module_with_warning.func('This warning IS suppressed')

module_with_warning.func('This warning is back to not being suppressed')
python main.py 
Missing expected DEM files for squares with lower left
This warning is not suppressed

Missing expected DEM files for squares with lower left
This warning is back to not being suppressed

Moving forward, we may also consider using warnings.warn which are easier to temporarily suppress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants