Example #1
0
def process_image(input, **kwargs):
    """Run a standard analysis and returns the associated Image object.

    The input can be a FITS or CASA image, a PyBDSF parameter save
    file, or a dictionary of options. Partial names are allowed for the
    parameters as long as they are unique. Parameters are set to default
    values if par = ''.

    Examples:
        > img = bdsf.process_image('example.fits', thresh_isl=4)
          --> process FITS image names 'example.fits'
        > img_3C196 = bdsf.process_image('3C196.image', mea='map')
          --> process CASA image, 'mean_map' parameter is abbreviated
        > img_VirA = bdsf.process_image('VirA_im.pybdsf.sav')
          --> load parameter save file and process
    """
    from interface import load_pars
    from image import Image
    import os

    # Try to load input assuming it's a parameter save file or a dictionary.
    # load_pars returns None if this doesn't work.
    img, err = load_pars(input)

    # If load_pars fails (returns None), assume that input is an image file. If it's not a
    # valid image file (but is an existing file), an error will be raised
    # by img.process() during reading of the file.
    if img is None:
        if os.path.exists(input):
            img = Image({'filename': input})
        else:
            raise RuntimeError("File '" + input + "' not found.")

    # Now process it. Any kwargs specified by the user will
    # override those read in from the parameter save file or dictionary.
    img.process(**kwargs)
    return img
Example #2
0
def process_image(input, **kwargs):
    """Run a standard analysis and returns the associated Image object.

    The input can be a FITS or CASA image, a PyBDSM parameter save
    file, or a dictionary of options. Partial names are allowed for the
    parameters as long as they are unique. Parameters are set to default
    values if par = ''.

    Examples:
        > img = bdsm.process_image('example.fits', thresh_isl=4)
          --> process FITS image names 'example.fits'
        > img_3C196 = bdsm.process_image('3C196.image', mea='map')
          --> process CASA image, 'mean_map' parameter is abbreviated
        > img_VirA = bdsm.process_image('VirA_im.pybdsm.sav')
          --> load parameter save file and process
    """
    from interface import load_pars
    from image import Image
    import os

    # Try to load input assuming it's a parameter save file or a dictionary.
    # load_pars returns None if this doesn't work.
    img, err = load_pars(input)

    # If load_pars fails (returns None), assume that input is an image file. If it's not a
    # valid image file (but is an existing file), an error will be raised
    # by img.process() during reading of the file.
    if img == None:
        if os.path.exists(input):
            img = Image({'filename': input})
        else:
            raise RuntimeError("File '" + input + "' not found.")

    # Now process it. Any kwargs specified by the user will
    # override those read in from the parameter save file or dictionary.
    img.process(**kwargs)
    return img
Example #3
0
 def load_pars(self, loadfile=None):
     """Load parameter values."""
     import interface
     import os
     if loadfile is None or loadfile == '':
         loadfile = self.opts.filename + '.pybdsm.sav'
     if os.path.exists(loadfile):
         timg, err = interface.load_pars(loadfile)
         if timg is not None:
             orig_filename = self.opts.filename
             self.opts = timg.opts
             self.opts.filename = orig_filename # reset filename to original
         else:
             if self._is_interactive_shell:
                 print "\n\033[31;1mERROR\033[0m: '"+\
                 loadfile+"' is not a valid parameter save file."
             else:
                 raise RuntimeError(str(err))
     else:
         if self._is_interactive_shell:
             print "\n\033[31;1mERROR\033[0m: File '"+\
             loadfile+"' not found."
         else:
             raise RuntimeError('File not found')
Example #4
0
 def load_pars(self, loadfile=None):
     """Load parameter values."""
     import interface
     import os
     if loadfile is None or loadfile == '':
         loadfile = self.opts.filename + '.pybdsf.sav'
     if os.path.exists(loadfile):
         timg, err = interface.load_pars(loadfile)
         if timg is not None:
             orig_filename = self.opts.filename
             self.opts = timg.opts
             self.opts.filename = orig_filename  # reset filename to original
         else:
             if self._is_interactive_shell:
                 print "\n\033[31;1mERROR\033[0m: '"+\
                 loadfile+"' is not a valid parameter save file."
             else:
                 raise RuntimeError(str(err))
     else:
         if self._is_interactive_shell:
             print "\n\033[31;1mERROR\033[0m: File '"+\
             loadfile+"' not found."
         else:
             raise RuntimeError('File not found')