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:
fileNamestr

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)

beamMSstr, optional

Measurement set from which the primary beam will be estimated. A column of attenuated Stokes I fluxes will be added to the table

VOPositionlist 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

VORadiusfloat 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.apply_beam(RA, Dec, spectralIndex, flux, referenceFrequency, beamMS, time, ant1, numchannels, startfreq, channelwidth, invert)

Worker function for attenuate() that applies the beam to a single flux

Parameters:
RAfloat

RA value in degrees

Decfloat

Dec value in degrees

spectralIndexfloat

Spectral index to adjust

fluxlist

Flux to attenuate

referenceFrequencyfloat

Reference frequency of polynomial fit

beamMSstr

Measurement set for which the beam model is made

timefloat

Time to calculate beam (in MJD seconds)

ant1int

Station index

numchannelsint

Number of channels

startfreqfloat

Start frequency in Hz

channelwidthfloat

Channel with in Hz

invertbool

If True, invert the beam (i.e. to un-attenuate the flux)

Returns:
attFluxfloat

Attenuated flux

adjSpectralIndexfloat

Adjusted spectral index. Returned only if spectralIndex is not None

lsmtool.operations_lib.apply_beam_star(inputs)

Simple multiprocessing helper function for apply_beam()

lsmtool.operations_lib.attenuate(beamMS, fluxes, RADeg, DecDeg, spectralIndex=None, referenceFrequency=None, timeIndx=0.5, invert=False)

Returns flux attenuated by primary beam.

Note: the attenuation is approximated using the array factor beam from the first station in the beam MS only (and it is assumed that this station is at LOFAR core). This approximation has been found to produce reasonable results for a typical LOFAR observation but may not work well for atypical observations.

Parameters:
beamMSstr

Measurement set for which the beam model is made

fluxeslist

List of fluxes to attenuate

RADeglist

List of RA values in degrees

DecDeglist

List of Dec values in degrees

spectralIndexlist, optional

List of spectral indices to adjust

referenceFrequencylist, optional

List of reference frequency of polynomial fit

timeIndxfloat (between 0 and 1), optional

Time as fraction of that covered by the beamMS for which the beam is calculated

invertbool, optional

If True, invert the beam (i.e. to un-attenuate the flux)

Returns:
attFluxesnumpy array

Attenuated fluxes

adjSpectralIndexnumpy array

Adjusted spectral indices. Returned only if spectralIndex is not None

lsmtool.operations_lib.calculateSeparation(ra1, dec1, ra2, dec2)

Returns angular separation between two coordinates (all in degrees).

Parameters:
ra1float or numpy array

RA of coordinate 1 in degrees

dec1float or numpy array

Dec of coordinate 1 in degrees

ra2float

RA of coordinate 2 in degrees

dec2float

Dec of coordinate 2 in degrees

Returns:
separationastropy Angle or numpy array

Angular separation in degrees

lsmtool.operations_lib.gaussian_fcn(g, x1, x2, const=False)

Evaluate a Gaussian on the given grid.

Parameters:
g: list

List of Gaussian parameters: [peak_flux, xcen, ycen, FWHMmaj, FWHMmin, PA_E_of_N]

x1, x2: grid (as produced by numpy.mgrid)

Grid coordinates on which to evaluate the Gaussian

constbool, optional

If True, all values are set to the peak_flux

Returns:
imgarray

Image of Gaussian

lsmtool.operations_lib.getFluxAtSingleFrequency(LSM, targetFreq=None, aggregate=None)

Returns flux density at given target frequency, adjusted according to the spectral index.

Parameters:
LSMsky model object

RA of coordinate 1 in degrees

targetFreqfloat, optional

Frequency in Hz. If None, the median is used

aggregatestr, optional

Aggregation to use

Returns:
fluxesnumpy array

Flux densities in Jy

lsmtool.operations_lib.makeWCS(refRA, refDec, crdelt=None)

Makes simple WCS object.

Parameters:
refRAfloat

Reference RA in degrees

refDecfloat

Reference Dec in degrees

crdelt: float, optional

Delta in degrees for sky grid

Returns:
wastropy.wcs.WCS object

A simple TAN-projection WCS object for specified reference position

lsmtool.operations_lib.make_template_image(image_name, reference_ra_deg, reference_dec_deg, reference_freq, ximsize=512, yimsize=512, cellsize_deg=0.000417, fill_val=0)

Make a blank image and save it to disk

Parameters:
image_namestr

Filename of output image

reference_ra_degfloat

RA for center of output image

reference_dec_degfloat

Dec for center of output image

reference_freqfloat

Ref freq of output image

ximsizeint, optional

Size of output image

yimsizeint, optional

Size of output image

cellsize_degfloat, optional

Size of a pixel in degrees

fill_valint, optional

Value with which to fill the image

lsmtool.operations_lib.matchSky(LSM1, LSM2, radius=0.1, byPatch=False, nearestOnly=False)

Matches two sky models by position.

Parameters:
LSM1SkyModel object

Sky model for which match indices are desired

LSM2SkyModel object

Sky model to match against

radiusfloat or str, optional

Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for matching when matchBy=’position’

byPatchbool, optional

If True, matching is done by patches

nearestOnlybool, optional

If True, only the nearest of multiple matches is returned

Returns:
matches1, matches2np.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.normalize_dec(ang)

Normalize Dec to be in the range [-90, 90].

Based on https://github.com/phn/angles/blob/master/angles.py

Parameters:
angfloat or astropy.coordinates.Angle

The Dec in degrees to be normalized.

Returns:
resfloat

Dec in degrees in the range [-90, 90].

lsmtool.operations_lib.normalize_ra(ang)

Normalize RA to be in the range [0, 360).

Based on https://github.com/phn/angles/blob/master/angles.py

Parameters:
angfloat or astropy.coordinates.Angle

The RA in degrees to be normalized.

Returns:
resfloat

RA in degrees in the range [0, 360).

lsmtool.operations_lib.polynomial(stokesI, coeff, nu)
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:
RAlist

List of RA values in degrees

Declist

List of Dec values in degrees

refRAfloat, optional

Reference RA in degrees.

refDecfloat, optional

Reference Dec in degrees

crdelt: float, optional

Delta in degrees for sky grid

Returns:
x, ylist, list

Lists of x and y pixel values corresponding to the input RA and Dec values

lsmtool.operations_lib.radec_to_xyz(ra, dec, time)

Convert RA and Dec coordinates to ITRS coordinates for LOFAR observations.

Note: the location adopted for LOFAR is that of the core, so the returned ITRS coordinates will be less accurate for stations outside of the core.

Parameters:
raastropy.coordinates.Angle

Right ascension

dec: astropy.coordinates.Angle

Declination

time: float

MJD time in seconds

Returns:
pointing_xyz: array

NumPy array containing the ITRS X, Y and Z coordinates

lsmtool.operations_lib.tessellate(ra_cal, dec_cal, ra_mid, dec_mid, width)

Makes a Voronoi tessellation and returns the resulting facet centers and polygons

Parameters:
ra_calarray

RA values in degrees of calibration directions

dec_calarray

Dec values in degrees of calibration directions

ra_midfloat

RA in degrees of bounding box center

dec_midfloat

Dec in degrees of bounding box center

widthfloat

Width of bounding box in degrees

Returns:
facet_points, facet_polyslist of tuples, list of arrays

List of facet points (centers) as (RA, Dec) tuples in degrees and list of facet polygons (vertices) as [RA, Dec] arrays in degrees (each of shape N x 2, where N is the number of vertices in a given facet)

lsmtool.operations_lib.voronoi(cal_coords, bounding_box)

Produces a Voronoi tessellation for the given coordinates and bounding box

Parameters:
cal_coordsarray

Array of x, y coordinates

bounding_boxarray

Array defining the bounding box as [minx, maxx, miny, maxy]

Returns:
vorVoronoi object

The resulting Voronoi object

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:
xlist

List of x values in pixels

ylist

List of y values in pixels

refRAfloat, optional

Reference RA in degrees

refDecfloat, optional

Reference Dec in degrees

crdelt: float, optional

Delta in degrees for sky grid

Returns:
RA, Declist, 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, with duplicates removed.

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, patchNames, ...])

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.

rasterize(cellsize[, fileRoot, ...])

Rasterize the sky model to FITS images (one image per spectral term).

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:
colNamesValsdict

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', 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:
LSM2SkyModel object

Secondary sky model to compare to the parent sky model

radiusfloat or str, optional

Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for matching

outDirstr, optional

Plots are saved to this directory

labelBystr, optional

One of ‘source’ or ‘patch’: label points using source names (‘source’) or patch names (‘patch’)

ignoreSpecfloat, optional

Ignore sources with this spectral index

excludeMultiplebool, optional

If True, sources with multiple matches are excluded. If False, the nearest of the multiple matches will be used for comparison

excludeByFluxbool, optional

If True, matches whose predicted fluxes differ from the parent model fluxes by 25% are excluded from the positional offset plot.

name1str, optional

Name to use in the plots for the primary sky model. If None, ‘Model 1’ is used.

name2str, optional

Name to use in the plots for LSM2. If None, ‘Model 2’ is used.

formatstr, optional

Format of plot files.

make_plotsbool, optional

If True, the plots described above are made.

Returns:
statsdict

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:
LSM2str or SkyModel object

Secondary sky model to concatenate with the parent sky model

matchBystr, 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

radiusfloat or str, optional

Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for matching when matchBy=’position’

keepstr, 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)

inheritPatchesbool, 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:
colNameslist

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:
colNamestr

Name of column

unitsstr, 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.

applyBeambool, optional

If True, fluxes will be attenuated by the beam. This attenuation also applies to fluxes used in aggregation functions.

Returns:
colValuesnumpy 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:
defaultDictdict

Dict of {colName:default} values

getDistance(RA, Dec, byPatch=False, units=None)

Returns angular distance for each source or patch to specified position

Parameters:
RAfloat or str

RA of position to which the distance is desired (in degrees or makesourcedb format)

Decfloat or str

Dec of position to which the distance is desired (in degrees or makesourcedb format)

byPatchbool, optional

Calculate distance by patches instead of by sources

unitsstr, optional

Units for resulting distance. If None, units are degrees

Returns:
distarray

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:
namesnumpy 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:
patchNamestr or list, optional

List of patch names for which the positions are desired

asArraybool, optional

If True, returns arrays of RA, Dec instead of a dict

methodNone 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.

applyBeambool, optional

If True, fluxes used as weights will be attenuated by the beam.

perPatchProjectionbool, optional

If True, a different projection center is used per patch. If False, a single projection center is used for all patches.

Returns:
positionsnumpy 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:
unitsstr, optional

Units for returned sizes (e.g., ‘arcsec’, ‘degree’)

weightbool, optional

If True, weight the source positions inside the patch by flux

applyBeambool, optional

If True and weight is True, attenuate the fluxes used for weighting by the beam

Returns:
datanumpy 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:
rowNamestr

Name of the source or patch

Returns:
indiceslist

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:
rowNamestr

Name of the source or patch

Returns:
rowValuesastropy 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, 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:
LSMSkyModel object

Input sky model.

algorithmstr

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

targetFluxstr or float, 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’)

patchNameslist, optional

List of patch names to use for the ‘voronoi’ algorithm. If both patchNames and targetFlux are given, the targetFlux selection is applied first

weightBySizebool, 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 downweighted

numClustersint, optional

Number of clusters for clustering. Sources are grouped around the numClusters brightest sources.

FWHMstr 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’)

thresholdfloat, optional

Value between 0 and 1 above which emission is considered for thresholding

applyBeambool, optional

If True, fluxes will be attenuated by the beam.

rootstr, 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_indexbool, optional

If True, pad the INDX is used in the patch names. E.g., facet_patch_001 instead of facet_patch_1

methodNone 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]

facetstr, optional

Facet fits file used with the algorithm ‘facet’

byPatchbool, optional

For the ‘tessellate’ or ‘meanshift’ algorithms, use patches instead of sources

kernelSizefloat, optional

Kernel size in degrees for ‘meanshift’ grouping

nIterationsint, optional

Number of iterations for ‘meanshift’ grouping

lookDistancefloat, optional

Look distance in degrees for ‘meanshift’ grouping

groupingDistancefloat, 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:
patcheslist of str

List of patch names to merge

namestr, 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:
colNamestr, list of str, optional

Name of column or columns to print. If None, all columns are printed

patchNamestr, list of str, optional

If given, returns column values for specified patch or patches only

sourceNamestr, list of str, optional

If given, returns column value for specified source or sources only

sortBystr 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

lowToHighbool, 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:
LSMSkyModel object

Input sky model

namestr or list

Source name or list of names (can include wildcards)

positionlist, 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])

shiftlist, optional

A list specifying the shift as [RAShift, DecShift] in degrees (e.g., [0.02312, 0.00342])

xyshiftlist, optional

A list specifying the shift as [xShift, yShift] in pixels. A FITS file must be specified with the fitsFILE argument

fitsFilestr, 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:
fileNamestr, optional

If given, the plot is saved to a file instead of displayed.

labelBystr, optional

One of ‘source’ or ‘patch’: label points using source names (‘source’) or patch names (‘patch’)

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:
cellsizefloat

The cellsize in degrees for the output image.

fileRootstr, 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’

writeRegionFilebool, 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)

clobberbool, 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:
filterExpressionstr, 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.

aggregatestr, 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.

applyBeambool, optional

If True, apparent fluxes will be used.

useRegExbool, optional

If True, string matching will use regular expression matching. If False, string matching uses Unix filename matching.

forcebool, 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:
filterExpressionstr, 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.

aggregatestr, 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.

applyBeambool, optional

If True, apparent fluxes will be used.

useRegExbool, optional

If True, string matching will use regular expression matching. If False, string matching uses Unix filename matching.

forcebool, 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:
colNamestr

Name of column. If not already present in the table, a new column will be created.

valueslist, 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.

masklist or array of bools, optional

If values is a list or array, a mask can be specified (True means the value is masked).

indexint, 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:
colDictdict

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:
patchDictdict, 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.

methodNone 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.

applyBeambool, optional

If True, fluxes used as weights will be attenuated by the beam.

perPatchProjectionbool, 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:
valueslist, 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.

masklist or array of bools, optional

If values is a list or array, a mask can be specified (True means the value is masked).

returnVerifiedbool, 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:
patchSkyModelstr or SkyModel object

Input sky model from which to transfer patches.

matchBystr, 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

radiusfloat 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, invertBeam=False, adjustSI=False, width=None)

Writes the sky model to a file.

Parameters:
filenamestr

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

clobberbool, optional

If True, an existing file is overwritten.

sortBystr 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.

lowToHighbool, optional

If True, sort values from low to high instead of high to low.

addHistorybool, optional

If True, the history of operations is written to the sky model header.

applyBeambool, optional

If True, fluxes will be adjusted for the beam before being written.

invertBeambool, optional

If True, the beam correction is inverted (i.e., from apparent sky to true sky).

adjustSIbool, optional

If True, adjust the spectral index column for the beam (only works if the spectral index in non-logarithmic. I.e., the ‘LogarithmicSI’ column entries are all False)

widthfloat, 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)

lsmtool.tableio module

lsmtool.tableio.Dec2Angle(Dec)

Returns Angle objects for input Dec values.

Parameters:
Decstr, float or list of str, float

Values of Dec to convert. Can be strings in makesourcedb format or floats in degrees

Returns:
DecAngleastropy.coordinates.Angle object
lsmtool.tableio.RA2Angle(RA)

Returns Angle objects for input RA values.

Parameters:
RAstr, float or list of str, float

Values of RA to convert. Can be strings in makesourcedb format or floats in degrees.

Returns:
RAAngleastropy.coordinates.Angle object
lsmtool.tableio.broadcastTable(fileName)

Sends a table via SAMP.

Parameters:
fileNamestr

Name of sky model file to broadcast

lsmtool.tableio.casaRegionWriter(table, fileName)

Writes model to a casa region file.

Parameters:
tableastropy.table.Table object

Input sky model table

fileNamestr

Output file to which the sky model is written

lsmtool.tableio.coneSearch(VOService, position, radius)

Returns table from a VO cone search.

Parameters:
VOServicestr

Name of VO service to query (must be one of ‘WENSS’ or ‘NVSS’)

positionlist of floats

A list specifying a 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])

radiusfloat or str, optional

Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for cone search region

lsmtool.tableio.convertExternalTable(table, columnMapping, fluxUnits='mJy')

Converts an external table.

Parameters:
tableTable

External table to convert

columnMappingdict

Dict that defines the column name mapping from external table

fluxUnitsstr, optional

Units of flux density in external table

lsmtool.tableio.createTable(outlines, metaDict, colNames, colDefaults)

Creates an astropy table from inputs.

Parameters:
outlineslist of str

Input lines

metaDictdict

Input meta data

colNameslist of str

Input column names

colDefaultslist

Input column default values

Returns:
tableastropy.table.Table object
lsmtool.tableio.decformat(val)

Column formatter for Dec values.

Parameters:
valfloat

Input Dec value in deg

Returns:
valstrstr

Formatted string as ‘dd.mm.ss.s’

lsmtool.tableio.ds9RegionWriter(table, fileName)

Writes table to a ds9 region file.

Parameters:
tableastropy.table.Table object

Input sky model table

fileNamestr

Output file to which the sky model is written

lsmtool.tableio.facetRegionWriter(table, fileName)

Writes the model patches to a ds9 facet region file.

The resulting file is suitable for use with WSClean in faceting mode.

Parameters:
tableastropy.table.Table object

Input sky model table; must have patches defined

fileNamestr

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:
tableastropy.table.Table object

Input sky model table; must have patches defined

fileNamestr

Output file to which the sky model is written

lsmtool.tableio.fluxformat(val)

Column formatter for flux density values.

Parameters:
valfloat

Input flux density value in Jy

Returns:
valstrstr

Formatted string to 3 digits

lsmtool.tableio.getGSM(position, radius)

Returns the table from a GSM search.

Parameters:
positionlist of floats

A list specifying a 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])

radiusfloat or str

Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for cone search region

lsmtool.tableio.getLoTSS(position, radius)

Returns table from a LoTSS search.

Parameters:
positionlist of floats

A list specifying a 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])

radiusfloat or str

Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for cone search region

lsmtool.tableio.getQueryInputs(position, radius)

Returns the inputs for a non-VO-compatible catalog search.

Parameters:
positionlist of floats

A list specifying a 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])

radiusfloat or str

Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for cone search region

Returns:
RAfloat

RA in degrees of query position

Decfloat

Dec in degrees of query position

radiusfloat

Radius in degrees of query cone

Raises:
ValueError

Raised when the input radius cannot be converted to degrees, usually due to improperly specified units

lsmtool.tableio.getTGSS(position, radius)

Returns the table from a TGSS search.

Parameters:
positionlist of floats

A list specifying a 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])

radiusfloat or str

Radius in degrees (if float) or ‘value unit’ (if str; e.g., ‘30 arcsec’) for cone search region

lsmtool.tableio.iteritems(d)
lsmtool.tableio.itervalues(d)
lsmtool.tableio.kvisAnnWriter(table, fileName)

Writes table to a kvis annotation file.

Parameters:
tableastropy.table.Table object

Input sky model table

fileNamestr

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:
formatStringstr

Header line

Returns:
colNameslist of str

Output column names

hasPatchesbool

Flag for patches

colDefaultsdict

Default values

metaDictdict

Output meta data

lsmtool.tableio.processLine(line, metaDict, colNames)

Processes a makesourcedb line.

Parameters:
linestr

Data line

metaDictdict

Input meta data

colNameslist of str

Input column names

Returns:
linestr

Processed line

metaDictdict

Output meta data

lsmtool.tableio.queryNonVOService(url, format='makesourcedb')

Returns the table from a non-VO service.

Parameters:
urlstr

URL of catalog

formatstr, optional

Format to use when reading the catalog. Any format accepted by Table.read() is valid

Raises:
ConnectionError

Raised when the wget call returns a nonzero return code, indicating a problem with the connection to the service

lsmtool.tableio.raformat(val)

Column formatter for RA values.

Parameters:
valfloat

Input RA value in deg

Returns:
valstrstr

Formatted string as ‘hh:mm:ss.s’

lsmtool.tableio.rowStr(row, metaDict)

Returns makesourcedb representation of a row.

Parameters:
rowastropy.table.Row object

Row to process

metaDictdict

Table meta dictionary

Returns:
linestr

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, header_start=0)

Reads a makesourcedb sky model file into an astropy table.

See https://www.astron.nl/lofarwiki/doku.php?id=public:user_software:documentation:makesourcedb for details. Note that source names, types, and patch names are limited to a length of 100 characters.

Parameters:
fileNamestr

Input ASCII file from which the sky model is read. Must respect the makesourcedb format

header_startint, optional

Line number at which header starts

Returns:
tableastropy.table.Table object
lsmtool.tableio.skyModelWriter(table, fileName)

Writes table to a makesourcedb sky model file.

Parameters:
fileNamestr

Output ASCII file to which the sky model is written