ImageFileCollection — MSUMastro toolbox 0.1 documentation

# ImageFileCollection

class `msumastro.image_collection.` `ImageFileCollection`(location=None, keywords=None, info_file=None)

  Bases: `object`

  Representation of a collection of image files.

  The class offers a table summarizing values of keywords in the FITS headers of the files in the collection and offers convenient methods for iterating over the files in the collection. The generator methods use simple filtering syntax and can automate storage of any FITS files modified in the loop using the generator.

  Parameters: | location : str, optional path to directory containing FITS files keywords : list of str, optional Keywords that should be used as column headings in the summary table. info_file : str, optional Path to file that contains a table of information about FITS files.

  Attributes

  `location` | str, Path name to directory containing FITS files
  `keywords` | list of str, Keywords currently in the summary table.
  `files` | list of str, Unfiltered list of FITS files in location.
  `summary_info` | astropy.table.Table of values of FITS keywords for files in the collection.

  Attributes Summary

  `files` | list of str, Unfiltered list of FITS files in location.
  `keywords` | list of str, Keywords currently in the summary table.
  `location` | str, Path name to directory containing FITS files
  `summary_info` | astropy.table.Table of values of FITS keywords for files in the collection.

  Methods Summary

  `data`([hdulist, save_with_name, ...]) | Generator that yields each image in the collection.
  `files_filtered`(**kwd) | Determine files whose keywords have listed values.
  `hdus`([save_with_name, save_location, ...]) | Generator that yields each HDU in the collection.
  `headers`([save_with_name, save_location, ...]) | Generator that yields each header in the collection.
  `values`(keyword[, unique]) | List of values for a keyword.

  Attributes Documentation

  `files`

    list of str, Unfiltered list of FITS files in location.

  `keywords`

    list of str, Keywords currently in the summary table.

    Setting the keywords causes the summary table to be regenerated unless the new keywords are a subset of the old.

  `location`

    str, Path name to directory containing FITS files

  `summary_info`

    astropy.table.Table of values of FITS keywords for files in the collection.

    Each keyword is a column heading. In addition, there is a column called ‘file’ that contains the name of the FITS file. The directory is not included as part of that name.

  Methods Documentation

  `data`(hdulist=None, save_with_name='', save_location='', do_not_scale_image_data=False, clobber=False, **kwd)

    Generator that yields each image in the collection.

    If any of the parameters `save_with_name`, `save_location` or `clobber` evaluates to `True` the generator will write a copy of each FITS file it is iterating over. In other words, if `save_with_name` and/or `save_location` is a string with non-zero length, and/or `clobber` is `True`, a copy of each FITS file will be made.

    Parameters: | save_with_name : str string added to end of file name (before extension) if FITS file should be saved after iteration. Unless save_location is set, files will be saved to location of the source files self.location save_location : str Directory in which to save FITS files; implies that FITS files will be saved. Note this provides an easy way to copy a directory of files–loop over the image with save_location set. clobber : bool If `True`, overwrite input FITS files. do_not_scale_image_data : bool If `True`, prevents fits from scaling images. Default is `False`. return_fname : bool, default is False If True, return the tuple (header, file_name) instead of just header. kwd : dict Any additional keywords are used to filter the items returned; see Examples for details.
    Returns: | numpy.ndarray If `return_fname` is `False`, yield the next image in the collection (numpy.ndarray, str) If `return_fname` is `True`, yield a tuple of (image, file path) for next the item in the collection.

  `files_filtered`(**kwd)

    Determine files whose keywords have listed values.

    **kwd is list of keywords and values the files must have.

    The value ‘*’ represents any value.
      A missing keyword is indicated by value ‘’

    Example: >>> keys = [‘imagetyp’,’filter’] >>> collection = ImageFileCollection(‘test/data’, keywords=keys) >>> collection.files_filtered(imagetyp=’LIGHT’, filter=’R’) >>> collection.files_filtered(imagetyp=’*’, filter=’‘)

    NOTE: Value comparison is case insensitive for strings.

  `hdus`(save_with_name='', save_location='', clobber=False, do_not_scale_image_data=False, **kwd)

    Generator that yields each HDU in the collection.

    If any of the parameters `save_with_name`, `save_location` or `clobber` evaluates to `True` the generator will write a copy of each FITS file it is iterating over. In other words, if `save_with_name` and/or `save_location` is a string with non-zero length, and/or `clobber` is `True`, a copy of each FITS file will be made.

    Parameters: | save_with_name : str string added to end of file name (before extension) if FITS file should be saved after iteration. Unless save_location is set, files will be saved to location of the source files self.location save_location : str Directory in which to save FITS files; implies that FITS files will be saved. Note this provides an easy way to copy a directory of files–loop over the HDU with save_location set. clobber : bool If `True`, overwrite input FITS files. do_not_scale_image_data : bool If `True`, prevents fits from scaling images. Default is `False`. return_fname : bool, default is False If True, return the tuple (header, file_name) instead of just header. kwd : dict Any additional keywords are used to filter the items returned; see Examples for details.
    Returns: | astropy.io.fits.HDU If `return_fname` is `False`, yield the next HDU in the collection (astropy.io.fits.HDU, str) If `return_fname` is `True`, yield a tuple of (HDU, file path) for next the item in the collection.

  `headers`(save_with_name='', save_location='', clobber=False, do_not_scale_image_data=True, return_fname=False, **kwd)

    Generator that yields each header in the collection.

    If any of the parameters `save_with_name`, `save_location` or `clobber` evaluates to `True` the generator will write a copy of each FITS file it is iterating over. In other words, if `save_with_name` and/or `save_location` is a string with non-zero length, and/or `clobber` is `True`, a copy of each FITS file will be made.

    Parameters: | save_with_name : str string added to end of file name (before extension) if FITS file should be saved after iteration. Unless save_location is set, files will be saved to location of the source files self.location save_location : str Directory in which to save FITS files; implies that FITS files will be saved. Note this provides an easy way to copy a directory of files–loop over the header with save_location set. clobber : bool If `True`, overwrite input FITS files. do_not_scale_image_data : bool If `True`, prevents fits from scaling images. Default is `True`. return_fname : bool, default is False If True, return the tuple (header, file_name) instead of just header. kwd : dict Any additional keywords are used to filter the items returned; see Examples for details.
    Returns: | astropy.io.fits.Header If `return_fname` is `False`, yield the next header in the collection (astropy.io.fits.Header, str) If `return_fname` is `True`, yield a tuple of (header, file path) for next the item in the collection.

  `values`(keyword, unique=False)

    List of values for a keyword.

    Parameters: | keyword : str Keyword (i.e. table column) for which values are desired. unique : bool, optional If True, return only the unique values for the keyword.
    Returns: | list Values as a list.