Reference/API

GALEX

data_buttons.galex.convert_to_jy(hdu_in, galex_filter, hdu_out=None)[source]

Convert from GALEX counts/s to Jy/pixel.

GALEX maps are provided in units of counts/s. These can be converted to more helpful units via the conversion factors given at https://asd.gsfc.nasa.gov/archive/galex/FAQ/counts_background.html.

Parameters:
  • hdu_in (str or astropy.io.fits.PrimaryHDU) – File name of GALEX .fits file, or an Astropy PrimaryHDU instance (i.e. the result of fits.open(file)[0]).
  • galex_filter (str) – Either ‘NUV’ or ‘FUV’.
  • hdu_out (str, optional) – If not None, will save the converted HDU out with this filename. Defaults to None.
Returns:

The HDU in units of Jy/pix.

Return type:

astropy.io.fits.PrimaryHDU

data_buttons.galex.galex_button(galaxies, filters='both', radius=None, filepath=None, download_data=True, create_mosaic=True, jy_conversion=True, verbose=False)[source]

Create a GALEX mosaic, given a galaxy name.

Using a galaxy name and radius, queries around that object, downloads available GALEX data and mosaics into a final product.

Because GALEX images are in counts/s and the integrations may be different lengths, we convert back to a raw count, add the frames and convert back to counts/s at the end. This effectively weights the frame by exposure time.

Parameters:
  • galaxies (str or list) – Names of galaxies to create mosaics for. Resolved by NED.
  • filters (str, optional) – One of ‘FUV’, ‘NUV’, or ‘both’. Selects which GALEX filters to create a mosaic for. Defaults to ‘both’.
  • radius (astropy.units.Quantity, optional) – Radius around the galaxy to search for observations. Defaults to None, where it will query Ned to get size.
  • filepath (str, optional) – Path to save the working and output files to. If not specified, saves to current working directory.
  • download_data (bool, optional) – If True, will download data from MAST. Defaults to True.
  • create_mosaic (bool, optional) – Switching this to True will mosaic data as appropriate. Defaults to True.
  • jy_conversion (bool, optional) – Convert the mosaicked file from raw units to Jy/pix. Defaults to True.
  • verbose (bool, optional) – Print out messages during the process. Useful mainly for debugging purposes or large images. Defaults to False.

SDSS

data_buttons.sdss.convert_to_jy(hdu_in, sdss_filter, hdu_out=None)[source]

Convert from SDSS nanomaggies to Jy/pixel.

SDSS maps are provided in convenience units of ‘nanomaggies’. In general, 1 nanomaggy is 3.631 x 10-6Jy, but there are are some offsets for the u and z band. This is detailed at http://www.sdss3.org/dr8/algorithms/magnitudes.php.

Parameters:
  • hdu_in (str or astropy.io.fits.PrimaryHDU) – File name of SDSS .fits file, or an Astropy PrimaryHDU instance (i.e. the result of fits.open(file)[0]).
  • sdss_filter (str) – Either ‘u’, ‘g’, ‘r’, ‘i’, or ‘z’.
  • hdu_out (str, optional) – If not None, will save the converted HDU out with this filename. Defaults to None.
Returns:

The HDU in units of Jy/pix.

Return type:

astropy.io.fits.PrimaryHDU

data_buttons.sdss.sdss_button(galaxies, filters='all', radius=None, filepath=None, download_data=True, create_mosaic=True, jy_conversion=True, verbose=False, **kwargs)[source]

Create an SDSS mosaic, given a galaxy name.

Using a galaxy name and radius, queries around that object, downloads available SDSS data and mosaics into a final product.

Parameters:
  • galaxies (str or list) – Names of galaxies to create mosaics for. Resolved by NED.
  • filters (str or list, optional) – Any combination of ‘u’, ‘g’, ‘r’, ‘i’, or ‘z’. If you want everything, select ‘all’. Defaults to ‘all’.
  • radius (astropy.units.Quantity, optional) – Radius around the galaxy to search for observations. Defaults to None, where it will query Ned to get size.
  • filepath (str, optional) – Path to save the working and output files to. If not specified, saves to current working directory.
  • download_data (bool, optional) – If True, will download data using MontagePy. Defaults to True.
  • create_mosaic (bool, optional) – Switching this to True will mosaic data as appropriate. Defaults to True.
  • jy_conversion (bool, optional) – Convert the mosaicked file from raw units to Jy/pix. Defaults to True.
  • verbose (bool, optional) – Print out messages during the process. Useful mainly for debugging purposes or large images. Defaults to False.

2MASS

data_buttons.two_mass.convert_to_jy(hdu_in, two_mass_filter, hdu_out=None)[source]

Convert from Vega magnitudes to Jy/pixel.

2MASS maps are provided in convenience units of data numbers (DN). During the mosaicking process, these are converted to Vega mags since the magnitude zero point varies between frames. The constants for converting magnitudes to Jy are given at https://old.ipac.caltech.edu/2mass/releases/allsky/faq.html#jansky.

Parameters:
  • hdu_in (str or astropy.io.fits.PrimaryHDU) – File name of 2MASS .fits file, or an Astropy PrimaryHDU instance (i.e. the result of fits.open(file)[0]).
  • two_mass_filter (str) – Either ‘J’, ‘H’, or ‘K’.
  • hdu_out (str, optional) – If not None, will save the converted HDU out with this filename. Defaults to None.
Returns:

The HDU in units of Jy/pix.

Return type:

astropy.io.fits.PrimaryHDU

data_buttons.two_mass.two_mass_button(galaxies, filters='all', radius=None, filepath=None, download_data=True, create_mosaic=True, jy_conversion=True, verbose=False, **kwargs)[source]

Create a 2MASS mosaic, given a galaxy name.

Using a galaxy name and radius, queries around that object, downloads available 2MASS data and mosaics into a final product.

Parameters:
  • galaxies (str or list) – Names of galaxies to create mosaics for. Resolved by NED.
  • filters (str or list, optional) – Any combination of ‘J’, ‘H’, and ‘K’. If you want everything, select ‘all’. Defaults to ‘all’.
  • radius (astropy.units.Quantity, optional) – Radius around the galaxy to search for observations. Defaults to None, where it will query Ned to get size.
  • filepath (str, optional) – Path to save the working and output files to. If not specified, saves to current working directory.
  • download_data (bool, optional) – If True, will download data using MontagePy. Defaults to True.
  • create_mosaic (bool, optional) – Switching this to True will mosaic data as appropriate. Defaults to True.
  • jy_conversion (bool, optional) – Convert the mosaicked file from raw units to Jy/pix. Defaults to True.
  • verbose (bool, optional) – Print out messages during the process. Useful mainly for debugging purposes or large images. Defaults to False.

WISE

data_buttons.wise.convert_to_jy(hdu_in, wise_filter, hdu_out=None)[source]

Convert from WISE DN to Jy/pixel.

WISE maps are provided in convenience units of data numbers (DN). The constants to convert them are given in Table 1 of http://wise2.ipac.caltech.edu/docs/release/prelim/expsup/sec2_3f.html.

Parameters:
  • hdu_in (str or astropy.io.fits.PrimaryHDU) – File name of WISE .fits file, or an Astropy PrimaryHDU instance (i.e. the result of fits.open(file)[0]).
  • wise_filter (str) – Either ‘1’, ‘2’, ‘3’, or ‘4’.
  • hdu_out (str, optional) – If not None, will save the converted HDU out with this filename. Defaults to None.
Returns:

The HDU in units of Jy/pix.

Return type:

astropy.io.fits.PrimaryHDU

data_buttons.wise.wise_button(galaxies, filters='all', radius=None, filepath=None, download_data=True, create_mosaic=True, jy_conversion=True, verbose=False, **kwargs)[source]

Create a WISE mosaic, given a galaxy name.

Using a galaxy name and radius, queries around that object, downloads available WISE data and mosaics into a final product.

Parameters:
  • galaxies (str or list) – Names of galaxies to create mosaics for. Resolved by NED.
  • filters (str or list, optional) – Any combination of ‘1’, ‘2’, ‘3’, and ‘4’. If you want everything, select ‘all’. Defaults to ‘all’.
  • radius (astropy.units.Quantity, optional) – Radius around the galaxy to search for observations. Defaults to None, where it will query Ned to get size.
  • filepath (str, optional) – Path to save the working and output files to. If not specified, saves to current working directory.
  • download_data (bool, optional) – If True, will download data using MontagePy. Defaults to True.
  • create_mosaic (bool, optional) – Switching this to True will mosaic data as appropriate. Defaults to True.
  • jy_conversion (bool, optional) – Convert the mosaicked file from raw units to Jy/pix. Defaults to True.
  • verbose (bool, optional) – Print out messages during the process. Useful mainly for debugging purposes or large images. Defaults to False.

HST

data_buttons.hst.astrometric_correction(filename)[source]

Perform astrometric corrections on HST data.

Using the astrodrizzle alignimages package, will perform astrometric corrections on either a single file or a set of files. If a single file, then it will only provide absolute astrometric corrections based on Gaia observations. If multiple files, it will also correct for relative corrections between observations.

Parameters:filename (str or list) – The filenames for the data to correct. Can either be a single string or a list of filenames. IMPORTANT: These filenames should be just the filename with no directory structure beforehand. Else alignimages gets confused!
Returns:The filename for which an astrometric solution has been found (if input is a string), or information regarding all of the astrometric fits (if input is a list).
Return type:str or astropy.table.Table
data_buttons.hst.convert_to_jy(hdu_in, hdu_out=None)[source]

Convert from HST electrons/s to Jy/pixel.

HST maps are provided in units of electrons/s. These can be converted to more helpful units using the keywords in the .fits header, specifically PHOTFLAM (the sensitivity in ergs/cm^2/Ang/electron), and the pivot wavelength PHOTPLAM.

Parameters:
  • hdu_in (str or astropy.io.fits.PrimaryHDU) – File name of HST .fits file, or an Astropy PrimaryHDU instance (i.e. the result of fits.open(file)[0]).
  • hdu_out (str, optional) – string provided. Defaults to None.
Returns:

The HDU in units of Jy/pix.

Return type:

astropy.io.fits.PrimaryHDU

data_buttons.hst.download_mast(obs_table, **kwargs)[source]

Download data from the MAST archive.

This function gives you an easy way to download data from the MAST archive, if you already have a table of observations (from Astroquery) to hand. By default, this will download everything into your current working directory.

Parameters:obs_table (astropy.table.Table) – The result of an astroquery.mast query.
data_buttons.hst.hst_button(galaxies, skymethod='globalmin+match', instruments='ACS/WFC', prop_ids=None, filters=None, radius=None, filepath=None, download_data=True, correct_astrometry=True, create_mosaic=True, jy_conversion=True, verbose=False, log_filename='hst.log')[source]

Create a HST mosaic, given a galaxy name.

Using a galaxy name and radius, queries around that object, downloads available HST data and mosaics into a final product. It will create separate mosaics for each proposal ID, and the file structure will look like /galaxy/HST/proposal_id/galaxy_instrument_filter_proposal_id.fits.

N.B. I must confess to not being well-versed with HST data, so if anyone can help improve this please let me know.

This data button uses a number of tools included in the drizzlepac Python package. This includes alignimages/tweakreg and astrodrizzle, which correct astrometry and are specifically tailored for the setup of HST data. This means that 1) creating mosaics with this will likely take a long time and 2) you will need a beefy computer (especially with regards to hard drive space).

Parameters:
  • galaxies (str or list) – Names of galaxies to create mosaics for. Resolved by NED.
  • skymethod (str, optional) – Method used for AstroDrizzle’s background matching step. In general, this can be left untouched but for mosaics with little overlap, it may be worth playing around with this. For instance, I’ve had some luck when there isn’t much overlap between exposures using ‘globalmin’. Options are ‘localmin’, ‘globalmin+match’, ‘globalmin’, and ‘match’. Defaults to ‘globalmin+match’.
  • instruments (str or list, optional) – Instrument to download data for. Can be any combination of ‘ACS/WFC’, ‘WFC3/IR’, ‘WFC3/UVIS’, ‘WFPC2/PC’, or ‘WFPC2/WFC’. If you want all available data for all these instruments, select ‘all’, but this is not recommended! Defaults to ‘ACS/WFC’.
  • prop_ids (str or list, optional) – Proposal IDs to download data for. Defaults to None, which will pull out all proposal IDs for each instrument.
  • filters (str or list, optional) – Filters to download data for. The script will look for each filter, for each instrument. Defaults to None, which will pull out all applicable filters for each instrument, for each proposal ID.
  • radius (astropy.units.Quantity, optional) – Radius around the galaxy to search for observations. Defaults to None, where it will query Ned to get size.
  • filepath (str, optional) – Path to save the working and output files to. If not specified, saves to current working directory.
  • download_data (bool, optional) – If True, will download data from MAST. Defaults to True.
  • correct_astrometry (bool, optional) – If True, will perform astrometric corrections to the downloaded data using alignimages. Defaults to True.
  • create_mosaic (bool, optional) – Switching this to True will mosaic the data using astrodrizzle as appropriate. Defaults to True.
  • jy_conversion (bool, optional) – Convert the mosaicked file from raw units to Jy/pix. Defaults to True.
  • verbose (bool, optional) – Can be used to suppress most of the output messages produced during the process. Mainly useful for debugging. Defaults to False.
  • log_filename (str, optional) – Will produce a stripped down log of what data the code is reducing. By default, will save to galaxy/hst.log.

Spitzer

data_buttons.spitzer.convert_to_jy(hdu_in, hdu_out=None)[source]

Convert from MJy/sr to Jy/px.

Spitzer maps are in MJy/sr, which can be converted through to units of Jy/px.

Parameters:
  • hdu_in (str or astropy.io.fits.PrimaryHDU) – File name of Spitzer .fits file, or an Astropy PrimaryHDU instance (i.e. the result of fits.open(file)[0]).
  • hdu_out (str, optional) – If not None, will save the converted HDU out with this filename. Defaults to None.
Returns:

The HDU in units of Jy/pix.

Return type:

astropy.io.fits.PrimaryHDU

data_buttons.spitzer.spitzer_button(galaxies, filters='all', radius=None, filepath=None, download_data=True, create_mosaic=True, jy_conversion=True, verbose=False)[source]

Create an Spitzer mosaic, given a galaxy name.

Using a galaxy name and radius, queries around that object, downloads available Spitzer data from the SHA and mosaics.

Parameters:
  • galaxies (str or list) – Names of galaxies to create mosaics for.
  • filters (str or list, optional) – Any combination of ‘IRAC1’, ‘IRAC2’, ‘IRAC3’, ‘IRAC4’, ‘MIPS24’, ‘MIPS70’, or ‘MIPS160’. If you want everything, select ‘all’. Defaults to ‘all’.
  • radius (astropy.units.Quantity, optional) – Radius around the galaxy to search for observations. Defaults to None, where it will query Ned to get size.
  • filepath (str, optional) – Path to save the working and output files to. If not specified, saves to current working directory.
  • download_data (bool, optional) – If True, will download data using Astroquery. Defaults to True.
  • create_mosaic (bool, optional) – Switching this to True will mosaic data as appropriate. Defaults to True.
  • jy_conversion (bool, optional) – Convert the mosaicked file from raw units to Jy/pix. Defaults to True.
  • verbose (bool, optional) – Print out messages during the process. Useful mainly for debugging purposes or large images. Defaults to False.

Herschel

data_buttons.herschel.convert_to_jy(hdu_in, hdu_out=None)[source]

Convert from MJy/sr to Jy/px.

SPIRE maps are in MJy/sr, which can be converted through to units of Jy/px.

Parameters:
  • hdu_in (str or astropy.io.fits.PrimaryHDU) – File name of SPIRE .fits file, or an Astropy PrimaryHDU instance (i.e. the result of fits.open(file)[0]).
  • hdu_out (str, optional) – If not None, will save the converted HDU out with this filename. Defaults to None.
Returns:

The HDU in units of Jy/pix.

Return type:

astropy.io.fits.PrimaryHDU

data_buttons.herschel.herschel_button(galaxies, filters='all', radius=None, filepath=None, download_data=True, create_mosaic=True, jy_conversion=True, verbose=False)[source]

Create an Herschel mosaic, given a galaxy name.

Using a galaxy name and radius, queries around that object, downloads available Herschel data from the HSA and mosaics.

Parameters:
  • galaxies (str or list) – Names of galaxies to create mosaics for.
  • filters (str or list, optional) – Any combination of ‘PACS70’, ‘PACS100’, ‘PACS160’, ‘SPIRE250’, ‘SPIRE350’, ‘SPIRE500’. If you want everything, select ‘all’. Defaults to ‘all’.
  • radius (astropy.units.Quantity, optional) – Radius around the galaxy to search for observations. Defaults to None, where it will query Ned to get size.
  • filepath (str, optional) – Path to save the working and output files to. If not specified, saves to current working directory.
  • download_data (bool, optional) – If True, will download data using Astroquery. Defaults to True.
  • create_mosaic (bool, optional) – Switching this to True will mosaic data as appropriate. Defaults to True.
  • jy_conversion (bool, optional) – Convert the mosaicked file from raw units to Jy/pix. Defaults to True.
  • verbose (bool, optional) – Print out messages during the process. Useful mainly for debugging purposes or large images. Defaults to False.

Planck

data_buttons.planck.convert_to_jy(hdu_in, frequency, hdu_out=None)[source]

Convert from Planck K to Jy/pixel.

Planck maps are units related to the CMB temperature. These can be converted to MJy/sr using conversion factors either in https://wiki.cosmos.esa.int/planckpla2015/index.php/UC_CC_Tables#LFI_Unit_Conversion_Tables for LFI, or Planck Collaboration IX (2013) for the HFI.

Parameters:
  • hdu_in (str or astropy.io.fits.PrimaryHDU) – File name of Planck .fits file, or an Astropy PrimaryHDU instance (i.e. the result of fits.open(file)[0]).
  • frequency (str) – Either ‘030’, ‘044’, ‘070’, ‘100’, ‘143’, ‘217’, ‘353’, ‘545’, or ‘857’.
  • hdu_out (str, optional) – If not None, will save the converted HDU out with this filename. Defaults to None.
Returns:

The HDU in units of Jy/pix.

Return type:

astropy.io.fits.PrimaryHDU

data_buttons.planck.planck_button(galaxies, frequencies='all', radius=None, filepath=None, download_data=True, jy_conversion=True, verbose=False)[source]

Obtain Planck cutout, given a galaxy name.

Using a galaxy name and radius, uses SkyView to download a Planck cutout.

Parameters:
  • galaxies (str or list) – Names of galaxies to create mosaics for. Resolved by NED.
  • frequencies (str or list, optional) – Any combination of ‘030’, ‘044’, ‘070’, ‘100’, ‘143’, ‘217’, ‘353’, ‘545’, ‘857’. If you want everything, select ‘all’. Defaults to ‘all’.
  • radius (astropy.units.Quantity, optional) – Radius around the galaxy to search for observations. Defaults to None, where it will query Ned to get size.
  • filepath (str, optional) – Path to save the working and output files to. If not specified, saves to current working directory.
  • download_data (bool, optional) – If True, will download data from SkyView. Defaults to True.
  • jy_conversion (bool, optional) – Convert the downloaded file from raw units to Jy/pix. Defaults to True.
  • verbose (bool, optional) – Print out messages during the process. Useful mainly for debugging purposes or large images. Defaults to False.

Tools

data_buttons.tools.background_median(data, sigma=3, npixels=5, maxiters=20, **kwargs)[source]

Calculate background median for data.

Calculates the background median for an image by iteratively sigma clipping. It first creates a source mask using segmentation and binary dilation (see https://photutils.readthedocs.io/en/stable/api/photutils.make_source_mask.html) for more details, before iteratively calculating the sigma-clipped median of the data.

Parameters:
  • data (str or numpy.ndarray or astropy.io.fits.PrimaryHDU) – Data to calculate the background median for. If provided as a string, this is interpreted as a filename for a .fits HDU.
  • sigma (float, optional) – Level to perform sigma-clipping to. Defaults to 3.
  • npixels (int, optional) – Number of connected pixels greater than sigma to consider for a pixel to be part of a source when masking. Defaults to 5.
  • maxiters (int,optional) – The maximum number of sigma-clipping iterations to perform. Defaults to 20.
Returns:

Background median of the data.

Return type:

float

data_buttons.tools.interp_nans(data, x_stddev=1)[source]

Interpolate over any NaNs present in a final mosaic.

Uses the Astropy.convolution interpolate_replace_nans to smooth over any gaps left in an image. This may be particularly useful for WFPC2 images, where there are small gaps between chips.

Parameters:
  • data (numpy.ndarray) – Input data to interpolate NaNs over.
  • x_stddev (int, optional) – Standard deviation of the Gaussian kernel. Defaults to 1 (pixel).
Returns:

The data with NaNs interpolated over

Return type:

numpy.ndarray

data_buttons.tools.make_header(galaxy, width=0.2, height=0.2, output_file='hdr.hdr', resolution=1)[source]

Replacement for mHdr.

mHdr seems to have broken with an IRSA update. This should function the same way.

Parameters:
  • galaxy (str) – Target to resolve.
  • width (float, optional) – Output image width in decimal degrees. Defaults to 0.2 deg.
  • height (float, optional) – Output image height in decimal degrees. Defaults to 0.2 deg.
  • output_file (str, optional) – Filename for output header. Defaults to hdr.hdr.
  • resolution (float, optional) – Resolution of output image in arcsec. Defaults to 1.
data_buttons.tools.model_background(data, poly_order=5, sigma=2, npixels=5, **kwargs)[source]

Model the background as a 2D polynomial.

After masking sources, fits a 2D polynomial to the remaining data. This is useful for images where the background ripples over small angular scales, such as 2MASS or SDSS data.

Parameters:
  • data (str or numpy.ndarray or astropy.io.fits.PrimaryHDU) – Data to calculate the background median for. If provided as a string, this is interpreted as a filename for a .fits HDU.
  • poly_order (int, optional) – The 2D polynomial order to fit the background to. Defaults to 5.
  • sigma (float, optional) – Level to set mask minimum SNR to. Defaults to 2.
  • npixels (int, optional) – Number of connected pixels greater than sigma to consider for a pixel to be part of a source when masking. Defaults to 5.
Returns:

The modelled background; same size as the input

data.

Return type:

numpy.ndarray

data_buttons.tools.mosaic(input_folder, header=None, output_folder='mosaic', reproject=True, background_match=True, haveAreas=False, verbose=False)[source]

Mosaic together a folder full of .fits files.

Takes a folder and runs through the number of steps that MontagePy requires to combine all the .fits files within that folder. Also, optionally performs background modelling and matching (which most users will want to set to true). Note that this is not a background subtraction! Can also be set to weight the final added images, for instance if you have input files of different exposure times.

Parameters:
  • input_folder (str) – Folder of raw files to mosaic.
  • header (str, optional) – Output from mHdr. If not specified, will mosaic all of the images together no matter the overlap.
  • output_folder (str, optional) – Working folder for mosaicking. Defaults to ‘mosaic’.
  • reproject (bool, optional) – Whether to reproject input images or not. If already on same pixel scale, you can skip this. In this case, it will move files from input_folder to the projected folder. Defaults to True.
  • background_match (bool, optional) – Whether to perform background matching steps while mosaicking. Defaults to True.
  • haveAreas (bool, optional) – If weighting a mosaic, you can use _area.fits files to effectively weight properly. If true, before co-adding the area files will be moved alongside the data files. Defaults to False.
  • verbose (bool, optional) – Print out verbose statements during the mosaicking process. Useful for debugging. Defaults to False.
data_buttons.tools.optimize_size(hdu, hdu_out=None)[source]

Optimize the size of a .fits image.

Calculate the minimum size for an image, updating the HDU at the end. This is useful for images out of mosaicking tools, where there might be a number of NaNs artificially inflating the filesize.

Parameters:
  • hdu (str or astropy.io.fits.PrimaryHDU) – Data to optimize size of. If this is a string, this is interpreted as a filename for a .fits HDU.
  • hdu_out (str, optional) – Filename for output trimmed .fits file. Defaults to None, which will save nothing.
Returns:

The size-optimized HDU.

Return type:

astropy.io.fits.ImageHDU