skymodel
- class lsmtool.skymodel.SkyModel(fileName, beamMS=None, checkDup=False, VOPosition=None, VORadius=None)
Bases:
objectObject that stores the sky model and provides methods for accessing it.
- 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
Examples
Add a point source:
>>> source = {'Name':'src1', 'Type':'POINT', 'Ra':'12:32:10.1', 'Dec':'23.43.21.21', 'I':2.134} >>> s.add(source)
- 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',
- make_plots=True,
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) – Secondary sky model to compare to the parent sky modelradius (
floatorstr, optional) – Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for matchingoutDir (
str, optional) – Plots are saved to this directorylabelBy (
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 indexexcludeMultiple (
bool, optional) – If True, sources with multiple matches are excluded. If False, the nearest of the multiple matches will be used for comparisonexcludeByFlux (
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.make_plots (
bool, optional) – If True, the plots described above are made.
- 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 (
strorSkyModel) – Secondary sky model to concatenate with the parent sky modelmatchBy (
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 (
floatorstr, 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 columnunits (
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.ndarray) – 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 (
floatorstr) – RA of position to which the distance is desired (in degrees or makesourcedb format)Dec (
floatorstr) – Dec of position to which the distance is desired (in degrees or makesourcedb format)byPatch (
bool, optional) – Calculate distance by patches instead of by sourcesunits (
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, with duplicates removed.
Note: use getColValues(‘Patch’) if you want the patch names for each source in the sky model.
- Returns:
names (
numpy.ndarray) – 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 (
strorlist, optional) – List of patch names for which the positions are desiredasArray (
bool, optional) – If True, returns arrays of RA, Dec instead of a dictmethod (
Noneorstr, 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.ndarrayordict) – (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:
- Returns:
data (
numpy.ndarray) – 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 tableorrow) – 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,
- patchNames=None,
- weightBySize=False,
- numClusters=100,
- FWHM=None,
- threshold=0.1,
- applyBeam=False,
- root='Patch',
- pad_index=False,
- method='mid',
- facet='',
- byPatch=False,
- kernelSize=0.1,
- nIterations=100,
- lookDistance=0.2,
- groupingDistance=0.01,
Groups sources into patches.
- Parameters:
LSM (
SkyModel) – 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 named ‘source_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.
’voronoi’ => given a previously grouped sky model, Voronoi tesselate using the patch positions for patches above the target flux (specified by the targetFlux parameter) or whose names match the input names (specified by the patchNames parameter)
’meanshift’ => use the meanshift clustering algorithm
the filename of a mask image => group by masked regions (where mask = True). Sources outside of masked regions are given patches of their own
targetFlux (
strorfloat, optional) – Target flux for ‘tessellate’ (the total flux of each tile will be close to this value) and ‘voronoi’ algorithms. The target flux can be specified as either a float in Jy or as a string with units (e.g., ‘25.0 mJy’)patchNames (
list, optional) – List of patch names to use for the ‘voronoi’ algorithm. If both patchNames and targetFlux are given, the targetFlux selection is applied firstweightBySize (
bool, optional) – If True, fluxes are weighted by patch size (as median_size / size) when the targetFlux criterion is applied. Patches with sizes below the median (flux-weighted) size are upweighted and those above the mean are downweightednumClusters (
int, optional) – Number of clusters for clustering. Sources are grouped around the numClusters brightest sources.FWHM (
strorfloat, 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 thresholdingapplyBeam (
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 is used in the patch names. E.g., facet_patch_001 instead of facet_patch_1method (
Noneorstr, 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’ or ‘meanshift’ algorithms, use patches instead of sourceskernelSize (
float, optional) – Kernel size in degrees for ‘meanshift’ groupingnIterations (
int, optional) – Number of iterations for ‘meanshift’ groupinglookDistance (
float, optional) – Look distance in degrees for ‘meanshift’ groupinggroupingDistance (
float, optional) – Grouping distance in degrees for ‘meanshift’ grouping
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:
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,listofstr, optional) – Name of column or columns to print. If None, all columns are printedpatchName (
str,listofstr, optional) – If given, returns column values for specified patch or patches onlysourceName (
str,listofstr, optional) – If given, returns column value for specified source or sources onlysortBy (
strorlistofstr, 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 givenlowToHigh (
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) – Input sky modelname (
strorlist) – 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 argumentfitsFile (
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:
Examples
Plot and display to the screen:
>>> s.plot()
Plot and save to a PDF file:
>>> s.plot('sky_plot.pdf')
- rasterize(
- cellsize,
- fileRoot=None,
- writeRegionFile=False,
- clobber=False,
Rasterize the sky model to FITS images (one image per spectral term).
The resulting images can be used with DDECal in DP3 for prediction using IDG. If the sky model is grouped into contiguous patches, a ds9 region file defining the Voronoi patches can also written (this file is required for use with IDG predict).
Note: currently, when writing the FITS images, only sky models with LogarithmicSI = False are supported.
- Parameters:
cellsize (
float) – The cellsize in degrees for the output image.fileRoot (
str, optional) – Filename root for the output FITS images. The images will be named fileRoot + ‘_0.fits’, fileRoot + ‘_1.fits’, etc. (one for each spectral term in the sky model). If writeRegionFile is True, a ds9 region file is also written as fileRoot + ‘.reg’. If not given, the root is taken from the filename of the input sky model (with its extension, if any, removed), if available, and otherwise is set to ‘skymodel’writeRegionFile (
bool, optional) – If True and the sky model is grouped into contiguous patches, a ds9 region file defining the Voronoi patches will be written (this file is required for DDECal)clobber (
bool, optional) – If True, existing files are overwritten.
- 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, ornumpy.ndarray) –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.ndarray: 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 setaggregate=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, ornumpy.ndarray) –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.ndarray: The indices to filter on can be specified directly as a numpy array of row or patch indices such as:
np.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 select sources that lie in masked regions:
>>> s.select('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.ndarray, ordict) – 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 (
listornumpy.ndarrayofbool, 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 (
Noneorstr, 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.ndarray, ordict) – 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 (
listornumpy.ndarrayofbool, 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 (
strorSkyModel) – 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 (
floatorstr, 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,
- invertBeam=False,
- width=None,
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’
’facet’ (ds9 region file of Voronoi facets; model must have patches)
plus all other formats supported by the astropy.table package
clobber (
bool, optional) – If True, an existing file is overwritten.sortBy (
strorlistofstr, 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, fluxes will be adjusted for the beam before being written.invertBeam (
bool, optional) – If True, the beam correction is inverted (i.e., from apparent sky to true sky).width (
float, optional) – The width in degrees of the total extent of the output facet regions. Only used when format = ‘facet’. If not given, the width will be set to fully cover the extent of the model
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 (point sources are indicated by points and Gaussians by ellipses):
>>> s.write('sky.reg', format='ds9')
Write to a WSClean/ds9 facet region file (regions define Voronoi facets around patch positions):
>>> s.write('facets.reg', format='facet')
- lsmtool.skymodel.iteritems(d)
- lsmtool.skymodel.itervalues(d)