Skip to content

Commit

Permalink
HLA-1254: Address issues caught by SonarQube (#1802)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlpstsci authored May 22, 2024
1 parent 1f64115 commit b051bce
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ number of the code change for that issue. These PRs can be viewed at:

3.7.1 (unreleased)
======================
- Addressed bugs caught by SonarQube static code analysis. Interface
changes listed here: Added missing input data parameter to the create_output
calls, Added missing log level to run function, Removed the deprecated
parameter, dao_threshold, from astrometric_utils.py/extract_sources, removed
"ivmlist" parameter from the interface of multiple functions in processInput.py
as it is an output parameter (buildFileListOrig, buildFileList, checkMultipleFiles,
and process_input), and addressed missing parameters in the calls to
get_ci_info and get_ci_from_file.. [#1802]

- Exclude single filter images from the generation of the total detection
image to minimize cosmic ray contamination, unless there are only single
filter images in the visit. [#1797]
Expand Down
1 change: 0 additions & 1 deletion drizzlepac/haputils/align_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,6 @@ def find_alignment_sources(self, output=True, dqname='DQ', crclean=False,
outroot=outroot,
kernel=self.kernel,
segment_threshold=self.threshold[chip],
dao_threshold=self.bkg_rms_mean[chip],
fwhm=self.kernel_fwhm,
**extract_pars)
if crclean and crmap is not None:
Expand Down
9 changes: 1 addition & 8 deletions drizzlepac/haputils/astrometric_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,7 @@ def build_gaussian_kernel(fwhm, npixels):


def extract_sources(img, dqmask=None, fwhm=3.0, kernel=None, photmode=None,
segment_threshold=None, dao_threshold=None,
dao_nsigma=3.0, source_box=7,
segment_threshold=None, dao_nsigma=3.0, source_box=7,
classify=True, centering_mode="starfind", nlargest=None,
outroot=None, plot=False, vmax=None, deblend=False,
log_level=logutil.logging.INFO):
Expand Down Expand Up @@ -988,10 +987,6 @@ def extract_sources(img, dqmask=None, fwhm=3.0, kernel=None, photmode=None,
segment_threshold : ndarray or None
Value from the image which serves as the limit for determining sources.
If None, compute a default value of (background+5*rms(background)).
dao_threshold : float, optional
[Deprecated] This parameter is not used. In fact, it now gets computed
internally using the ``sigma_clipped_bkg()`` function which uses the
``dao_nsigma`` parameter.
dao_nsigma : float
This number gets used to determine the threshold for detection of point
sources. The threshold gets computed using a simple ``mean + dao_nsigma * rms``,
Expand Down Expand Up @@ -1456,7 +1451,6 @@ def generate_source_catalog(image, dqname="DQ", output=False, fwhm=3.0,

bkg_ra, bkg_median, bkg_rms_ra, bkg_rms_median = compute_2d_background(imgarr, box_size, win_size)
threshold = nsigma * bkg_rms_ra
dao_threshold = nsigma * bkg_rms_median

(kernel, kernel_psf), kernel_fwhm = build_auto_kernel(imgarr - bkg_ra, whtarr,
threshold=threshold,
Expand All @@ -1470,7 +1464,6 @@ def generate_source_catalog(image, dqname="DQ", output=False, fwhm=3.0,
outroot=outroot, kernel=kernel,
photmode=photmode,
segment_threshold=threshold,
dao_threshold=dao_threshold,
fwhm=kernel_fwhm, **detector_pars)
del crmap
source_cats[chip] = seg_tab
Expand Down
8 changes: 4 additions & 4 deletions drizzlepac/haputils/ci_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ def get_ci_from_file(drzfile, ci_lookup_file_path, log_level, **kw):
inst, detect, filt = parse_file(drzfile)
return get_ci_info(inst, detect, filt, ci_lookup_file_path, **kw)


if __name__ == '__main__':
ci_lookup_file_path = 'svm_parameters/any'
inst, detect, filt = ('wfc3', 'uvis', 'f606w')
ciap_dict = get_ci_info(inst, detect, filt)
ciap_dict = get_ci_info(inst, detect, filt, ci_lookup_file_path)
log.info("configuration: {}".format(inst, detect, filt))
log.info("eff_wave: {}".format(ciap_dict['eff_wave']))
log.info("ci_lower: {}".format(ciap_dict['ci_lower_limit']))
Expand All @@ -220,7 +220,7 @@ def get_ci_from_file(drzfile, ci_lookup_file_path, log_level, **kw):

drizzled_image = 'hst_12311_03_wfc3_uvis_f275w_drz.fits'
inst, detect, filt = parse_file(drizzled_image)
ciap_dict = get_ci_from_file(drizzled_image)
ciap_dict = get_ci_from_file(drizzled_image, ci_lookup_file_path, logutil.logging.INFO)
log.info("drizzled image: {}".format(drizzled_image))
log.info("configuration: {}".format(inst, detect, filt))
log.info("eff_wave: {}".format(ciap_dict['eff_wave']))
Expand All @@ -231,7 +231,7 @@ def get_ci_from_file(drzfile, ci_lookup_file_path, log_level, **kw):

drizzled_image = 'hst_11969_04_wfpc2_f606w_pc_drz.fits'
inst, detect, filt = parse_file(drizzled_image)
ciap_dict = get_ci_from_file(drizzled_image)
ciap_dict = get_ci_from_file(drizzled_image, ci_lookup_file_path, logutil.logging.INFO)
log.info("drizzled image: {}".format(drizzled_image))
log.info("configuration: {}".format(inst, detect, filt))
log.info("eff_wave: {}".format(ciap_dict['eff_wave']))
Expand Down
10 changes: 5 additions & 5 deletions drizzlepac/haputils/hapcut_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ def mvm_id_filenames(sky_coord, cutout_size, log_level=logutil.logging.INFO):
del acs_query_table
del wfc3_query_table

# Catch the case where no files are found which satisfied the Query
if not query_table:
log.warning("Query for objects within {} of {} returned NO RESULTS!".format(radius, (str_ra, str_dec)))
return query_table

# Compute the limits of the cutout region
deg_cutout_size = cutout_size.to(u.deg)
ra_min = sky_coord.ra.degree - deg_cutout_size.value[0]
Expand All @@ -127,6 +122,11 @@ def mvm_id_filenames(sky_coord, cutout_size, log_level=logutil.logging.INFO):
str_ra = "{:.4f}".format(sky_coord.ra.degree)
str_dec = "{:.4f}".format(sky_coord.dec.degree)

# Catch the case where no files are found which satisfied the Query
if not query_table:
log.warning("Query for objects within {} of {} returned NO RESULTS!".format(radius, (str_ra, str_dec)))
return query_table

# Filter the output as necessary to include only MVM filenames (MVM prefix: hst_skycell).
# Also, filter out images which are not actually in the requested cutout region as the
# archive search had to be done using a radius.
Expand Down
1 change: 0 additions & 1 deletion drizzlepac/haputils/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ def align_to_gaia(

exposure_filenames = []
headerlet_filenames = {}
align_table = None
crclean = []

# If no catalog list has been provided, use the list defined in the configuration file
Expand Down
2 changes: 1 addition & 1 deletion drizzlepac/nicmosData.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,10 @@ def fromcalfile(filename):
hdulist = fileutil.openImage(filename)

if 'TEMPFILE' in hdulist[0].header:
tddfile = hdulist[0].header['TEMPFILE']
if tddfile == 'N/A':
return None
else:
tddfile = hdulist[0].header['TEMPFILE']
tddhdulist = fileutil.openImage(tddfile)
return darkobject(tddhdulist)
else:
Expand Down
10 changes: 5 additions & 5 deletions drizzlepac/processInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,15 @@ def processFilenames(input=None,output=None,infilesOnly=False):
return filelist, output, ivmlist, oldasndict


def process_input(input, output=None, ivmlist=None, updatewcs=True,
def process_input(input, output=None, updatewcs=True,
prodonly=False, wcskey=None, **workinplace):
"""
Create the full input list of filenames after verifying and converting
files as needed.
"""

newfilelist, ivmlist, output, oldasndict, origflist = buildFileListOrig(
input, output=output, ivmlist=ivmlist, wcskey=wcskey,
input, output=output, wcskey=wcskey,
updatewcs=updatewcs, **workinplace)

if not newfilelist:
Expand Down Expand Up @@ -655,19 +655,19 @@ def _process_input_wcs_single(fname, wcskey, updatewcs):
wcscorr.init_wcscorr(fname)


def buildFileList(input, output=None, ivmlist=None,
def buildFileList(input, output=None,
wcskey=None, updatewcs=True, **workinplace):
"""
Builds a file list which has undergone various instrument-specific
checks for input to MultiDrizzle, including splitting STIS associations.
"""
newfilelist, ivmlist, output, oldasndict, filelist = \
buildFileListOrig(input=input, output=output, ivmlist=ivmlist,
buildFileListOrig(input=input, output=output,
wcskey=wcskey, updatewcs=updatewcs, **workinplace)
return newfilelist, ivmlist, output, oldasndict


def buildFileListOrig(input, output=None, ivmlist=None,
def buildFileListOrig(input, output=None,
wcskey=None, updatewcs=True, **workinplace):
"""
Builds a file list which has undergone various instrument-specific
Expand Down

0 comments on commit b051bce

Please sign in to comment.