Skip to content

Commit

Permalink
Fix unintended removal of handlers from the root logger (#245)
Browse files Browse the repository at this point in the history
* Fix logging and clean up

* Fix text

* Fix text

* Remove install of old pybdsm script
  • Loading branch information
darafferty authored Nov 15, 2024
1 parent e0f306d commit 0df0e1a
Show file tree
Hide file tree
Showing 32 changed files with 113 additions and 359 deletions.
2 changes: 1 addition & 1 deletion bdsf/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Op_cleanup(Op):
""" """
def __call__(self, img):

mylog = mylogger.logging.getLogger("PyBDSM.Cleanup")
mylog = mylogger.logging.getLogger("PyBDSF.Cleanup")

### plotresults for all gaussians together
if img.opts.plot_allgaus and has_pl:
Expand Down
2 changes: 1 addition & 1 deletion bdsf/collapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Op_collapse(Op):
"""Collapse 3D image"""

def __call__(self, img):
mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Collapse")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Collapse")
if img.opts.polarisation_do:
pols = ['I', 'Q', 'U', 'V'] # make sure I is done first
else:
Expand Down
10 changes: 5 additions & 5 deletions bdsf/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ def get_errors(img, p, stdav, bm_pix=None, fixed_to_beam=False):
from . import mylogger
import numpy as N

mylog = mylogger.logging.getLogger("PyBDSM.Compute")
mylog = mylogger.logging.getLogger("PyBDSF.Compute")

if len(p) % 7 > 0:
mylog.error("Gaussian parameters passed have to have 7n numbers")
Expand Down Expand Up @@ -1116,7 +1116,7 @@ def read_image_from_file(filename, img, indir, quiet=False):
except ImportError as err:
has_casacore = False

mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Readfile")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Readfile")
if indir is None or indir == './':
prefix = ''
else:
Expand Down Expand Up @@ -1370,7 +1370,7 @@ def write_image_to_file(use, filename, image, img, outdir=None,
import os
from . import mylogger

mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Writefile")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Writefile")

wcs_obj = img.wcs_obj
if pad_image and img.opts.trim_box is not None:
Expand Down Expand Up @@ -1407,7 +1407,7 @@ def write_image_to_file(use, filename, image, img, outdir=None,
# The "overwrite" argument was added in astropy v1.3, so fall back to "clobber"
# if it doesn't work
temp_im.writeto(tfile.name, clobber=clobber)
send_fits_image(img.samp_client, img.samp_key, 'PyBDSM image', tfile.name)
send_fits_image(img.samp_client, img.samp_key, 'PyBDSF image', tfile.name)
else:
# Write image to FITS file
if outdir is None:
Expand Down Expand Up @@ -2017,7 +2017,7 @@ def start_samp_proxy():
s = ServerProxy(HUB_PARAMS['samp.hub.xmlrpc.url'])

# Register with Hub
metadata = {"samp.name": 'PyBDSM', "samp.description.text": 'PyBDSM: the Python Blob Detection and Source Measurement software'}
metadata = {"samp.name": 'PyBDSF', "samp.description.text": 'PyBDSF: the Python Blob Detector and Source Finder software'}
result = s.samp.hub.register(HUB_PARAMS['samp.secret'])
private_key = result['samp.private-key']
s.samp.hub.declareMetadata(private_key, metadata)
Expand Down
4 changes: 2 additions & 2 deletions bdsf/gaul2srl.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Op_gaul2srl(Op):
def __call__(self, img):
# for each island, get the gaussians into a list and then send them to process
# src_index is source number, starting from 0
mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Gaul2Srl")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Gaul2Srl")
mylogger.userinfo(mylog, 'Grouping Gaussians into sources')
img.aperture = img.opts.aperture
if img.aperture is not None and img.aperture <= 0.0:
Expand Down Expand Up @@ -325,7 +325,7 @@ def process_Multiple(self, img, g_sublist, mask, src_index, isrc, subim, isl, de
from scipy import ndimage
from . import functions as func

mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Gaul2Srl ")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Gaul2Srl ")
dum = img.beam[0]*img.beam[1]
cdeltsq = img.wcs_obj.acdelt[0]*img.wcs_obj.acdelt[1]
bmar_p = 2.0*pi*dum/(cdeltsq*fwsig*fwsig)
Expand Down
4 changes: 2 additions & 2 deletions bdsf/gausfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Op_gausfit(Op):
def __call__(self, img):
from . import functions as func

mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Gausfit")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Gausfit")
if len(img.islands) == 0:
img.gaussians = []
img.ngaus = 0
Expand Down Expand Up @@ -946,7 +946,7 @@ def __init__(self, img, gaussian, isl_idx, g_idx, flg=0):
"""Initialize Gaussian object from fitting data
Parameters:
img: PyBDSM image object
img: PyBDSF image object
gaussian: 6-tuple of fitted numbers
isl_idx: island serial number
g_idx: gaussian serial number
Expand Down
2 changes: 1 addition & 1 deletion bdsf/islands.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Op_islands(Op):
Prerequisites: module rmsimage should be run first.
"""
def __call__(self, img):
mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Islands")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Islands")
opts = img.opts

minsize = opts.minpix_isl
Expand Down
2 changes: 1 addition & 1 deletion bdsf/make_residimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __call__(self, img):
from copy import deepcopy as cp
import os

mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"ResidImage")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"ResidImage")
mylog.info("Calculating residual image after subtracting reconstructed gaussians")
shape = img.ch0_arr.shape
thresh= img.opts.fittedimage_clip
Expand Down
4 changes: 2 additions & 2 deletions bdsf/mylogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
def init_logger(logfilename, quiet=False, debug=False):
logging.USERINFO = logging.INFO + 1
logging.addLevelName(logging.USERINFO, 'USERINFO')
logger = logging.root
logger = logging.getLogger('PyBDSF')
logger.setLevel(logging.DEBUG)

# First remove any existing handlers (in case PyBDSM has been run
# First remove any existing handlers (in case PyBDSF has been run
# before in this session but the quiet or debug options have changed
while len(logger.handlers) > 0:
logger.removeHandler(logger.handlers[0])
Expand Down
2 changes: 1 addition & 1 deletion bdsf/opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ class Opts(object):
group = "output_opts")
output_all = Bool(False,
doc = "Write out all files automatically to directory "\
"'outdir/filename_pybdsm'",
"'outdir/filename_pybdsf'",
group = "output_opts")
opdir_overwrite = Enum('overwrite', 'append',
doc = "'overwrite'/'append': If output_all=True, "\
Expand Down
32 changes: 16 additions & 16 deletions bdsf/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def write_opts(self, img, dir):
import inspect
from . import mylogger

mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Output")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Output")
fname = 'parameters_used'
f = open(dir+fname, 'w')
mylog.info('Writing '+dir+fname)
Expand All @@ -139,11 +139,11 @@ def write_opts(self, img, dir):
f.close()

def save_opts(self, img, dir):
""" Saves input parameters to a PyBDSM save file."""
""" Saves input parameters to a PyBDSF save file."""
from . import interface
from . import mylogger

mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Output")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Output")
fname = 'parameters.sav'
mylog.info('Writing '+dir+fname)
interface.save_pars(img, dir+fname, quiet=True)
Expand Down Expand Up @@ -215,7 +215,7 @@ def write_bbs_gaul(img, filename=None, srcroot=None, patch=None,
from . import mylogger
import os

mylog = mylogger.logging.getLogger("PyBDSM.write_gaul")
mylog = mylogger.logging.getLogger("PyBDSF.write_gaul")
if int(img.equinox) != 2000 and int(img.equinox) != 1950:
mylog.warning('Equinox of input image is not J2000 or B1950. '
'Sky model may not be appropriate for BBS.')
Expand Down Expand Up @@ -247,7 +247,7 @@ def write_lsm_gaul(img, filename=None, srcroot=None, patch=None,
from . import mylogger
import os

mylog = mylogger.logging.getLogger("PyBDSM.write_gaul")
mylog = mylogger.logging.getLogger("PyBDSF.write_gaul")
if int(img.equinox) != 2000 and int(img.equinox) != 1950:
mylog.warning('Equinox of input image is not J2000 or B1950. '
'Sky model may not be appropriate for Sagecal.')
Expand Down Expand Up @@ -277,7 +277,7 @@ def write_ds9_list(img, filename=None, srcroot=None, deconvolve=False,
from . import mylogger
import os

mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Output")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Output")
if objtype == 'gaul':
outl, outn, patl = list_and_sort_gaussians(img, patch=None)
elif objtype == 'srl':
Expand Down Expand Up @@ -316,7 +316,7 @@ def write_ascii_list(img, filename=None, sort_by='indx', format='ascii',
from . import mylogger
import os

mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Output")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Output")
if objtype == 'gaul':
outl, outn, patl = list_and_sort_gaussians(img, patch=None, sort_by=sort_by)
elif objtype == 'srl':
Expand Down Expand Up @@ -346,7 +346,7 @@ def write_casa_gaul(img, filename=None, incl_empty=False, clobber=False):
from . import mylogger
import os

mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Output")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Output")
outl, outn, patl = list_and_sort_gaussians(img, patch=None)
outstr_list = make_casa_str(img, outl)
if filename is None:
Expand All @@ -371,7 +371,7 @@ def write_fits_list(img, filename=None, sort_by='index', objtype='gaul',
from astropy.io import fits as pyfits
from ._version import __version__

mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Output")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Output")
if objtype == 'gaul':
outl, outn, patl = list_and_sort_gaussians(img, patch=None, sort_by=sort_by)
elif objtype == 'srl':
Expand Down Expand Up @@ -421,7 +421,7 @@ def write_fits_list(img, filename=None, sort_by='index', objtype='gaul',
tbhdu.header.add_comment('Source list for '+img.filename)
elif objtype == 'shap':
tbhdu.header.add_comment('Shapelet list for '+img.filename)
tbhdu.header.add_comment('Generated by PyBDSM version %s'
tbhdu.header.add_comment('Generated by PyBDSF version %s'
% (__version__, ))
freq = "%.5e" % img.frequency
tbhdu.header.add_comment('Reference frequency of the detection ("ch0") image: %s Hz' % freq)
Expand Down Expand Up @@ -454,7 +454,7 @@ def write_kvis_ann(img, filename=None, sort_by='indx',
from . import mylogger
import os

mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Output")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Output")
if filename is None:
filename = img.imagename + '.kvis.ann'
if os.path.exists(filename) and not clobber:
Expand Down Expand Up @@ -488,7 +488,7 @@ def write_star(img, filename=None, sort_by='indx',
from . import mylogger
import os

mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Output")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Output")
if filename is None:
filename = img.imagename + '.star'
if os.path.exists(filename) and not clobber:
Expand Down Expand Up @@ -621,7 +621,7 @@ def make_lsm_str(img, glist, gnames, incl_empty=False):

outstr_list = ["# SAGECAL sky model\n"]
freq = "%.5e" % img.frequency
outstr_list.append('# Generated by PyBDSM version %s\n'
outstr_list.append('# Generated by PyBDSF version %s\n'
% (__version__, ))
outstr_list.append("# Name | RA (hr,min,sec) | DEC (deg,min,sec) | I | Q | U | V | SI | RM | eX | eY | eP | freq0\n\n")
for gindx, g in enumerate(glist[0]):
Expand Down Expand Up @@ -686,7 +686,7 @@ def make_ds9_str(img, glist, gnames, deconvolve=False, objtype='gaul', incl_empt
elif int(img.equinox) == 1950:
equinox = 'fk4'
else:
mylog = mylogger.logging.getLogger("PyBDSM.write_ds9")
mylog = mylogger.logging.getLogger("PyBDSF.write_ds9")
mylog.warning('Equinox of input image is not J2000 or B1950. '
'Regions may not be correct.')
equinox = 'fk5'
Expand Down Expand Up @@ -741,7 +741,7 @@ def make_ascii_str(img, glist, objtype='gaul', format='ascii', incl_empty=False,
outstr_list.append('# Gaussian list for '+img.filename+'\n')
elif objtype == 'srl':
outstr_list.append('# Source list for '+img.filename+'\n')
outstr_list.append('# Generated by PyBDSM version %s\n'
outstr_list.append('# Generated by PyBDSF version %s\n'
% (__version__, ))
outstr_list.append('# Reference frequency of the detection ("ch0") image: %s Hz\n' % freq)
outstr_list.append('# Equinox : %s \n\n' % img.equinox)
Expand Down Expand Up @@ -971,7 +971,7 @@ def list_and_sort_gaussians(img, patch=None, root=None,
# mask file.
if 0 in unique_patch_ids:
from . import mylogger
mylog = mylogger.logging.getLogger("PyBDSM.write_gaul")
mylog = mylogger.logging.getLogger("PyBDSF.write_gaul")
mylog.warning('Some sources fall outside of the regions '
'defined in the mask file. These sources are not '
'included in the output sky model.')
Expand Down
2 changes: 1 addition & 1 deletion bdsf/plotresults.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def plotresults(img, ch0_image=True, rms_image=True, mean_image=True,
numx = 1
numy = int(N.ceil(float(len(images))/float(numx)))
fig = pl.figure(figsize=(max(15, 10.0*float(numy)/float(numx)), 10.0))
fig.canvas.manager.set_window_title('PyBDSM Fit Results for '+ img.filename)
fig.canvas.manager.set_window_title('PyBDSF Fit Results for '+ img.filename)
gray_palette = cm.gray
gray_palette.set_bad('k')

Expand Down
2 changes: 1 addition & 1 deletion bdsf/polarisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Op_polarisation(Op):
Prerequisites: module gaul2srl should be run first."""

def __call__(self, img):
mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Polarisatn")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Polarisatn")
if img.opts.polarisation_do:
mylog.info('Extracting polarisation properties for all sources')
pols = ['I', 'Q', 'U', 'V']
Expand Down
4 changes: 2 additions & 2 deletions bdsf/preprocess.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Module preprocess
Calculates some basic statistics of the image and sets up processing
parameters for PyBDSM.
parameters for PyBDSF.
"""
from __future__ import absolute_import

Expand All @@ -20,7 +20,7 @@ class Op_preprocess(Op):
are blanked in QC ? """

def __call__(self, img):
mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Preprocess")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Preprocess")
bstat = func.bstat
if img.opts.kappa_clip is None:
kappa = -img.pixel_beamarea()
Expand Down
4 changes: 2 additions & 2 deletions bdsf/psf_vary.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Op_psf_vary(Op):
def __call__(self, img):

if img.opts.psf_vary_do:
mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Psf_Vary")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Psf_Vary")
mylogger.userinfo(mylog, '\nEstimating PSF variations')
opts = img.opts
dir = img.basedir + '/misc/'
Expand Down Expand Up @@ -847,7 +847,7 @@ def psf_in_tile(self, image, beam, g_gauls, cdelt, factor, snrcutstack, volrank,
and pass it to stackpsf with a weight for each gaussian, to calculate the average psf per tile.
Should define weights inside a tile to include closure errors """
mylog = mylogger.logging.getLogger("PyBDSM."+img.log+"Psf_Vary")
mylog = mylogger.logging.getLogger("PyBDSF."+img.log+"Psf_Vary")

tile_list, tile_coord, tile_snr = tile_prop
tr_gaul = self.trans_gaul(g_gauls)
Expand Down
8 changes: 4 additions & 4 deletions bdsf/readimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Op_readimage(Op):
Loads image and configures wcslib machinery for it.
"""
def __call__(self, img):
mylog = mylogger.logging.getLogger("PyBDSM." + img.log + "Readimage")
mylog = mylogger.logging.getLogger("PyBDSF." + img.log + "Readimage")

if img.opts.filename == '':
raise RuntimeError('Image file name not specified.')
Expand Down Expand Up @@ -310,7 +310,7 @@ def init_beam(self, img):
"""Initialize beam parameters, and conversion routines
to convert beam to/from pixel coordinates"""
from .const import fwsig
mylog = mylogger.logging.getLogger("PyBDSM.InitBeam")
mylog = mylogger.logging.getLogger("PyBDSF.InitBeam")

hdr = img.header
cdelt1, cdelt2 = img.wcs_obj.acdelt[0:2]
Expand Down Expand Up @@ -402,7 +402,7 @@ def pixel_beamarea():
def init_freq(self, img):
"""Initialize frequency parameters and store them.
Basically, PyBDSM uses two frequency parameters:
Basically, PyBDSF uses two frequency parameters:
img.frequency - the reference frequency in Hz of the ch0 image
img.freq_pars - the crval, crpix, and cdelt values for the
Expand All @@ -419,7 +419,7 @@ def init_freq(self, img):
warnings.filterwarnings("ignore", category=DeprecationWarning)
from pywcs import WCS

mylog = mylogger.logging.getLogger("PyBDSM.InitFreq")
mylog = mylogger.logging.getLogger("PyBDSF.InitFreq")
if img.opts.frequency_sp is not None and img.image_arr.shape[1] > 1:
# If user specifies multiple frequencies, then let
# collapse.py do the initialization
Expand Down
Loading

0 comments on commit 0df0e1a

Please sign in to comment.