LSMTool Module Documentation¶
lsmtool module¶
The load() convenience function is used to load a sky model file into a SkyModel object.
-
lsmtool.
load
(fileName, beamMS=None, VOPosition=None, VORadius=None)¶ Loads a sky model from a file or VO service and returns a SkyModel object.
Parameters: - fileName : str
Input ASCII file from which the sky model is read (must respect the makesourcedb format), name of VO service to query (must be one of ‘WENSS’, ‘NVSS’, ‘TGSS’, or ‘GSM’), or dict (single source only)
- beamMS : str, optional
Measurement set from which the primary beam will be estimated. A column of attenuated Stokes I fluxes will be added to the table
- VOPosition : list of floats
A list specifying a new position as [RA, Dec] in either makesourcedb format (e.g., [‘12:23:43.21’, ‘+22.34.21.2’]) or in degrees (e.g., [123.2312, 23.3422]) for a cone search
- VORadius : float or str, optional
Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for cone search region in degrees
Returns: - SkyModel object
A SkyModel object that stores the sky model and provides methods for accessing it.
Examples
Load a sky model from a makesourcedb-formated file:
>>> import lsmtool >>> s = lsmtool.load('sky.model')
Load a sky model with a beam MS so that apparent fluxes will be available (in addition to intrinsic fluxes):
>>> s = lsmtool.load('sky.model', 'SB100.MS')
Load a sky model from the WENSS using all sources within 5 degrees of the position RA = 212.8352792, Dec = 52.202644:
>>> s = lsmtool.load('WENSS', VOPosition=[212.8352792, 52.202644], VOradius=5.0)
Load a sky model from a dictionary defining the source:
>>> source = {'Name':'src1', 'Type':'POINT', 'Ra':'12:32:10.1', 'Dec':'23.43.21.21', 'I':2.134} >>> s = lsmtool.load(source)
lsmtool.operations_lib module¶
-
lsmtool.operations_lib.
attenuate
(beamMS, fluxes, RADeg, DecDeg, timeIndx=0.5)¶ Returns flux attenuated by primary beam.
Parameters: - beamMS : str
Measurement set for which the beam model is made
- fluxes : list
List of fluxes to attenuate
- RADeg : list
List of RA values in degrees
- DecDeg : list
List of Dec values in degrees
- timeIndx : float (between 0 and 1), optional
Time as fraction of that covered by the beamMS for which the beam is calculated
Returns: - attFluxes : numpy array
-
lsmtool.operations_lib.
calculateSeparation
(ra1, dec1, ra2, dec2)¶ Returns angular separation between two coordinates (all in degrees).
Parameters: - ra1 : float or numpy array
RA of coordinate 1 in degrees
- dec1 : float or numpy array
Dec of coordinate 1 in degrees
- ra2 : float
RA of coordinate 2 in degrees
- dec2 : float
Dec of coordinate 2 in degrees
Returns: - separation : astropy Angle or numpy array
Angular separation in degrees
-
lsmtool.operations_lib.
makeWCS
(refRA, refDec, crdelt=None)¶ Makes simple WCS object.
Parameters: - refRA : float
Reference RA in degrees
- refDec : float
Reference Dec in degrees
- crdelt: float, optional
Delta in degrees for sky grid
Returns: - w : astropy.wcs.WCS object
A simple TAN-projection WCS object for specified reference position
-
lsmtool.operations_lib.
matchSky
(LSM1, LSM2, radius=0.1, byPatch=False, nearestOnly=False)¶ Matches two sky models by position.
Parameters: - LSM1 : SkyModel object
Sky model for which match indices are desired
- LSM2 : SkyModel object
Sky model to match against
- radius : float or str, optional
Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for matching when matchBy=’position’
- byPatch : bool, optional
If True, matching is done by patches
- nearestOnly : bool, optional
If True, only the nearest of multiple matches is returned
Returns: - matches1, matches2 : np.array, np.array
matches1 is the array of indices of LSM1 that have matches in LSM2 within the specified radius. matches2 is the array of indices of LSM2 for the same sources.
-
lsmtool.operations_lib.
radec2xy
(RA, Dec, refRA=None, refDec=None, crdelt=None)¶ Returns x, y for input ra, dec.
Note that the reference RA and Dec must be the same in calls to both radec2xy() and xy2radec() if matched pairs of (x, y) <=> (RA, Dec) are desired.
Parameters: - RA : list
List of RA values in degrees
- Dec : list
List of Dec values in degrees
- refRA : float, optional
Reference RA in degrees.
- refDec : float, optional
Reference Dec in degrees
- crdelt: float, optional
Delta in degrees for sky grid
Returns: - x, y : list, list
Lists of x and y pixel values corresponding to the input RA and Dec values
-
lsmtool.operations_lib.
xy2radec
(x, y, refRA=0.0, refDec=0.0, crdelt=None)¶ Returns x, y for input ra, dec.
Note that the reference RA and Dec must be the same in calls to both radec2xy() and xy2radec() if matched pairs of (x, y) <=> (RA, Dec) are desired.
Parameters: - x : list
List of x values in pixels
- y : list
List of y values in pixels
- refRA : float, optional
Reference RA in degrees
- refDec : float, optional
Reference Dec in degrees
- crdelt: float, optional
Delta in degrees for sky grid
Returns: - RA, Dec : list, list
Lists of RA and Dec values corresponding to the input x and y pixel values
lsmtool.skymodel module¶
-
class
lsmtool.skymodel.
SkyModel
(fileName, beamMS=None, checkDup=False, VOPosition=None, VORadius=None)¶ Bases:
object
Object that stores the sky model and provides methods for accessing it.
Methods
add
(colNamesVals)Add a source to the sky model. broadcast
()Sends the model to another application using SAMP. compare
(LSM2[, radius, outDir, labelBy, …])Compare two sky models. concatenate
(LSM2[, matchBy, radius, keep, …])Concatenate two sky models. copy
()Returns a copy of the sky model. getColNames
()Returns a list of all available column names. getColValues
(colName[, units, aggregate, …])Returns a numpy array of column values. getDefaultValues
()Returns dict of {colName:default} values for all columns with defaults. getDistance
(RA, Dec[, byPatch, units])Returns angular distance for each source or patch to specified position getPatchNames
()Returns array of all patch names in the sky model. getPatchPositions
([patchName, asArray, …])Returns arrays or a dict of patch positions (as {‘patchName’:(RA, Dec)}). getPatchSizes
([units, weight, applyBeam])Returns array of patch sizes. getRowIndex
(rowName)Returns index or indices for specified source or patch as a list. getRowValues
(rowName)Returns an astropy table or table row for specified source or patch. group
(algorithm[, targetFlux, numClusters, …])Groups sources into patches. info
()Prints information about the sky model. merge
(patches[, name])Merge two or more patches together. more
([colName, patchName, sourceName, …])Prints the sky model table to the screen with more-like commands. move
(name[, position, shift])Move or shift a source or sources. plot
([fileName, labelBy])Shows a simple plot of the sky model. remove
(filterExpression[, aggregate, …])Filters the sky model, removing all sources that meet the given expression. select
(filterExpression[, aggregate, …])Filters the sky model, keeping all sources that meet the given expression. setColValues
(colName, values[, mask, index])Sets column values. setDefaultValues
(colDict)Sets default column values. setPatchPositions
([patchDict, method, …])Sets the patch positions. setRowValues
(values[, mask, returnVerified])Sets values for a single row. transfer
(patchSkyModel[, matchBy, radius])Transfer patches from the input sky model. ungroup
()Removes all patches from the sky model. write
([fileName, format, clobber, sortBy, …])Writes the sky model to a file. -
add
(colNamesVals)¶ Add a source to the sky model.
Parameters: - colNamesVals : dict
A dictionary that specifies the column values for the source to be added
-
broadcast
()¶ Sends the model to another application using SAMP.
Both the SAMP hub and the receiving application must be running before the table is broadcasted. Examples of SMAP-aware applications are TOPCAT, Aladin, and ds9.
Examples
Send the model to TOPCAT. First, start TOPCAT, then run the command:
>>> s.broadcast()
TOPCAT should then load the table.
-
compare
(LSM2, radius='10 arcsec', outDir='.', labelBy=None, ignoreSpec=None, excludeMultiple=True, excludeByFlux=False, name1=None, name2=None, format='pdf')¶ Compare two sky models.
Comparison plots and a text file with statistics are written out to the an output directory. Plots are made for:
- flux ratio vs. radius from sky model center
- flux ratio vs. sky position
- flux ratio vs flux
- position offsets
- The following statistics are saved to ‘stats.txt’ in the output directory:
- mean and standard deviation of flux ratio
- mean and standard deviation of RA offsets
- mean and standard deviation of Dec offsets
These statistics are also returned as a dictionary.
Parameters: - LSM2 : SkyModel object
Secondary sky model to compare to the parent sky model
- radius : float or str, optional
Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for matching
- outDir : str, optional
Plots are saved to this directory
- labelBy : str, optional
One of ‘source’ or ‘patch’: label points using source names (‘source’) or patch names (‘patch’)
- ignoreSpec : float, optional
Ignore sources with this spectral index
- excludeMultiple : bool, optional
If True, sources with multiple matches are excluded. If False, the nearest of the multiple matches will be used for comparison
- excludeByFlux : bool, optional
If True, matches whose predicted fluxes differ from the parent model fluxes by 25% are excluded from the positional offset plot.
- name1 : str, optional
Name to use in the plots for the primary sky model. If None, ‘Model 1’ is used.
- name2 : str, optional
Name to use in the plots for LSM2. If None, ‘Model 2’ is used.
- format : str, optional
Format of plot files.
Returns: - stats : dict
Dict of statistics with the following keys (where the clipped values are after 3-sigma clipping):
- ‘meanRatio’
- ‘stdRatio’
- ‘meanRAOffsetDeg’
- ‘stdRAOffsetDeg’
- ‘meanDecOffsetDeg’
- ‘stdDecOffsetDeg’
- ‘meanClippedRatio’
- ‘stdClippedRatio’
- ‘meanClippedRAOffsetDeg’
- ‘stdClippedRAOffsetDeg’
- ‘meanClippedDecOffsetDeg’
- ‘stdClippedDecOffsetDeg’
Examples
Compare two sky models and save plots:
>>> LSM2 = lsmtool.load('sky2.model') >>> s.compare(LSM2, outDir='comparison_results/')
Compare a LOFAR sky model to a global sky model made from VLSS+TGSS+NVSS (where refRA and refDec are the approximate center of the LOFAR sky model coverage):
>>> LSM2 = lsmtool.load('GSM', VOPosition=[refRA, refDec], VORadius='5 deg') >>> s.compare(LSM2, radius='30 arcsec', excludeMultiple=True, outDir='comparison_results/', name1='LOFAR', name2='GSM', format='png')
-
concatenate
(LSM2, matchBy='name', radius=0.1, keep='all', inheritPatches=False)¶ Concatenate two sky models.
Parameters: - LSM2 : str or SkyModel object
Secondary sky model to concatenate with the parent sky model
- matchBy : str, optional
Determines how duplicate sources are determined: - ‘name’ => duplicates are identified by name - ‘position’ => duplicates are identified by radius. Sources within the
radius specified by the radius parameter are considered duplicates
- radius : float or str, optional
Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for matching when matchBy=’position’
- keep : str, optional
Determines how duplicates are treated: - ‘all’ => all duplicates are kept; those with identical names are re-
named
- ‘from1’ => duplicates kept are those from sky model 1 (the parent)
- ‘from2’ => duplicates kept are those from sky model 2 (the secondary)
- inheritPatches : bool, optional
If True, duplicates inherit the patch name from the parent sky model. If False, duplicates keep their own patch names.
Examples
Concatenate two sky models, identifying duplicates by matching to the source names. When duplicates are found, keep the source from the parent sky model and discard the duplicate from secondary sky model (this might be useful when merging two gsm.py sky models that have some overlap):
>>> LSM2 = lsmtool.load('gsm_sky2.model') >>> s.concatenate(LSM2, matchBy='name', keep='from1')
Concatenate two sky models, identifying duplicates by matching to the source positions within a radius of 10 arcsec. When duplicates are found, keep the source from the secondary sky model and discard the duplicate from the parent sky model (this might be useful when replacing parts of a low-resolution sky model with a high-resolution one):
>>> LSM2 = lsmtool.load('high_res_sky.model') >>> s.concatenate(LSM2, matchBy='position', radius=10.0/3600.0, keep='from2')
-
copy
()¶ Returns a copy of the sky model.
-
getColNames
()¶ Returns a list of all available column names.
Returns: - colNames : list
List of all column names
Examples
Get column names:
>>> s.getColNames()
-
getColValues
(colName, units=None, aggregate=None, applyBeam=False)¶ Returns a numpy array of column values.
Parameters: - colName : str
Name of column
- units : str, optional
Output units (the values are converted as needed). By default, the units are those used by makesourcedb, with the exception of RA and Dec which have default output units of degrees.
- aggregate : {‘sum’, ‘mean’, ‘wmean’, ‘min’, max’}, optional
If set, the array returned will be of values aggregated over the patch members. The following aggregation functions are available:
- ‘sum’: sum of patch values
- ‘mean’: mean of patch values
- ‘wmean’: Stokes-I-weighted mean of patch values
- ‘min’: minimum of patch values
- ‘max’: maximum of patch values
Note that, in some cases, certain aggregation functions will not produce meaningful results. For example, asking for the sum of the MajorAxis values per patch will not give a good indication of the size of the patch (to get the sizes, use the getPatchSizes() method). Additionally, applying the ‘mean’ or ‘wmean’ functions to the RA or Dec columns may give strange results near the poles or near RA = 0h. For aggregated RA and Dec values, use the getPatchPositions() method instead which projects the sources onto the image plane before aggregation.
- applyBeam : bool, optional
If True, fluxes will be attenuated by the beam. This attenuation also applies to fluxes used in aggregation functions.
Returns: - colValues : numpy array
Array of column values. None is returned if column is not found.
Examples
Get Stokes I fluxes in Jy:
>>> s.getColValues('I') array([ 60.4892, 1.2413, 1.216 , ..., 1.12 , 1.25 , 1.16 ])
Get Stokes I fluxes in mJy:
>>> s.getColValues('I', units='mJy') array([ 60489.2, 1241.3, 1216. , ..., 1120. , 1250. , 1160. ])
Get total Stokes I flux for the patches:
>>> s.getColValues('I', aggregate='sum') array([ 61.7305, 1.216 , 3.9793, ..., 1.12 , 1.25 , 1.16 ])
Get flux-weighted average RA and Dec for the patches. As noted above, the getColValues() method is not appropriate for use with RA or Dec, so we must use getPatchPositions() instead:
>>> RA, Dec = s.getPatchPositions(method='wmean', asArray=True)
-
getDefaultValues
()¶ Returns dict of {colName:default} values for all columns with defaults.
Returns: - defaultDict : dict
Dict of {colName:default} values
-
getDistance
(RA, Dec, byPatch=False, units=None)¶ Returns angular distance for each source or patch to specified position
Parameters: - RA : float or str
RA of position to which the distance is desired (in degrees or makesourcedb format)
- Dec : float or str
Dec of position to which the distance is desired (in degrees or makesourcedb format)
- byPatch : bool, optional
Calculate distance by patches instead of by sources
- units : str, optional
Units for resulting distance. If None, units are degrees
Returns: - dist : array
Array of distances
Examples
Find distance in degrees to a position for all sources:
>>> s.getDistance(94.0, 42.0)
Find distance in arcmin:
>>> s.getDistance(94.0, 42.0, units='arcmin')
Find distance to patch centers:
>>> s.setPatchPositions(method='mid') >>> s.getDistance(94.0, 42.0, byPatch=True)
-
getPatchNames
()¶ Returns array of all patch names in the sky model.
Returns: - names : numpy array
Array of patch names. None is returned if the sky model does not have patches
-
getPatchPositions
(patchName=None, asArray=False, method=None, applyBeam=False, perPatchProjection=True)¶ Returns arrays or a dict of patch positions (as {‘patchName’:(RA, Dec)}).
Parameters: - patchName : str or list, optional
List of patch names for which the positions are desired
- asArray : bool, optional
If True, returns arrays of RA, Dec instead of a dict
- method : None or str, optional
This parameter specifies the method used to calculate the patch positions. If None, the current patch positions stored in the sky model, if any, will be returned. - ‘mid’ => calculate the midpoint of the patch - ‘mean’ => calculate the mean RA and Dec of the patch - ‘wmean’ => calculate the flux-weighted mean RA and Dec of the patch - None => current patch positions are returned Note that the mid, mean, and wmean positions are calculated from TAN- projected values.
- applyBeam : bool, optional
If True, fluxes used as weights will be attenuated by the beam.
- perPatchProjection : bool, optional
If True, a different projection center is used per patch. If False, a single projection center is used for all patches.
Returns: - positions : numpy array or dict
(RA, Dec) arrays (if asArray is False) of patch positions or a dictionary of {‘patchName’:(RA, Dec)}.
Examples
Get the current patch positions:
>>> s.getPatchPositions() {'bin0': [<Angle 91.77565208333331 deg>, <Angle 41.57834805555555 deg>], 'bin1': [<Angle 91.59991874999997 deg>, <Angle 41.90387583333333 deg>], 'bin2': [<Angle 90.83773333333332 deg>, <Angle 42.189861944444445 deg>],
Get them as RA and Dec arrays in degrees:
>>> s.getPatchPositions(asArray=True) (array([ 91.77565208, 91.59991875, 90.83773333]), array([ 41.57834806, 41.90387583, 42.18986194]))
Calculate the flux-weighted mean positions of each patch:
>>> s.getPatchPositions(method='wmean', asArray=True)
-
getPatchSizes
(units=None, weight=False, applyBeam=False)¶ Returns array of patch sizes.
Parameters: - units : str, optional
Units for returned sizes (e.g., ‘arcsec’, ‘degree’)
- weight : bool, optional
If True, weight the source positions inside the patch by flux
- applyBeam : bool, optional
If True and weight is True, attenuate the fluxes used for weighting by the beam
Returns: - data : numpy array
Array of patch sizes. None is returned if the sky model does not have patches
-
getRowIndex
(rowName)¶ Returns index or indices for specified source or patch as a list.
Parameters: - rowName : str
Name of the source or patch
Returns: - indices : list
List of indices. ValueError is raised if the source is not found.
Examples
Get row index for the source ‘src1’:
>>> s.getRowIndex('src1') [0]
Get row indices for the patch ‘bin1’ and verify the patch name:
>>> ind = s.getRowIndex('bin1') >>> print(s.getColValues('patch')[ind]) ['bin1', 'bin1', 'bin1']
-
getRowValues
(rowName)¶ Returns an astropy table or table row for specified source or patch.
Parameters: - rowName : str
Name of the source or patch
Returns: - rowValues : astropy table or row
Table (if more than one source) or row (if one source). None is returned if source is not found.
Examples
Get row values for the source ‘src1’:
>>> rows = s.getRowValues('src1')
Sum over the fluxes of sources in the ‘bin1’ patch:
>>> tot = 0.0 >>> for row in s.getRowValues('bin1'): tot += row['I']
-
group
(algorithm, targetFlux=None, numClusters=100, FWHM=None, threshold=0.1, applyBeam=False, root='Patch', pad_index=False, method='mid', facet='', byPatch=False)¶ Groups sources into patches.
Parameters: - LSM : SkyModel object
Input sky model.
- algorithm : str
Algorithm to use for grouping: - ‘single’ => all sources are grouped into a single patch - ‘every’ => every source gets a separate patch - ‘cluster’ => SAGECAL clustering algorithm that groups sources into
specified number of clusters (specified by the numClusters parameter).
- ‘tessellate’ => group into tiles whose total flux approximates
- the target flux (specified by the targetFlux parameter).
- ‘threshold’ => group by convolving the sky model with a Gaussian beam
- and then thresholding to find islands of emission (NOTE: all sources are currently considered to be point sources of flux unity)
- ‘facet’ => group by facets using as an input a fits file. It requires
- the use of the additional parameter ‘facet’ to enter the name of the fits file (NOTE: This method is experimental).
- ‘voronoi’ => given a previously grouped sky model, voronoi tesselate
- using the patch positions
- the filename of a mask image => group by masked regions (where mask =
- True). Source outside of masked regions are given patches of their own.
- targetFlux : str or float, optional
Target flux for tessellation (the total flux of each tile will be close to this value). The target flux can be specified as either a float in Jy or as a string with units (e.g., ‘25.0 mJy’).
- numClusters : int, optional
Number of clusters for clustering. Sources are grouped around the numClusters brightest sources.
- FWHM : str or float, optional
FWHM of convolving Gaussian used for thresholding. The FWHM can be specified as either a float in degrees or as a string with units (e.g., ‘25.0 arcsec’)
- threshold : float, optional
Value between 0 and 1 above which emission is considered for thresholding
- applyBeam : bool, optional
If True, fluxes will be attenuated by the beam.
- root : str, optional
Root string from which patch names are constructed. For ‘single’, the patch name will be set to root; for the other grouping algorithms, the patch names will be ‘root_INDX’, where INDX is an integer ranging from (0:nPatches).
- pad_index : bool, optional
If True, pad the INDX used in the patch names. E.g., facet_patch_001 instead of facet_patch_1
- method : None or str, optional
This parameter specifies the method used to set the patch positions: - ‘mid’ => the position is set to the midpoint of the patch - ‘mean’ => the positions is set to the mean RA and Dec of the patch - ‘wmean’ => the position is set to the flux-weighted mean RA and Dec of the patch - ‘zero’ => set all positions to [0.0, 0.0]
- facet : str, optional
Facet fits file used with the algorithm ‘facet’
- byPatch : bool, optional
For the ‘tessellate’ algorithm, use patches instead of by sources
Examples
Tesselate the sky model into patches with approximately 30 Jy total flux:
>>> s.group('tessellate', targetFlux=30.0)
-
info
()¶ Prints information about the sky model.
-
merge
(patches, name=None)¶ Merge two or more patches together.
Parameters: - patches : list of str
List of patch names to merge
- name : str, optional
Name of resulting merged patch. If None, the merged patch uses the name of the first patch in the input patches list
Examples
Merge three patches into one named ‘binmerged’:
>>> s.merge(['bin0', 'bin1', 'bin2'], 'binmerged')
-
more
(colName=None, patchName=None, sourceName=None, sortBy=None, lowToHigh=False)¶ Prints the sky model table to the screen with more-like commands.
Parameters: - colName : str, list of str, optional
Name of column or columns to print. If None, all columns are printed
- patchName : str, list of str, optional
If given, returns column values for specified patch or patches only
- sourceName : str, list of str, optional
If given, returns column value for specified source or sources only
- sortBy : str or list of str, optional
Name of columns to sort on. If None, no sorting is done. If a list is given, sorting is done on the columns in the order given
- lowToHigh : bool, optional
If True, sort values from low to high instead of high to low
Examples
Print the entire model:
>>> s.more()
Print only the ‘Name’ and ‘I’ columns for the ‘bin0’ patch:
>>> s.more(['Name', 'I'], 'bin0', sortBy=['I'])
-
move
(name, position=None, shift=None)¶ Move or shift a source or sources.
If both a position and a shift are specified, a source is moved to the new position and then shifted. Note that only a single source can be moved to a new position. However, multiple sources can be shifted.
If an xyshift is specified, a FITS file must also be specified to define the WCS system. If a position, a shift, and an xyshift are all specified, a source is moved to the new position, shifted in RA and Dec, and then shifted in x and y.
Parameters: - LSM : SkyModel object
Input sky model
- name : str or list
Source name or list of names (can include wildcards)
- position : list, optional
A list specifying a new position as [RA, Dec] in either makesourcedb format (e.g., [‘12:23:43.21’, ‘+22.34.21.2’]) or in degrees (e.g., [123.2312, 23.3422])
- shift : list, optional
A list specifying the shift as [RAShift, DecShift] in degrees (e.g., [0.02312, 0.00342])
- xyshift : list, optional
A list specifying the shift as [xShift, yShift] in pixels. A FITS file must be specified with the fitsFILE argument
- fitsFile : str, optional
A FITS file from which to take WCS information to transform the pixel coordinates to RA and Dec values. The xyshift argument must be specfied for this to be useful
Examples
Move source ‘1609.6+6556’ to a new position:
>>> s.move('1609.6+6556', position=['16:10:00', '+65.57.00'])
Shift the source by 10 arcsec in Dec:
>>> s.move('1609.6+6556', shift=[0.0, 10.0/3600.0])
Shift all sources by 10 pixels in x:
>>> s.move('*', xyshift=[10, 0], fitsFile='image.fits')
-
plot
(fileName=None, labelBy=None)¶ Shows a simple plot of the sky model.
The circles in the plot are scaled with flux. If the sky model is grouped into patches, sources are colored by patch and the patch positions are indicated with stars.
Parameters: - fileName : str, optional
If given, the plot is saved to a file instead of displayed.
- labelBy : str, optional
One of ‘source’ or ‘patch’: label points using source names (‘source’) or patch names (‘patch’)
-
remove
(filterExpression, aggregate=None, applyBeam=None, useRegEx=False, force=True)¶ Filters the sky model, removing all sources that meet the given expression.
After filtering, the sky model contains only those sources for which the given filter expression is false.
Parameters: - filterExpression : str, dict, list, or numpy array
- If string:
A string specifying the filter expression in the form: ‘<property> <operator> <value> [<units>]’ (e.g., ‘I <= 10.5 Jy’).
- If dict:
The filter can also be given as a dictionary in the form: {‘filterProp’:property, ‘filterOper’:operator,
‘filterVal’:value, ‘filterUnits’:units}
- If list:
The filter can also be given as a list of: [property, operator, value] or [property, operator, value, units]
- If numpy array:
The indices to filter on can be specified directly as a numpy array of row or patch indices such as: array([ 0, 2, 19, 20, 31, 37])
or as a numpy array of bools with the same length as the sky model.
If a numpy array is given and the indices correspond to patches, then set aggregate=True.
- The property to filter on must be one of the following:
- a valid column name
- the filename of a mask image
- Supported operators are:
- !=
- <=
- >=
- >
- <
- = (or ‘==’)
Units are optional and must be specified as required by astropy.units.
- aggregate : str, optional
If set, the selection will be done on values aggregated over the patch members. The following aggregation functions are available: - ‘sum’: sum of patch values - ‘mean’: mean of patch values - ‘wmean’: Stokes I weighted mean of patch values - ‘min’: minimum of patch values - ‘max’: maximum of patch values - True: only valid when the filter indices are specified directly as a numpy array. If True, filtering is done on patches instead of sources.
- applyBeam : bool, optional
If True, apparent fluxes will be used.
- useRegEx : bool, optional
If True, string matching will use regular expression matching. If False, string matching uses Unix filename matching.
- force : bool, optional
If True, filters that result in empty sky models are allowed. If False, such filters are not applied and the sky model is unaffected.
Examples
Filter on column ‘I’ (Stokes I flux). This filter will remove all sources with Stokes I flux greater than 1.5 Jy:
>>> s.remove('I > 1.5 Jy') INFO: Removed 1102 sources.
If the sky model has patches and the filter is desired per patch, use
aggregate = function
. For example, to filter on the sum of the patch fluxes:>>> s.remove('I > 1.5 Jy', aggregate='sum')
Or, to filter on patches smaller than 5 arcmin in size:
>>> sizes = s.getPatchSizes(units='arcmin') >>> s.remove(sizes < 5.0, aggregate=True)
Filter on source names, removing those that match “src*_1?” (e.g., ‘src2345_15’, ‘srcB2_1a’, etc.):
>>> s.remove('Name == src*_1?')
Use a CASA clean mask image named ‘clean_mask.mask’ to remove sources that lie in masked regions:
>>> s.remove('clean_mask.mask == True')
-
select
(filterExpression, aggregate=None, applyBeam=False, useRegEx=False, force=True)¶ Filters the sky model, keeping all sources that meet the given expression.
After filtering, the sky model contains only those sources for which the given filter expression is true.
Parameters: - filterExpression : str, dict, list, or numpy array
- If string:
A string specifying the filter expression in the form: ‘<property> <operator> <value> [<units>]’ (e.g., ‘I <= 10.5 Jy’).
- If dict:
The filter can also be given as a dictionary in the form: {‘filterProp’:property, ‘filterOper’:operator,
‘filterVal’:value, ‘filterUnits’:units}
- If list:
The filter can also be given as a list of: [property, operator, value] or [property, operator, value, units]
- If numpy array:
The indices to filter on can be specified directly as a numpy array of row or patch indices such as: array([ 0, 2, 19, 20, 31, 37])
or as a numpy array of bools with the same length as the sky model.
If a numpy array is given and the indices correspond to patches, then set aggregate=True.
- The property to filter on must be one of the following:
- a valid column name
- the filename of a mask image
- Supported operators are:
- !=
- <=
- >=
- >
- <
- = (or ‘==’)
Units are optional and must be specified as required by astropy.units.
- aggregate : str, optional
If set, the selection will be done on values aggregated over the patch members. The following aggregation functions are available:
- ‘sum’: sum of patch values
- ‘mean’: mean of patch values
- ‘wmean’: Stokes I weighted mean of patch values
- ‘min’: minimum of patch values
- ‘max’: maximum of patch values
- True: only valid when the filter indices are specified directly
as a numpy array. If True, filtering is done on patches instead of sources.
- applyBeam : bool, optional
If True, apparent fluxes will be used.
- useRegEx : bool, optional
If True, string matching will use regular expression matching. If False, string matching uses Unix filename matching.
- force : bool, optional
If True, selections that result in empty sky models are allowed. If False, such selections are not applied and the sky model is unaffected.
Examples
Filter on column ‘I’ (Stokes I flux). This filter will select all sources with Stokes I flux greater than 1.5 Jy:
>>> s.select('I > 1.5 Jy') INFO: Kept 1102 sources.
If the sky model has patches and the filter is desired per patch, use
aggregate = function
. For example, to select on the sum of the patch fluxes:>>> s.select('I > 1.5 Jy', aggregate='sum')
Or, to filter on patches smaller than 5 arcmin in size:
>>> sizes = s.getPatchSizes(units='arcmin') >>> s.select(sizes < 5.0, aggregate=True)
Filter on source names, keeping those that match “src*_1?”:
>>> s.select('Name == src*_1?')
Use a CASA clean mask image named ‘clean_mask.mask’ to remove sources that lie in masked regions:
>>> s.filter('clean_mask.mask == True')
-
setColValues
(colName, values, mask=None, index=None)¶ Sets column values.
Parameters: - colName : str
Name of column. If not already present in the table, a new column will be created.
- values : list, numpy array, or dict
Array of values or dict of {sourceName:value} pairs. If list or array, the length must match the number of rows in the table. If dict, missing values will be masked unless already present. Values are assumed to be in units required by makesourcedb.
- mask : list or array of bools, optional
If values is a list or array, a mask can be specified (True means the value is masked).
- index : int, optional
Index that specifies the column position in the table, if column is not already present in the table.
Examples
Set Stokes I fluxes:
>>> s.setColValues('I', [1.0, 1.1, 1.2, 0.0, 1.3], mask=[False, False, False, True, False])
-
setDefaultValues
(colDict)¶ Sets default column values.
Parameters: - colDict : dict
Dict specifying column names and default values as {‘colName’:value} where the value is in the units accepted by makesourcedb (e.g., Hz for ‘ReferenceFrequency’).
Examples
Set new default value for ReferenceFrequency:
>>> s.setDefaultValues({'ReferenceFrequency': 140e6})
-
setPatchPositions
(patchDict=None, method='mid', applyBeam=False, perPatchProjection=True)¶ Sets the patch positions.
Parameters: - patchDict : dict, optional
Dict specifying patch names and positions as {‘patchName’:[RA, Dec]} where both RA and Dec are degrees J2000 or in makesourcedb format. If None, positions are set for all patches using the method given by the ‘method’ parameter.
- method : None or str, optional
If no patchDict is given, this parameter specifies the method used to set the patch positions: - ‘mid’ => the position is set to the midpoint of the patch - ‘mean’ => the position is set to the mean RA and Dec of the patch - ‘wmean’ => the position is set to the flux-weighted mean RA and Dec of the patch - ‘zero’ => set all positions to [0.0, 0.0]
Note that the mid, mean, and wmean positions are calculated from TAN- projected values.
- applyBeam : bool, optional
If True, fluxes used as weights will be attenuated by the beam.
- perPatchProjection : bool, optional
If True, a different projection center is used per patch. If False, a single projection center is used for all patches.
Examples
Set all patch positions to their (projected) midpoints:
>>> s.setPatchPositions()
Set all patch positions to their (projected) flux-weighted mean positions:
>>> s.setPatchPositions(method='wmean')
Set new position for the ‘bin0’ patch only:
>>> s.setPatchPositions({'bin0': [123.231, 23.4321]})
-
setRowValues
(values, mask=None, returnVerified=False)¶ Sets values for a single row.
If a row with the given name already exists, its values are updated. If not, a new row is made and appended to the table.
Parameters: - values : list, numpy array, or dict
Array of values or dict of {colName:value} pairs. If list or array, the length must match the number and order of the columns in the table. If dict, missing values will be masked unless already present.
- mask : list or array of bools, optional
If values is a list or array, a mask can be specified (True means the value is masked).
- returnVerified : bool, optional
If True, the values are verified and returned, allowing them to be passed to table.add_row().
Examples
Set row values for the source ‘src1’ (which can be a new source or an existing source):
>>> s.setRowValues({'Name':'src1', 'Ra':213.123, 'Dec':23.1232, 'I':23.2, 'Type':'POINT'})
The RA and Dec values can be in degrees (as above) or in makesourcedb format. E.g.:
>>> s.setRowValues({'Name':'src1', 'Ra':'12:22:21.1', 'Dec':'+14.46.31.5', 'I':23.2, 'Type':'POINT'})
-
transfer
(patchSkyModel, matchBy='name', radius=0.1)¶ Transfer patches from the input sky model.
Sources matching those in patchSkyModel will be grouped into the patches defined in patchSkyModel. Sources that do not appear in patchSkyModel will be placed into separate patches (one per source). Patch positions are not transferred (as they may no longer be appropriate after transfer).
Parameters: - patchSkyModel : str or SkyModel object
Input sky model from which to transfer patches.
- matchBy : str, optional
Determines how matching sources are determined: - ‘name’ => matches are identified by name - ‘position’ => matches are identified by radius. Sources within the
radius specified by the radius parameter are considered matches
- radius : float or str, optional
Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for matching when matchBy=’position’
Examples
Transfer patches from one sky model to another and set their positions (matching sources are identified by name):
>>> s.transfer('master_sky.model') >>> s.setPatchPositions(method='mid')
-
ungroup
()¶ Removes all patches from the sky model.
Examples
Remove all patches:
>>> s.ungroup()
-
write
(fileName=None, format='makesourcedb', clobber=False, sortBy=None, lowToHigh=False, addHistory=True, applyBeam=False)¶ Writes the sky model to a file.
Parameters: - filename : str
Name of output file.
- format: str, optional
- Format of the output file. Allowed formats are:
- ‘makesourcedb’ (BBS format)
- ‘fits’
- ‘votable’
- ‘hdf5’
- ‘ds9’
- ‘kvis’
- ‘casa’
- ‘factor’
- plus all other formats supported by the astropy.table package
- clobber : bool, optional
If True, an existing file is overwritten.
- sortBy : str or list of str, optional
Name of columns to sort on. If None, no sorting is done. If a list is given, sorting is done on the columns in the order given.
- lowToHigh : bool, optional
If True, sort values from low to high instead of high to low.
- addHistory : bool, optional
If True, the history of operations is written to the sky model header.
- applyBeam : bool, optional
If True, apparent fluxes will be written.
Examples
Write the model to a makesourcedb sky model file suitable for use with BBS:
>>> s.write('modsky.model')
Write to a fits catalog:
>>> s.write('sky.fits', format='fits')
Write to a ds9 region file:
>>> s.write('sky.reg', format='ds9')
-
-
lsmtool.skymodel.
iteritems
(d)¶
-
lsmtool.skymodel.
itervalues
(d)¶
lsmtool.tableio module¶
-
lsmtool.tableio.
Dec2Angle
(Dec)¶ Returns Angle objects for input Dec values.
Parameters: - Dec : str, float or list of str, float
Values of Dec to convert. Can be strings in makesourcedb format or floats in degrees
Returns: - DecAngle : astropy.coordinates.Angle object
-
lsmtool.tableio.
RA2Angle
(RA)¶ Returns Angle objects for input RA values.
Parameters: - RA : str, float or list of str, float
Values of RA to convert. Can be strings in makesourcedb format or floats in degrees.
Returns: - RAAngle : astropy.coordinates.Angle object
-
lsmtool.tableio.
broadcastTable
(fileName)¶ Sends a table via SAMP.
Parameters: - fileName : str
Name of sky model file to broadcast
-
lsmtool.tableio.
casaRegionWriter
(table, fileName)¶ Writes model to a casa region file.
Parameters: - table : astropy.table.Table object
Input sky model table
- fileName : str
Output file to which the sky model is written
-
lsmtool.tableio.
coneSearch
(VOService, position, radius)¶ Returns table from a VO cone search.
Parameters: - VOService : str
Name of VO service to query (must be one of ‘WENSS’ or ‘NVSS’)
- position : list of floats
A list specifying a new position as [RA, Dec] in either makesourcedb format (e.g., [‘12:23:43.21’, ‘+22.34.21.2’]) or in degrees (e.g., [123.2312, 23.3422])
- radius : float or str, optional
Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for cone search region in degrees
-
lsmtool.tableio.
createTable
(outlines, metaDict, colNames, colDefaults)¶ Creates an astropy table from inputs.
Parameters: - outlines : list of str
Input lines
- metaDict : dict
Input meta data
- colNames : list of str
Input column names
- colDefaults : list
Input column default values
Returns: - table : astropy.table.Table object
-
lsmtool.tableio.
ds9RegionWriter
(table, fileName)¶ Writes table to a ds9 region file.
Parameters: - table : astropy.table.Table object
Input sky model table
- fileName : str
Output file to which the sky model is written
-
lsmtool.tableio.
factorDirectionsWriter
(table, fileName)¶ Writes patches to a Factor directions file.
Note that Factor respects the order of patches and they are sorted here by apparent flux from brightest to faintest.
Parameters: - table : astropy.table.Table object
Input sky model table; must have patches defined
- fileName : str
Output file to which the sky model is written
-
lsmtool.tableio.
getGSM
(position, radius)¶ Returns the file name from a GSM search.
Parameters: - position : list of floats
A list specifying a new position as [RA, Dec] in either makesourcedb format (e.g., [‘12:23:43.21’, ‘+22.34.21.2’]) or in degrees (e.g., [123.2312, 23.3422])
- radius : float or str, optional
Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for cone search region in degrees
-
lsmtool.tableio.
getTGSS
(position, radius)¶ Returns the file name from a TGSS search.
Parameters: - position : list of floats
A list specifying a new position as [RA, Dec] in either makesourcedb format (e.g., [‘12:23:43.21’, ‘+22.34.21.2’]) or in degrees (e.g., [123.2312, 23.3422])
- radius : float or str, optional
Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for cone search region in degrees
-
lsmtool.tableio.
iteritems
(d)¶
-
lsmtool.tableio.
itervalues
(d)¶
-
lsmtool.tableio.
kvisAnnWriter
(table, fileName)¶ Writes table to a kvis annotation file.
Parameters: - table : astropy.table.Table object
Input sky model table
- fileName : str
Output file to which the sky model is written
-
lsmtool.tableio.
makeEmptyTable
()¶ Returns an empty sky model table.
-
lsmtool.tableio.
processFormatString
(formatString)¶ Proccesses the header string.
Parameters: - formatString : str
Header line
Returns: - colNames : list of str
Output column names
- hasPatches : bool
Flag for patches
- colDefaults : dict
Default values
- metaDict : dict
Output meta data
-
lsmtool.tableio.
processLine
(line, metaDict, colNames)¶ Processes a makesourcedb line.
Parameters: - line : str
Data line
- metaDict : dict
Input meta data
- colNames : list of str
Input column names
Returns: - line : str
Processed line
- metaDict : dict
Output meta data
-
lsmtool.tableio.
rowStr
(row, metaDict)¶ Returns makesourcedb representation of a row.
Parameters: - row : astropy.table.Row object
Row to process
- metaDict : dict
Table meta dictionary
Returns: - line : str
Sting representing a row in a makesourcedb sky model file
-
lsmtool.tableio.
skyModelIdentify
(origin, *args, **kwargs)¶ Identifies valid makesourcedb sky model files.
-
lsmtool.tableio.
skyModelReader
(fileName)¶ Reads a makesourcedb sky model file into an astropy table.
See http://www.lofar.org/operations/doku.php?id=engineering:software:tools:makesourcedb#format_string for details. Note that source names, types, and patch names are limited to a length of 100 characters.
Parameters: - fileName : str
Input ASCII file from which the sky model is read. Must respect the makesourcedb format
Returns: - table : astropy.table.Table object
-
lsmtool.tableio.
skyModelWriter
(table, fileName)¶ Writes table to a makesourcedb sky model file.
Parameters: - fileName : str
Output ASCII file to which the sky model is written