Edge detection (ED) is both a set of Python scripts and a process that allows you to:
This is a the typical data set that ED can handle:
Applying the Sobel operator we get the footprint edges in a binary image.
These thin 1-pixel edges are the input to our edge finding algorithm. Some of these edges do not look continuous but it is a ds9 effect. Zooming in, you could see an unbroken edge.
ED installation
The Edge Detection functions run in any system where AstroData can run. At this time is limited to Linux machines running RedHat, Fedora, Ubuntu and Mac OS X.
The software is installed in the gemini_python gempy directory which need to be imported before running ED.
A tar file is available with the ED software and a setup.py file is provided to install it in your system. For example, if you untar the ED tar file in the current directory then:
python setup.py install --home=/tmp
# Add to PYTHONPATH the new pathname where the ED modules are:
setenv PYTHONPATH ${PYTHONPATH}:/tmp/lib/python.
Getting Help
If you experience problems installing or running ED please contact the Gemini Helpdesk.
For internal Gemini staff please contact: Nelson Zarate at nzarate@gemini.edu.
Quick Example: Getting cutouts from each footprint in an image
Start your favorite Python shell
importing modules
from astrodata import AstroData
# The module 'extract.py' should be in a directory accessible via
# the environment variable PYTHONPATH.
#
from gempy.adlibrary import extract as extr
Use AstroData to open a FITS file
# Open an F2 Flat exposure of a Multi-object footprint mask.
ad = AstroData('fS20120104S0070.fits')
Find footprints
# Find edges, pairs them into Footprint objects and create a
# binary table 'TRACEFP' with information about each footprint's edges,
# appending the table to the input AstroData object. The 'debug' flag will
# set the function to display the input image in ds9 and plot
# the edges in a 'matplotlib' window.
#
adout = extr.trace_footprints(ad,debug=True)
Use the TRACEFP table in the adout object to cut the footprints on a target MOS spectra image.
ad = AstroData('myobjects.fits')
# Add the TRACEFP extension to the target spectrum's AD object.
ad.append(adout['TRACEFP'])
Get footprint cutouts.
# A rectangular cutout is produced for each footprint with information
# in the TRACEFP table. Only one footprint per cutout and all pixels
# between the rectangle boundaries and the footprint's edges are set to zero.
# An AstroData object is returned with as many IMAGE extensions as
# there are footprints. The 'debug' flag will set the function to display
# each cutout in ds9 and a footprint drawing in a 'matplotlib' window.
#
# Notice that we use the target spectrum's AD object containing the
# TRACEFP extension.
ad_cuts = extr.cut_footprints(ad, debug=True)
Saving all into a FITS file.
ad_cuts.write('mycuts.fits')
The main goal when locating edges is to find a list of (x,y) pixel coordinates belonging to one edge along the footprint boundary. These are the basic steps to achieve this.
- The GMOS, GNIRS and F2 Flat images should have a good signal to noise ratio. If multiple Flats are available then combining several individual exposures can reduce noise and improve signal to noise. In general a S/N of 3.0 or better will guarantee that footprint edges are found.
- The footprints separation is crucial to determine a well defined edge showing no breakage along the dispersion axis. If two footprints are as close as one pixel, chances are that the algorithm will fail to find the edges.
- For F2 data, the prefiltering is a one sigma standard deviation of the Gauss filter.
- For GNIRS data, the brightest footprints (see picture) are clipped to normalized the orders.
- GMOS, footprints are well illuminated and uniform with no need of filtering.
The trace_footprints and cut_footprints are user level functions to obtain footprint edges information and footprint cutouts.
This user level function finds the footprint edges of spectroscopic flats creating a BINTABLE extension with the footprint parameters information and appends it to the input AstroData object.
USAGE
adout = trace_footprints(ad, function='polynomial', order=2, trace_threshold=1., debug=False)
Parameters
----------
ad: Input AstroData object.
function: Name of the fitting function to use when fitting edges. The default
value is 'polynomial'. Other posible values are: 'legendre', 'chebyshev'
order: Order of the polynomial. Default is 2.
trace_threshold:
Threshold in units of sigma to applied to the filtered image.
Default value is one.
debug: If True, footprint edges plot will be displayed and the input image will be
displayed on ds9 showing the footprint edges.
Output
------
adout: Output AstroData objects which is the input AD object with
the 'TRACEFP' binary table appended.
User level function to read from the AD objects the ‘TRACEFP’ extension having footprints information to cut footprints. It returns an AD object with a list of IMAGE extensions; each one containing a footprint cut.
USAGE
adout = cut_footprints(ad,debug=False)
Parameters
----------
ad: Input AstroData object containing the binary TABLE extension named 'TRACEFP'.
debug: If True, footprint edges plot inside a rectangle will be displayed and the
rectangle is also displayed as an image in the ds9 display.
Output
------
adout: Output AstroData object with as many image extensions as
records in the input 'TRACEFP' table.
NOTE
----
If the adinput is a target spectra to be cut, then the caller should
append the already created TRACEFP table to this target AD object.