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

DM-39726: Use warnings instead of numpy.warnings #797

Merged
merged 1 commit into from
Jun 20, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions python/lsst/pipe/tasks/dataFrameActions/_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from typing import Iterable

import warnings
import numpy as np
import pandas as pd
from astropy import units
Expand Down Expand Up @@ -51,19 +52,19 @@ def __call__(self, df: pd.DataFrame, **kwargs):
if not (fluxMag0 := kwargs.get('fluxMag0')):
fluxMag0 = 1/np.power(10, -0.4*self.coadd_zeropoint)

with np.warnings.catch_warnings():
np.warnings.filterwarnings('ignore', r'invalid value encountered')
np.warnings.filterwarnings('ignore', r'divide by zero')
with warnings.catch_warnings():
warnings.filterwarnings('ignore', r'invalid value encountered')
warnings.filterwarnings('ignore', r'divide by zero')
return -2.5 * np.log10(df[self.column] / fluxMag0)


class MagColumnNanoJansky(SingleColumnAction):

def __call__(self, df: pd.DataFrame, **kwargs):

with np.warnings.catch_warnings():
np.warnings.filterwarnings('ignore', r'invalid value encountered')
np.warnings.filterwarnings('ignore', r'divide by zero')
with warnings.catch_warnings():
warnings.filterwarnings('ignore', r'invalid value encountered')
warnings.filterwarnings('ignore', r'divide by zero')
return -2.5 * np.log10((df[self.column] * 1e-9) / 3631.0)


Expand Down
25 changes: 13 additions & 12 deletions python/lsst/pipe/tasks/functors.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from itertools import product
import logging
import os.path
import warnings

import pandas as pd
import numpy as np
Expand Down Expand Up @@ -787,9 +788,9 @@ def columns(self):
return [self.col]

def _func(self, df):
with np.warnings.catch_warnings():
np.warnings.filterwarnings('ignore', r'invalid value encountered')
np.warnings.filterwarnings('ignore', r'divide by zero')
with warnings.catch_warnings():
warnings.filterwarnings('ignore', r'invalid value encountered')
warnings.filterwarnings('ignore', r'divide by zero')
return -2.5*np.log10(df[self.col] / self.fluxMag0)

@property
Expand Down Expand Up @@ -821,9 +822,9 @@ def columns(self):
return [self.col, self.col + 'Err']

def _func(self, df):
with np.warnings.catch_warnings():
np.warnings.filterwarnings('ignore', r'invalid value encountered')
np.warnings.filterwarnings('ignore', r'divide by zero')
with warnings.catch_warnings():
warnings.filterwarnings('ignore', r'invalid value encountered')
warnings.filterwarnings('ignore', r'divide by zero')
fluxCol, fluxErrCol = self.columns
x = df[fluxErrCol] / df[fluxCol]
y = self.fluxMag0Err / self.fluxMag0
Expand All @@ -850,9 +851,9 @@ def columns(self):
return [self.col1, self.col2]

def _func(self, df):
with np.warnings.catch_warnings():
np.warnings.filterwarnings('ignore', r'invalid value encountered')
np.warnings.filterwarnings('ignore', r'divide by zero')
with warnings.catch_warnings():
warnings.filterwarnings('ignore', r'invalid value encountered')
warnings.filterwarnings('ignore', r'divide by zero')
return -2.5*np.log10(df[self.col1]/df[self.col2])

@property
Expand Down Expand Up @@ -1375,9 +1376,9 @@ def dn2flux(self, dn, fluxMag0):
return self.AB_FLUX_SCALE * dn / fluxMag0

def dn2mag(self, dn, fluxMag0):
with np.warnings.catch_warnings():
np.warnings.filterwarnings('ignore', r'invalid value encountered')
np.warnings.filterwarnings('ignore', r'divide by zero')
with warnings.catch_warnings():
warnings.filterwarnings('ignore', r'invalid value encountered')
warnings.filterwarnings('ignore', r'divide by zero')
return -2.5 * np.log10(dn/fluxMag0)

def dn2fluxErr(self, dn, dnErr, fluxMag0, fluxMag0Err):
Expand Down
10 changes: 6 additions & 4 deletions python/lsst/pipe/tasks/skyCorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

__all__ = ["SkyCorrectionTask", "SkyCorrectionConfig"]

import warnings

import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.pipe.base.connectionTypes as cT
Expand Down Expand Up @@ -468,8 +470,8 @@ def _subtractVisitBackground(self, calExps, calBkgs, camera, config):
"Focal plane background model constructed using %.2f x %.2f mm (%d x %d pixel) superpixels; "
"FP BG median = %.1f counts, FP BG IQR = %.1f counts"
)
with np.warnings.catch_warnings():
np.warnings.filterwarnings("ignore", r"invalid value encountered")
with warnings.catch_warnings():
warnings.filterwarnings("ignore", r"invalid value encountered")
stats = np.nanpercentile(bgModelBase.getStatsImage().array, [50, 75, 25])
self.log.info(
msg,
Expand Down Expand Up @@ -506,8 +508,8 @@ def _subtractDetectorBackground(self, calExp, bgModel):
Detector level realization of the full focal plane bg model.
"""
image = calExp.getMaskedImage()
with np.warnings.catch_warnings():
np.warnings.filterwarnings("ignore", r"invalid value encountered")
with warnings.catch_warnings():
warnings.filterwarnings("ignore", r"invalid value encountered")
calBkgElement = bgModel.toCcdBackground(calExp.getDetector(), image.getBBox())
image -= calBkgElement.getImage()
return calExp, calBkgElement
Expand Down