Skip to content

Commit

Permalink
respect verbosity, suppress numpy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonreusch committed Dec 22, 2022
1 parent 4ba98ec commit 2283a2c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
6 changes: 4 additions & 2 deletions ztflc/fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def fit(self, verbose=False, **kwargs):

# checking fit
if not self.minuit.valid:
warnings.warn("migrad is not valid")
if self._hfitverbose:
warnings.warn("migrad is not valid")
self.fit_ok = False
else:
self.fit_ok = True
Expand Down Expand Up @@ -190,7 +191,8 @@ def _read_hess_(hess):
)
for i, k in enumerate(self.FREEPARAMETERS):
fakeMatrix[i, i] = self.minuit.errors[k] ** 2
warnings.warn("Inaccurate covariance Matrix. Only trace defined")
if self._hfitverbose:
warnings.warn("Inaccurate covariance Matrix. Only trace defined")
return _read_hess_(fakeMatrix)

# --------- #
Expand Down
41 changes: 24 additions & 17 deletions ztflc/forcephotometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,18 @@ def run_forcefit(
print("NaNs in the image, skipped")
else:
try:
fitresults = diffdata.fit_flux()
datainfo = diffdata.get_main_info()
dataout[i] = {**fitresults, **datainfo}
dataout[i]["data_hasnan"] = has_nan
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fitresults = diffdata.fit_flux()
datainfo = diffdata.get_main_info()
dataout[i] = {**fitresults, **datainfo}
dataout[i]["data_hasnan"] = has_nan
except ValueError:
warnings.warn(
"Shape of diffimg and psfimg do not correspond (index: %d). Skipping."
% (i)
)
if verbose:
warnings.warn(
"Shape of diffimg and psfimg do not correspond (index: %d). Skipping."
% (i)
)
pass
del diffdata
gc.collect()
Expand Down Expand Up @@ -276,19 +279,23 @@ def get_ith_diffdata_multiprocess(args):
diffdata = DiffData(*filepath, coords)
has_nan = np.any(np.isnan(diffdata.diffimg))
if has_nan and no_badsub:
print("NaNs in the image, skipped")
if verbose:
print("NaNs in the image, skipped")
return None
else:
try:
fitresults = diffdata.fit_flux()
datainfo = diffdata.get_main_info()
dataout = {**fitresults, **datainfo}
dataout["data_hasnan"] = has_nan
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fitresults = diffdata.fit_flux()
datainfo = diffdata.get_main_info()
dataout = {**fitresults, **datainfo}
dataout["data_hasnan"] = has_nan
except ValueError:
warnings.warn(
"Shape of diffimg and psfimg do not correspond (index: %d). Skipping."
% (index)
)
if verbose:
warnings.warn(
"Shape of diffimg and psfimg do not correspond (index: %d). Skipping."
% (index)
)
return None
del diffdata

Expand Down

0 comments on commit 2283a2c

Please sign in to comment.