text
stringlengths
81
112k
Determine the beam in pixels at the given location in sky coordinates. Parameters ---------- ra , dec : float The sly coordinates at which the beam is determined. Returns ------- beam : :class:`AegeanTools.fits_image.Beam` A beam object, with a/b...
Calculate the area of the synthesized beam in square degrees. Parameters ---------- ra, dec : float The sky coordinates at which the calculation is made. Returns ------- area : float The beam area in square degrees. def get_beamarea_deg2(self, r...
Calculate the beam area in square pixels. Parameters ---------- ra, dec : float The sky coordinates at which the calculation is made dec Returns ------- area : float The beam area in square pixels. def get_beamarea_pix(self, ra, dec): ...
calculate the GCD sky separation (degrees) between two pixels. Parameters ---------- pix1, pix2 : (float, float) The (x,y) pixel coordinates for the two positions. Returns ------- dist : float The distance between the two points (degrees). def s...
Determine the local psf at a given sky location. The psf is returned in degrees. Parameters ---------- ra, dec : float The sky position (degrees). Returns ------- a, b, pa : float The psf semi-major axis, semi-minor axis, and position an...
Determine the local psf (a,b,pa) at a given sky location. The psf is in pixel coordinates. Parameters ---------- ra, dec : float The sky position (degrees). Returns ------- a, b, pa : float The psf semi-major axis (pixels), semi-minor ax...
Get the psf at the location specified in pixel coordinates. The psf is also in pixel coordinates. Parameters ---------- ra, dec : float The sky position (degrees). Returns ------- a, b, pa : float The psf semi-major axis (pixels), semi-mi...
Get the psf as a :class:`AegeanTools.fits_image.Beam` object. Parameters ---------- ra, dec : float The sky position (degrees). Returns ------- beam : :class:`AegeanTools.fits_image.Beam` The psf at the given location. def get_beam(self, ra, dec...
Calculate the area of the beam in square pixels. Parameters ---------- ra, dec : float The sky position (degrees). Returns ------- area : float The area of the beam in square pixels. def get_beamarea_pix(self, ra, dec): """ Calcu...
Calculate the area of the beam in square degrees. Parameters ---------- ra, dec : float The sky position (degrees). Returns ------- area : float The area of the beam in square degrees. def get_beamarea_deg2(self, ra, dec): """ C...
Find the first location in our array that is not empty def find_start_point(self): """ Find the first location in our array that is not empty """ for i, row in enumerate(self.data): for j, _ in enumerate(row): if self.data[i, j] != 0: # or not np.isfinite(se...
Move from the current location to the next Parameters ---------- x, y : int The current location def step(self, x, y): """ Move from the current location to the next Parameters ---------- x, y : int The current location "...
Determine whether the pixel x,y is nonzero Parameters ---------- x, y : int The pixel of interest. Returns ------- solid : bool True if the pixel is not zero. def solid(self, x, y): """ Determine whether the pixel x,y is nonzero ...
Starting at a point on the perimeter of a region, 'walk' the perimeter to return to the starting point. Record the path taken. Parameters ---------- startx, starty : int The starting location. Assumed to be on the perimeter of a region. Returns ------- ...
March about and trace the outline of our object Returns ------- perimeter : list The pixels on the perimeter of the region [[x1, y1], ...] def do_march(self): """ March about and trace the outline of our object Returns ------- perimeter : li...
Blank all the pixels within the given perimeter. Parameters ---------- perimeter : list The perimeter of the region. def _blank_within(self, perimeter): """ Blank all the pixels within the given perimeter. Parameters ---------- perimeter : l...
Recursive march in the case that we have a fragmented shape. Returns ------- perimeters : [perimeter1, ...] The perimeters of all the regions in the image. See Also -------- :func:`AegeanTools.msq2.MarchingSquares.do_march` def do_march_all(self): ""...
Generate a model 2d Gaussian with the given parameters. Evaluate this model at the given locations x,y. Parameters ---------- x, y : numeric or array-like locations at which to evaluate the gaussian amp : float Peak value. xo, yo : float Center of the gaussian. sx, s...
Construct a correlation matrix corresponding to the data. The matrix assumes a gaussian correlation function. Parameters ---------- x, y : array-like locations at which to evaluate the correlation matirx sx, sy : float major/minor axes of the gaussian correlation function (sigmas) ...
Calculate a matrix which is effectively the square root of the correlation matrix C Parameters ---------- C : 2d array A covariance matrix Returns ------- B : 2d array A matrix B such the B.dot(B') = inv(C) def Bmatrix(C): """ Calculate a matrix which is effectively t...
Analytical calculation of the Jacobian for an elliptical gaussian Will work for a model that contains multiple Gaussians, and for which some components are not being fit (don't vary). Parameters ---------- pars : lmfit.Model The model parameters x, y : list Locations at which th...
Wrapper around :func:`AegeanTools.fitting.jacobian` and :func:`AegeanTools.fitting.emp_jacobian` which gives the output in a format that is required for lmfit. Parameters ---------- pars : lmfit.Model The model parameters x, y : list Locations at which the jacobian is being evaluat...
Create a hessian matrix corresponding to the source model 'pars' Only parameters that vary will contribute to the hessian. Thus there will be a total of nvar x nvar entries, each of which is a len(x) x len(y) array. Parameters ---------- pars : lmfit.Parameters The model x, y : list...
Calculate the hessian matrix empirically. Create a hessian matrix corresponding to the source model 'pars' Only parameters that vary will contribute to the hessian. Thus there will be a total of nvar x nvar entries, each of which is a len(x) x len(y) array. Parameters ---------- pars : lmfi...
Calculate the autocorrelation function of the noise where the noise is a 2d array that may contain nans Parameters ---------- noise : 2d-array Noise image. Returns ------- acf : 2d-array The ACF. def nan_acf(noise): """ Calculate the autocorrelation function of th...
Create the matrix ita of the noise where the noise may be a masked array where ita(x,y) is the correlation between pixel pairs that have the same separation as x and y. Parameters ---------- noise : 2d-array The noise image acf : 2d-array The autocorrelation matrix. (None = calcula...
Calculate the expected bias on each of the parameters in the model pars. Only parameters that are allowed to vary will have a bias. Calculation follows the description of Refrieger & Brown 1998 (cite). Parameters ---------- data : 2d-array data that was fit pars : lmfit.Parameters ...
Calculate and apply a bias correction to the given fit parameters Parameters ---------- params : lmfit.Parameters The model parameters. These will be modified. data : 2d-array The data which was used in the fitting acf : 2d-array ACF of the data. Default = None. Retu...
Calculate the parameter errors for a fitted source using the description of Condon'97 All parameters are assigned errors, assuming that all params were fit. If some params were held fixed then these errors are overestimated. Parameters ---------- source : :class:`AegeanTools.models.SimpleSource...
Convert pixel based errors into sky coord errors Parameters ---------- source : :class:`AegeanTools.models.SimpleSource` The source which was fit. model : lmfit.Parameters The model which was fit. wcshelper : :class:`AegeanTools.wcs_helpers.WCSHelper` WCS information. ...
Convert pixel based errors into sky coord errors Uses covariance matrix for ra/dec errors and calculus approach to a/b/pa errors Parameters ---------- source : :class:`AegeanTools.models.SimpleSource` The source which was fit. model : lmfit.Parameters The model which was fit. ...
Convert an lmfit.Parameters object into a function which calculates the model. Parameters ---------- params : lmfit.Parameters Model parameters, can have multiple components. Returns ------- model : func A function f(x,y) that will compute the model. def ntwodgaussian_lmfit(p...
Fit the model to the data data may contain 'flagged' or 'masked' data with the value of np.NaN Parameters ---------- data : 2d-array Image data params : lmfit.Parameters Initial model guess. B : 2d-array B matrix to be used in residual calculations. Default = N...
Take a set of parameters that were fit with lmfit, and replace the errors with the 1\sigma errors calculated using the covariance matrix. Parameters ---------- params : lmfit.Parameters Model data : 2d-array Image data errs : 2d-array ? Image noise. B : 2d-array ...
act as a multiprocessing barrier def barrier(events, sid, kind='neighbour'): """ act as a multiprocessing barrier """ events[sid].set() # only wait for the neighbours if kind=='neighbour': if sid > 0: logging.debug("{0} is waiting for {1}".format(sid, sid - 1)) e...
Perform sigma clipping on an array, ignoring non finite values. During each iteration return an array whose elements c obey: mean -std*lo < c < mean + std*hi where mean/std are the mean std of the input array. Parameters ---------- arr : iterable An iterable array of numeric types. ...
A shallow wrapper for sigma_filter. Parameters ---------- args : list A list of arguments for sigma_filter Returns ------- None def _sf2(args): """ A shallow wrapper for sigma_filter. Parameters ---------- args : list A list of arguments for sigma_filter ...
Calculate the background and rms for a sub region of an image. The results are written to shared memory - irms and ibkg. Parameters ---------- filename : string Fits file to open region : list Region within the fits file that is to be processed. (row_min, row_max). step_size :...
Calculate the background and noise images corresponding to the input file. The calculation is done via a box-car approach and uses multiple cores and shared memory. Parameters ---------- filename : str Filename to be filtered. step_size : (int, int) Step size for the filter. b...
Create a background and noise image from an input image. Resulting images are written to `outbase_bkg.fits` and `outbase_rms.fits` Parameters ---------- im_name : str or HDUList Image to filter. Either a string filename or an astropy.io.fits.HDUList. out_base : str The output filena...
Combine data and a fits header to write a fits file. Parameters ---------- data : numpy.ndarray The data to be written. header : astropy.io.fits.hduheader The header for the fits file. file_name : string The file to write Returns ------- None def write_fits(d...
Convert sexegessimal RA string into a float in degrees. Parameters ---------- dec : string A string separated representing the Dec. Expected format is `[+- ]hh:mm[:ss.s]` Colons can be replaced with any whit space character. Returns ------- dec : float The Dec i...
Convert decimal degrees into a sexagessimal string in degrees. Parameters ---------- x : float Angle in degrees Returns ------- dms : string String of format [+-]DD:MM:SS.SS or XX:XX:XX.XX if x is not finite. def dec2dms(x): """ Convert decimal degrees into a s...
Convert decimal degrees into a sexagessimal string in hours. Parameters ---------- x : float Angle in degrees Returns ------- dms : string String of format HH:MM:SS.SS or XX:XX:XX.XX if x is not finite. def dec2hms(x): """ Convert decimal degrees into a sexages...
Calculate the great circle distance between to points using the haversine formula [1]_. Parameters ---------- ra1, dec1, ra2, dec2 : float The coordinates of the two points of interest. Units are in degrees. Returns ------- dist : float The distance between the two poi...
Calculate the bearing of point 2 from point 1 along a great circle. The bearing is East of North and is in [0, 360), whereas position angle is also East of North but (-180,180] Parameters ---------- ra1, dec1, ra2, dec2 : float The sky coordinates (degrees) of the two points. Returns -...
Translate a given point a distance r in the (initial) direction theta, along a great circle. Parameters ---------- ra, dec : float The initial point of interest (degrees). r, theta : float The distance and initial direction to translate (degrees). Returns ------- ra, dec ...
Calculate the Rhumb line distance between two points [1]_. A Rhumb line between two points is one which follows a constant bearing. Parameters ---------- ra1, dec1, ra2, dec2 : float The position of the two points (degrees). Returns ------- dist : float The distance between...
Calculate the bearing of point 2 from point 1 along a Rhumb line. The bearing is East of North and is in [0, 360), whereas position angle is also East of North but (-180,180] Parameters ---------- ra1, dec1, ra2, dec2 : float The sky coordinates (degrees) of the two points. Returns ---...
Translate a given point a distance r in the (initial) direction theta, along a Rhumb line. Parameters ---------- ra, dec : float The initial point of interest (degrees). r, theta : float The distance and initial direction to translate (degrees). Returns ------- ra, dec : fl...
Convert galactic l/b to fk5 ra/dec Parameters ---------- l, b : float Galactic coordinates in radians. Returns ------- ra, dec : float FK5 ecliptic coordinates in radians. def galactic2fk5(l, b): """ Convert galactic l/b to fk5 ra/dec Parameters ---------- ...
Mask a 2d image (data) such that pixels within 'region' are set to nan. Parameters ---------- data : 2d-array Image array. wcs : astropy.wcs.WCS WCS for the image in question. region : :class:`AegeanTools.regions.Region` A region within which the image pixels will be maske...
Created a masked version of file, using a region. Parameters ---------- regionfile : str A file which can be loaded as a :class:`AegeanTools.regions.Region`. The image will be masked according to this region. infile : str Input FITS image. outfile : str Output FIT...
Apply a given mask (region) to the table, removing all the rows with ra/dec inside the region If negate=False then remove the rows with ra/dec outside the region. Parameters ---------- region : :class:`AegeanTools.regions.Region` Region to mask. table : Astropy.table.Table Table t...
Apply a region file as a mask to a catalog, removing all the rows with ra/dec inside the region If negate=False then remove the rows with ra/dec outside the region. Parameters ---------- regionfile : str A file which can be loaded as a :class:`AegeanTools.regions.Region`. The catalogue...
Convert a MIMAS region (.mim) file into a DS9 region (.reg) file. Parameters ---------- mimfile : str Input file in MIMAS format. regfile : str Output file. def mim2reg(mimfile, regfile): """ Convert a MIMAS region (.mim) file into a DS9 region (.reg) file. Parameters ...
Convert a MIMAS region (.mim) file into a MOC region (.fits) file. Parameters ---------- mimfile : str Input file in MIMAS format. fitsfile : str Output file. def mim2fits(mimfile, fitsfile): """ Convert a MIMAS region (.mim) file into a MOC region (.fits) file. Parameter...
Convert a string that describes a box in ds9 format, into a polygon that is given by the corners of the box Parameters ---------- line : str A string containing a DS9 region command for a box. Returns ------- poly : [ra, dec, ...] The corners of the box in clockwise order from ...
Parse a string that describes a circle in ds9 format. Parameters ---------- line : str A string containing a DS9 region command for a circle. Returns ------- circle : [ra, dec, radius] The center and radius of the circle. def circle2circle(line): """ Parse a string tha...
Parse a string of text containing a DS9 description of a polygon. This function works but is not very robust due to the constraints of healpy. Parameters ---------- line : str A string containing a DS9 region command for a polygon. Returns ------- poly : [ra, dec, ...] The...
Parse a DS9 region file and write a MIMAS region (.mim) file. Parameters ---------- regfile : str DS9 region (.reg) file. mimfile : str MIMAS region (.mim) file. maxdepth : str Depth/resolution of the region file. def reg2mim(regfile, mimfile, maxdepth): """ Parse...
Return a region that is the combination of those specified in the container. The container is typically a results instance that comes from argparse. Order of construction is: add regions, subtract regions, add circles, subtract circles, add polygons, subtract polygons. Parameters ---------- co...
Construct a region which is the intersection of all regions described in the given list of file names. Parameters ---------- flist : list A list of region filenames. Returns ------- region : :class:`AegeanTools.regions.Region` The intersection of all regions, possibly empty...
Save the given region to a file Parameters ---------- region : :class:`AegeanTools.regions.Region` A region. filename : str Output file name. def save_region(region, filename): """ Save the given region to a file Parameters ---------- region : :class:`AegeanTools....
Convert a MIMAS region (.mim) file into a image (eg .png) Parameters ---------- region : :class:`AegeanTools.regions.Region` Region of interest. filename : str Output filename. def save_as_image(region, filename): """ Convert a MIMAS region (.mim) file into a image (eg .png) ...
Return some pixel information based on the given hdu header pixarea - the area of a single pixel in deg2 pixscale - the side lengths of a pixel (assuming they are square) Parameters ---------- header : HDUHeader or dict FITS header information Returns ------- pixarea : float ...
Create a :class:`AegeanTools.fits_image.Beam` object from a fits header. BPA may be missing but will be assumed to be zero. if BMAJ or BMIN are missing then return None instead of a beam object. Parameters ---------- header : HDUHeader The fits header. Returns ------- beam : ...
Search through an image header. If the keywords BMAJ/BMIN/BPA are not set, but there are AIPS history cards, then we can populate the BMAJ/BMIN/BPA. Fix the header if possible, otherwise don't. Either way, don't complain. Parameters ---------- header : HDUHeader Fits header which may or ma...
Set the image data. Will not work if the new image has a different shape than the current image. Parameters ---------- pixels : numpy.ndarray New image data Returns ------- None def set_pixels(self, pixels): """ Set the image data. ...
Calculate the rms of the image. The rms is calculated from the interqurtile range (IQR), to reduce bias from source pixels. Returns ------- rms : float The image rms. Notes ----- The rms value is cached after first calculation. def get_background_rm...
Get the sky coordinates for a given image pixel. Parameters ---------- pixel : (float, float) Image coordinates. Returns ------- ra,dec : float Sky coordinates (degrees) def pix2sky(self, pixel): """ Get the sky coordinates for a...
Get the pixel coordinates for a given sky position (degrees). Parameters ---------- skypos : (float,float) ra,dec position in degrees. Returns ------- x,y : float Pixel coordinates. def sky2pix(self, skypos): """ Get the pixel co...
Open a file, read contents, return a list of all the sources in that file. @param filename: @return: list of OutputSource objects def load_sources(filename): """ Open a file, read contents, return a list of all the sources in that file. @param filename: @return: list of OutputSource objects ...
Will search the beam info from the HISTORY :param hdulist: :return: def search_beam(hdulist): """ Will search the beam info from the HISTORY :param hdulist: :return: """ header = hdulist[0].header history = header['HISTORY'] history_str = str(history) #AIPS CLEAN BMAJ= 1....
Ensure that a>=b for a given source object. If a<b then swap a/b and increment pa by 90. err_a/err_b are also swapped as needed. Parameters ---------- source : object any object with a/b/pa/err_a/err_b properties def fix_shape(source): """ Ensure that a>=b for a given source object...
Angle theta is periodic with period pi. Constrain theta such that -pi/2<theta<=pi/2. Parameters ---------- theta : float Input angle. Returns ------- theta : float Rotate angle. def theta_limit(theta): """ Angle theta is periodic with period pi. Constrain theta...
Convert a telescope name into a latitude returns None when the telescope is unknown. Parameters ---------- telescope : str Acronym (name) of telescope, eg MWA. Returns ------- lat : float The latitude of the telescope. Notes ----- These values were taken from w...
Determine how many cores we are able to use. Return 1 if we are not able to make a queue via pprocess. Parameters ---------- cores : int The number of cores that are requested. Returns ------- cores : int The number of cores available. def check_cores(cores): """ D...
Look for and return all the aux files that are associated witht this filename. Will look for: background (_bkg.fits) rms (_rms.fits) mask (.mim) catalogue (_comp.fits) psf map (_psf.fits) will return filenames if they exist, or None where they do not. Parameters --...
Generator function. Segment an image into islands and return one island at a time. Needs to work for entire image, and also for components within an island. Parameters ---------- data : 2d-array Image array. rmsimg : 2d-array Noise image. ...
Estimates the number of sources in an island and returns initial parameters for the fit as well as limits on those parameters. Parameters ---------- data : 2d-array (sub) image of flux values. Background should be subtracted. rmsimg : 2d-array Image of 1...
Convert fitting results into a set of components Parameters ---------- result : lmfit.MinimizerResult The fitting results. model : lmfit.Parameters The model that was fit. island_data : :class:`AegeanTools.models.IslandFittingData` Data abou...
Populate the global_data object by loading or calculating the various components Parameters ---------- filename : str or HDUList Main image which source finding is run on hdu_index : int HDU index of the image within the fits file, default is 0 (first) ...
Generate and save the background and RMS maps as FITS files. They are saved in the current directly as aegean-background.fits and aegean-rms.fits. Parameters ---------- image_filename : str or HDUList Input image. hdu_index : int If fits file has more th...
Save the image data. This is probably only useful if the image data has been blanked. Parameters ---------- outname : str Name for the output file. def save_image(self, outname): """ Save the image data. This is probably only useful if the image data...
Calculate an rms image and a bkg image. Parameters ---------- mesh_size : int Number of beams per box default = 20 forced_rms : float The rms of the image. If None: calculate the rms level (default). Otherwise assume a constant rms. ...
Estimate the background noise mean and RMS. The mean is estimated as the median of data. The RMS is estimated as the IQR of data / 1.34896. Parameters ---------- xmin, xmax, ymin, ymax : int The bounding region over which the bkg/rms will be calculated. Retu...
Load a fits file (bkg/rms/curve) and make sure that it is the same shape as the main image. Parameters ---------- image : :class:`AegeanTools.fits_image.FitsImage` The main image that has already been loaded. auxfile : str or HDUList The auxiliary file t...
Do island refitting (priorized fitting) on a group of islands. Parameters ---------- group : list A list of components grouped by island. stage : int Refitting stage. outerclip : float Ignored, placed holder for future development. ...
Take an Island, do all the parameter estimation and fitting. Parameters ---------- island_data : :class:`AegeanTools.models.IslandFittingData` The island to be fit. Returns ------- sources : list The sources that were fit. def _fit_island(self,...
Execute fitting on a list of islands This function just wraps around fit_island, so that when we do multiprocesing a single process will fit multiple islands before returning results. Parameters ---------- islands : list of :class:`AegeanTools.models.IslandFittingData` ...
Run the Aegean source finder. Parameters ---------- filename : str or HDUList Image filename or HDUList. hdu_index : int The index of the FITS HDU (extension). outfile : str file for printing catalog (NOT a table, just a text file of my own...
Take an input catalog, and image, and optional background/noise images fit the flux and ra/dec for each of the given sources, keeping the morphology fixed if doregroup is true the groups will be recreated based on a matching radius/probability. if doregroup is false then the islands of the inpu...
Determine whether a list of files are of a recognizable output type. Parameters ---------- files : str A list of file names Returns ------- result : bool True if *all* the file names are supported def check_table_formats(files): """ Determine whether a list of files ar...
Print a list of all the file formats that are supported for writing. The file formats are determined by their extensions. Returns ------- None def show_formats(): """ Print a list of all the file formats that are supported for writing. The file formats are determined by their extensions. ...
Modify the metadata dictionary. DATE, PROGRAM, and PROGVER are added/modified. Parameters ---------- meta : dict The dictionary to be modified, default = None (empty) Returns ------- An updated dictionary. def update_meta_data(meta=None): """ Modify the metadata dictio...
Save a catalogue of sources using filename as a model. Meta data can be written to some file types (fits, votable). Each type of source will be in a separate file: - base_comp.ext :class:`AegeanTools.models.OutputSource` - base_isle.ext :class:`AegeanTools.models.IslandSource` - base_simp.ext :cla...
Load a catalogue and extract the source positions (only) Parameters ---------- filename : str Filename to read. Supported types are csv, tab, tex, vo, vot, and xml. Returns ------- catalogue : list A list of [ (ra, dec), ...] def load_catalog(filename): """ Load a cata...
Load a table from a given file. Supports csv, tab, tex, vo, vot, xml, fits, and hdf5. Parameters ---------- filename : str File to read Returns ------- table : Table Table of data. def load_table(filename): """ Load a table from a given file. Supports csv, ta...
Write a table to a file. Parameters ---------- table : Table Table to be written filename : str Destination for saving table. Returns ------- None def write_table(table, filename): """ Write a table to a file. Parameters ---------- table : Table ...