From 8cbd33bcaf77e2e3893b868cc86cd4fe548dac3d Mon Sep 17 00:00:00 2001 From: a-griffiths Date: Thu, 20 Sep 2018 13:05:16 +0100 Subject: [PATCH 1/3] Update .param_format.py~, AutoSpec, and 4 more files... --- .param_format.py~ | 62 ++++++++++++++++++++++++++++++++++++++++++++++ AutoSpec | 21 +++++++++------- catalog_format.txt | 4 +-- param_format.py | 6 ++--- test/catalog.txt | 4 +-- test/param.py | 12 ++++----- 6 files changed, 87 insertions(+), 22 deletions(-) create mode 100755 .param_format.py~ diff --git a/.param_format.py~ b/.param_format.py~ new file mode 100755 index 0000000..6e25aec --- /dev/null +++ b/.param_format.py~ @@ -0,0 +1,62 @@ +# Default configuration file for AutoSpec v 1.1.2 +# DATE: 20-09-2018 + +# ----------- Operating Mode ------------------------------------------------------------------------------------------------------------------------------------------------------------- + +MODE = 'param' # 'param' or 'cat' to use configuration or catalogue file respectively for extraction mode (string). + +# ----------- Reference Spectra ----------------------------------------------------------------------------------------------------------------------------------------------------------- + +REF = '' # reference spectrum to use for cross correlation, must also be in image (IMG), aperture (APER) parameters or '' to use white light image. + +# ----------- Required Files -------------------------------------------------------------------------------------------------------------------------------------------------------------- + +DATACUBE = '' # name of datacube file (string). +CATALOG = '' # name of catalog file (string). + +# ----------- Datacube Extension: Use if datacube extensions are not specified in fits headers -------------------------------------------------------------------------------------------- + +DATA_EXT = () # The number/name of the data (int or str), or data and variance extensions (int, int or str, str), () if none. + +# ----------- Spectral Extractions -------------------------------------------------------------------------------------------------------------------------------------------------------- + +APER = '' # aperture sizes (in arcseconds) for spectrum extraction (float or array or floats). +IMG = '' # name of additional image files for weighted spectra and segmentation extractions (string or comma seperated list of strings), '' if none. + +# ----------- Object Masks ---------------------------------------------------------------------------------------------------------------------------------------------------------------- + +USE_WHITE = True # if AutoSpec should also use the MUSE_WHITE segmentation map to create masks (True or False). +OBJ_MASK = 'INTER' # object mask from union (UNION) or intersection (INTER) of segmentation maps (string). +SEG = '' # name of additional segmentation maps files to be used (string or comma seperated list of strings). + +# ----------- Output Formatting ----------------------------------------------------------------------------------------------------------------------------------------------------------- + +OUTPUT = 'output' # name of output directory (string). +PRE_OUT = 'Source_' # string to prepend to output data files (string), '' if none. + +# ----------- Extraction Parameters ------------------------------------------------------------------------------------------------------------------------------------------------------- + +SIZE = 5 # sub image/cube extraction size in arcseconds (float). +XCOR = True # perform cross correlation (True or False). +CONT_SUB = True # preform continuum subtraction, only runs if XCOR is True (True or False). +CONT_POLY = 5 # degree of polynomial for contiuum fitting (integer). +SKY_SUB = True # Perform sky subtraction when extracting spectra (True or False). +PLOTS = True # output plots (True or False). + +# ----------- Outputs --------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +OUT_SUB = False # output extracted source subcubes (True or False), these make up the bulk of the output filesize. +OUT_IMG = True # output extracted source images (True or False). +OUT_SEG = True # output segmentation maps (True or False). +OUT_MASK = True # output object and sky masks (True or False). +OUT_XCOR = True # output cross-correlation map (True or False). +OUT_SPEC = True # output additional spectra (True) or final only (False). + +# ----------- MISCELLANEOUS --------------------------------------------------------------------------------------------------------------------------------------------------------------- + +CMAP = 'viridis' # colour map to use for image plots. +ORIG_FROM = '' # name of the detector software which creates this object (string). +ORIG_FROMV = '' # version of the detector software which creates this object (string). +ORIG_CUBE = '' # name of the FITS data cube from which this object has been extracted (string). +ORIGN_CUBEV = '' # version of the FITS data cube (string). +WARNINGS = False # turn warnings on (True) or off (False). diff --git a/AutoSpec b/AutoSpec index 9888502..3e86089 100755 --- a/AutoSpec +++ b/AutoSpec @@ -3,8 +3,8 @@ """ AutoSpec: Automated Datacube Spectrum Extractor @author: Alex Griffiths -v 1.1.0 -05-09-2018 +v 1.1.2 +20-09-2018 """ # Import dependencies. from __future__ import absolute_import, division, print_function @@ -59,16 +59,16 @@ def create_source(ID, ra, dec, size, ref): if ref == '': ext_mode = 'IMG' refspec = 'MUSE_WHITE' - elif ref not in imgs.keys(): - print('Reference not in images or apertures, using white light.') + elif ref.replace('.', '').isdigit() is False: ext_mode = 'IMG' - refspec = 'MUSE_WHITE' + refspec = ref elif ref.replace('.', '').isdigit() is True: ext_mode = 'APER' refspec = 'MUSE_APER_%.1f' % float(ref) - elif ref.replace('.', '').isdigit() is False: + elif ref not in imgs.keys(): + print('Reference not in images or apertures, using white light.') ext_mode = 'IMG' - refspec = ref + refspec = 'MUSE_WHITE' # This creates the source object (see MPDAF for more details). s = Source.from_data(ID=ID, ra=ra, dec=dec, extras=extra, @@ -108,10 +108,11 @@ def create_source(ID, ra, dec, size, ref): # Extract all spectra set by user. tags = [i for i in s.images.keys() if 'SEG_' not in i and 'MASK_' not in i] + aps = params.APER if isinstance(params.APER, tuple) else [params.APER] s.extract_spectra(s.cubes['MUSE'], obj_mask=mask, sky_mask='MASK_SKY', skysub=params.SKY_SUB, - tags_to_try=tags, apertures=params.APER) + tags_to_try=tags, apertures=aps) # Set up naming convention based on if the user has sky-subtraction set. if params.SKY_SUB is True: @@ -186,8 +187,10 @@ def create_masks(src): src.add_seg_images(del_sex=False) seg = [i for i in src.images.keys() if 'SEG_' in i] # Do not use the white light image not set. - if params.USE_WHITE is False: + if params.USE_IMGS is False: seg.remove('SEG_MUSE_WHITE') + for key in imgs: + seg.remove('SEG_'+key) src.find_sky_mask(seg) src.find_union_mask(seg) # Check if any maps are empty before creating intersection mask. diff --git a/catalog_format.txt b/catalog_format.txt index a1868ab..d77d36e 100755 --- a/catalog_format.txt +++ b/catalog_format.txt @@ -1,5 +1,5 @@ -# Example catalog file for AutoSpec v 1.1.0 -# DATE: 05-09-2018 +# Example catalog file for AutoSpec v 1.1.2 +# DATE: 20-09-2018 # Parameter mode catalog format [id ra dec]. # diff --git a/param_format.py b/param_format.py index 7e0caef..66fbac4 100755 --- a/param_format.py +++ b/param_format.py @@ -1,5 +1,5 @@ -# Default configuration file for AutoSpec v 1.1.0 -# DATE: 05-09-2018 +# Default configuration file for AutoSpec v 1.1.2 +# DATE: 20-09-2018 # ----------- Operating Mode ------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -25,7 +25,7 @@ # ----------- Object Masks ---------------------------------------------------------------------------------------------------------------------------------------------------------------- -USE_WHITE = True # if AutoSpec should also use the MUSE_WHITE segmentation map to create masks (True or False). +USE_IMGS = True # if AutoSpec should also use the segmentation maps created from the images in IMG parameter to create final masks (True or False). OBJ_MASK = 'INTER' # object mask from union (UNION) or intersection (INTER) of segmentation maps (string). SEG = '' # name of additional segmentation maps files to be used (string or comma seperated list of strings). diff --git a/test/catalog.txt b/test/catalog.txt index d0a1322..89d9108 100755 --- a/test/catalog.txt +++ b/test/catalog.txt @@ -1,5 +1,5 @@ -# Example catalog file for AutoSpec v 1.1.0 -# DATE: 05-09-2018 +# Example catalog file for AutoSpec v 1.1.2 +# DATE: 20-09-2018 # Parameter mode catalog format [id ra dec]. # diff --git a/test/param.py b/test/param.py index 942ba0c..c4ca176 100755 --- a/test/param.py +++ b/test/param.py @@ -1,5 +1,5 @@ -# Default configuration file for AutoSpec v 1.1.0 -# DATE: 05-09-2018 +# Default configuration file for AutoSpec v 1.1.2 +# DATE: 20-09-2018 # ----------- Operating Mode ------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -20,14 +20,14 @@ # ----------- Spectral Extractions -------------------------------------------------------------------------------------------------------------------------------------------------------- -APER = 1.0, 2.0 # aperture sizes (in arcseconds) for spectrum extraction (float or array or floats). -IMG = 'g-band.fits', 'r-band.fits' # name of additional image files for weighted spectra and segmentation extractions (string or comma seperated list of strings), '' if none. +APER = 2.0 # aperture sizes (in arcseconds) for spectrum extraction (float or array or floats). +IMG = 'g-band.fits','r-band.fits' # name of additional image files for weighted spectra and segmentation extractions (string or comma seperated list of strings), '' if none. # ----------- Object Masks ---------------------------------------------------------------------------------------------------------------------------------------------------------------- -USE_WHITE = True # if AutoSpec should also use the MUSE_WHITE segmentation map to create masks (True or False). +USE_IMGS = True # if AutoSpec should also use the segmentation maps created from the images in IMG parameter to create final masks (True or False). OBJ_MASK = 'INTER' # object mask from union (UNION) or intersection (INTER) of segmentation maps (string). -SEG = 'g-seg.fits', 'r-seg.fits' # name of additional segmentation maps files to be used (string or comma seperated list of strings). +SEG = 'g-seg.fits' # name of additional segmentation maps files to be used (string or comma seperated list of strings). # ----------- Output Formatting ----------------------------------------------------------------------------------------------------------------------------------------------------------- From 45aed38b6fe4124233990bcf73e3c041b9124b3e Mon Sep 17 00:00:00 2001 From: Alex Griffiths Date: Thu, 20 Sep 2018 13:06:26 +0100 Subject: [PATCH 2/3] Delete .param_format.py~ --- .param_format.py~ | 62 ----------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100755 .param_format.py~ diff --git a/.param_format.py~ b/.param_format.py~ deleted file mode 100755 index 6e25aec..0000000 --- a/.param_format.py~ +++ /dev/null @@ -1,62 +0,0 @@ -# Default configuration file for AutoSpec v 1.1.2 -# DATE: 20-09-2018 - -# ----------- Operating Mode ------------------------------------------------------------------------------------------------------------------------------------------------------------- - -MODE = 'param' # 'param' or 'cat' to use configuration or catalogue file respectively for extraction mode (string). - -# ----------- Reference Spectra ----------------------------------------------------------------------------------------------------------------------------------------------------------- - -REF = '' # reference spectrum to use for cross correlation, must also be in image (IMG), aperture (APER) parameters or '' to use white light image. - -# ----------- Required Files -------------------------------------------------------------------------------------------------------------------------------------------------------------- - -DATACUBE = '' # name of datacube file (string). -CATALOG = '' # name of catalog file (string). - -# ----------- Datacube Extension: Use if datacube extensions are not specified in fits headers -------------------------------------------------------------------------------------------- - -DATA_EXT = () # The number/name of the data (int or str), or data and variance extensions (int, int or str, str), () if none. - -# ----------- Spectral Extractions -------------------------------------------------------------------------------------------------------------------------------------------------------- - -APER = '' # aperture sizes (in arcseconds) for spectrum extraction (float or array or floats). -IMG = '' # name of additional image files for weighted spectra and segmentation extractions (string or comma seperated list of strings), '' if none. - -# ----------- Object Masks ---------------------------------------------------------------------------------------------------------------------------------------------------------------- - -USE_WHITE = True # if AutoSpec should also use the MUSE_WHITE segmentation map to create masks (True or False). -OBJ_MASK = 'INTER' # object mask from union (UNION) or intersection (INTER) of segmentation maps (string). -SEG = '' # name of additional segmentation maps files to be used (string or comma seperated list of strings). - -# ----------- Output Formatting ----------------------------------------------------------------------------------------------------------------------------------------------------------- - -OUTPUT = 'output' # name of output directory (string). -PRE_OUT = 'Source_' # string to prepend to output data files (string), '' if none. - -# ----------- Extraction Parameters ------------------------------------------------------------------------------------------------------------------------------------------------------- - -SIZE = 5 # sub image/cube extraction size in arcseconds (float). -XCOR = True # perform cross correlation (True or False). -CONT_SUB = True # preform continuum subtraction, only runs if XCOR is True (True or False). -CONT_POLY = 5 # degree of polynomial for contiuum fitting (integer). -SKY_SUB = True # Perform sky subtraction when extracting spectra (True or False). -PLOTS = True # output plots (True or False). - -# ----------- Outputs --------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -OUT_SUB = False # output extracted source subcubes (True or False), these make up the bulk of the output filesize. -OUT_IMG = True # output extracted source images (True or False). -OUT_SEG = True # output segmentation maps (True or False). -OUT_MASK = True # output object and sky masks (True or False). -OUT_XCOR = True # output cross-correlation map (True or False). -OUT_SPEC = True # output additional spectra (True) or final only (False). - -# ----------- MISCELLANEOUS --------------------------------------------------------------------------------------------------------------------------------------------------------------- - -CMAP = 'viridis' # colour map to use for image plots. -ORIG_FROM = '' # name of the detector software which creates this object (string). -ORIG_FROMV = '' # version of the detector software which creates this object (string). -ORIG_CUBE = '' # name of the FITS data cube from which this object has been extracted (string). -ORIGN_CUBEV = '' # version of the FITS data cube (string). -WARNINGS = False # turn warnings on (True) or off (False). From fbbdffde5fd9d2aadee79899dfde4474dfd045a8 Mon Sep 17 00:00:00 2001 From: Alex Griffiths Date: Thu, 20 Sep 2018 14:39:00 +0100 Subject: [PATCH 3/3] Updates for v1.1.2 --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 63497c2..5db7e3f 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ The parameter file provides easy user modification to AutoSpec run modes. Each p **IMG:** list of additional image file names. AutoSpec will used each of the images to produce weighted spectra and derived object and sky masks. This is either a single file name as a string ('g-band.fits') or a list of file names ('g-band.fits', 'r-band.fits'). -**USE_WHITE:** tells AutoSpec if you would like to use the white light image and segmentation maps when deriving the object and sky masks. +**USE_IMGS:** tells AutoSpec if you would like to use your additional images when deriving the object and sky masks. This is best set to false if using a pre-defined segmentation map but want to output spectra weighted by images. If you want AutoSpec to calculate segmentation maps for you from the images then use True here. **OBJ_MASK:** here we define if you want to use the intersection or the union of the individual segmentation maps to produce an object mask in order to build the initial spectrum. The intersection mask only selects areas where the object overlaps in the combined segmentation maps, whereas union uses the combination. If you choose intersection and it is found to be empty, the code defaults to using the union mask in order to successfully extract a spectrum. @@ -229,6 +229,15 @@ AutoSpec is licenced under a [BSD 3-Clause License](LICENSE.md) ## Changelog +**v.1.1.2:** September 20, 2018 + +* Small fixes over 1.1.1 where apertures were not extracting correctly. +* Changed USE_WHITE parameter to USE_IMGS parameter for users with existing segmentation maps. + +**v.1.1.1:** September 7, 2018 + +* Small fix over 1.1.0 where images were not importing properly. + **v.1.1.0:** September 5, 2018 * Tidied up code and simplified parameter file.