From 132ffb1e1c1fc0e3d8a180aeaee74add38ad93c2 Mon Sep 17 00:00:00 2001 From: Steve Goldman <32876747+s-goldman@users.noreply.github.com> Date: Wed, 3 Apr 2024 09:39:03 -0400 Subject: [PATCH] HLA-1209 Bug fix that allows for user inputs in astrodrizzle with mdriztab=True (#1774) --- CHANGELOG.rst | 2 ++ drizzlepac/astrodrizzle.help | 18 ++++++++++++------ drizzlepac/astrodrizzle.py | 25 ++++++++++++------------- drizzlepac/processInput.py | 16 +++++++++++----- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e4fa82909..1024d371d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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] diff --git a/drizzlepac/astrodrizzle.help b/drizzlepac/astrodrizzle.help index a751637bf..0e7fe90dc 100644 --- a/drizzlepac/astrodrizzle.help +++ b/drizzlepac/astrodrizzle.help @@ -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. @@ -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. @@ -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. diff --git a/drizzlepac/astrodrizzle.py b/drizzlepac/astrodrizzle.py index 539121f78..969fe60d4 100644 --- a/drizzlepac/astrodrizzle.py +++ b/drizzlepac/astrodrizzle.py @@ -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: @@ -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 @@ -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" @@ -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) @@ -239,7 +239,6 @@ def run(configobj, wcsmap=None): .format(__version__, util._ptime()[0])) print("", flush=True) - except Exception: clean = False print(textutil.textbox( diff --git a/drizzlepac/processInput.py b/drizzlepac/processInput.py index f54539bed..49e76d13b 100644 --- a/drizzlepac/processInput.py +++ b/drizzlepac/processInput.py @@ -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 @@ -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 ----- @@ -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.