Skip to content

Commit

Permalink
HLA-1209 Bug fix that allows for user inputs in astrodrizzle with mdr…
Browse files Browse the repository at this point in the history
…iztab=True (#1774)
  • Loading branch information
s-goldman authored Apr 3, 2024
1 parent 5a868ad commit 132ffb1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ number of the code change for that issue. These PRs can be viewed at:
source catalog before the corresponding bad segments are removed from the
segmentation image. [#1771]

- Bug fix for mdriztab=True option in Astrodrizzle previously overwriting user inputs. [#1774]

- Reverted PR #1222 allowing pixels to be filled with available data where WHT=0. [#1767]

- Improved calculation of S_REGION using dialation and erosion. [#1762]
Expand Down
18 changes: 12 additions & 6 deletions drizzlepac/astrodrizzle.help
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ input : str or list of str (Default = ``'*flt.fits'``)
will automatically generate the ``IVM`` files itself for each input
exposure.

mdriztab : bool (Default = False)
This button will immediately update the parameter values in the ``TEAL``
GUI based on those provided by the ``MDRIZTAB`` reference table referenced
in the first input image. This requires that the ``MDRIZTAB`` reference
file be available locally.

editpars : bool (Default = False)
A parameter that allows user to edit input parameters by hand in the GUI.
``True`` to use the GUI to edit parameters.
Expand All @@ -39,6 +45,12 @@ configobj : ConfigObjPars, ConfigObj, dict (Default = None)
parameters not provided explicitly will be initialized with their
default values as described in the "Other Parameters" section.

wcsmap : wcs_functions.WCSMap, None (Default = None)
An instance of ``wcs_functions.WCSMap`` which can be used to override the
default ``WCS`` mapping for the input images. This parameter is used to
specify the mapping between the input images and the output frame. If
``None`` is provided, then the default ``WCS`` mapping will be used.

input_dict : dict, optional
An optional list of parameters specified by the user, which can also
be used to override the defaults.
Expand Down Expand Up @@ -73,12 +85,6 @@ output : str (Default = '')
wild-card specification is given as input, then a rootname of ``'final'``
will be used for the output file name.

mdriztab : bool (Default = False)
This button will immediately update the parameter values in the ``TEAL``
GUI based on those provided by the ``MDRIZTAB`` reference table referenced
in the first input image. This requires that the ``MDRIZTAB`` reference
file be available locally.

runfile : str (Default = 'astrodrizzle.log')
This log file will contain all the output messages generated during
processing, including full details of any errors/exceptions.
Expand Down
25 changes: 12 additions & 13 deletions drizzlepac/astrodrizzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,16 @@ def AstroDrizzle(input=None, mdriztab=False, editpars=False, configobj=None,
print("Problem with input parameters. Quitting...", file=sys.stderr)
return

if not configObj:
return

# add flag to configObj to indicate whether or not to use mdriztab
configObj['mdriztab'] = mdriztab
# If 'editpars' was set to True, util.getDefaultConfigObj() will have
# already called 'run()'.
if not editpars:
run(configObj, wcsmap=wcsmap)

run(configObj, wcsmap=wcsmap, input_dict=input_dict)

##############################
# Interfaces used by TEAL #
##############################
@util.with_logging
def run(configobj, wcsmap=None):
def run(configobj, wcsmap=None, input_dict=None):
"""
Initial example by Nadia ran MD with configobj EPAR using:
It can be run in one of two ways:
Expand All @@ -139,6 +135,8 @@ def run(configobj, wcsmap=None):
teal.teal('astrodrizzle')
The example config files are in drizzlepac/pars
input_dict is a dictionary of user-specified parameters
"""
# turn on logging, redirecting stdout/stderr messages to a log file
Expand Down Expand Up @@ -185,8 +183,10 @@ def run(configobj, wcsmap=None):
# based on input paramters
imgObjList = None
procSteps.addStep('Initialization')
imgObjList, outwcs = processInput.setCommonInput(configobj)
procSteps.endStep('Initialization')
imgObjList, outwcs = processInput.setCommonInput(
configobj, overwrite_dict=input_dict
)
procSteps.endStep("Initialization")

if imgObjList is None or not imgObjList:
errmsg = "No valid images found for processing!\n"
Expand All @@ -210,14 +210,14 @@ def run(configobj, wcsmap=None):
# subtract the sky
sky.subtractSky(imgObjList, configobj, procSteps=procSteps)

# _dbg_dump_virtual_outputs(imgObjList)
# _dbg_dump_virtual_outputs(imgObjList)

# drizzle to separate images
adrizzle.drizSeparate(imgObjList, outwcs, configobj, wcsmap=wcsmap,
logfile=logfile,
procSteps=procSteps)

# _dbg_dump_virtual_outputs(imgObjList)
# _dbg_dump_virtual_outputs(imgObjList)

# create the median images from the driz sep images
createMedian.createMedian(imgObjList, configobj, procSteps=procSteps)
Expand All @@ -239,7 +239,6 @@ def run(configobj, wcsmap=None):
.format(__version__, util._ptime()[0]))
print("", flush=True)


except Exception:
clean = False
print(textutil.textbox(
Expand Down
16 changes: 11 additions & 5 deletions drizzlepac/processInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
import multiprocessing


def setCommonInput(configObj, createOutwcs=True):
def setCommonInput(configObj, createOutwcs=True, overwrite_dict={}):
"""
The common interface interpreter for MultiDrizzle tasks which not only runs
'process_input()' but 'createImageObject()' and 'defineOutput()' as well to
Expand All @@ -70,10 +70,11 @@ def setCommonInput(configObj, createOutwcs=True):
----------
configObj : object
configObj instance or simple dictionary of input parameters
imageObjectList : list of imageObject objects
list of imageObject instances, 1 for each input exposure
outwcs : object
imageObject instance defining the final output frame
createOutwcs : bool
whether of not to update the output WCS infomation
overwrite_dict: dict
dictionary of user input paramters to overwrite in configObj
(needed in particular for using mdriztab=True option)
Notes
-----
Expand Down Expand Up @@ -129,6 +130,11 @@ def setCommonInput(configObj, createOutwcs=True):

# Update configObj with values from mpars
cfgpars.mergeConfigObj(configObj, mdriztab_dict)

if overwrite_dict:
# user inputs are removed in above line, we need to add them back
# overwrite values in configObj with those from the input_dict
cfgpars.mergeConfigObj(configObj, overwrite_dict)

# Convert interpreted list of input files from process_input into a list
# of imageObject instances for use by the MultiDrizzle tasks.
Expand Down

0 comments on commit 132ffb1

Please sign in to comment.