Skip to content
Snippets Groups Projects
Commit 232efa45 authored by David Rafferty's avatar David Rafferty
Browse files

Add option to tessellate using patches

parent bfa2f4ba
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,7 @@ def run(step, parset, LSM):
def group(LSM, algorithm, targetFlux=None, numClusters=100, FWHM=None,
threshold=0.1, applyBeam=False, root='Patch', pad_index=False, method='mid',
facet=""):
facet="", byPatch=False):
"""
Groups sources into patches.
......@@ -110,6 +110,9 @@ def group(LSM, algorithm, targetFlux=None, numClusters=100, FWHM=None,
- '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
--------
......@@ -157,6 +160,12 @@ def group(LSM, algorithm, targetFlux=None, numClusters=100, FWHM=None,
targetFlux = float(parts[0])
if len(parts) == 2:
units = parts[1]
if byPatch:
if not 'Patch' in LSM.table.keys():
raise ValueError('Sky model must be grouped before "byPatch" can be used.')
x, y, midRA, midDec = LSM._getXY(byPatch=True)
f = LSM.getColValues('I', units=units, applyBeam=applyBeam, aggregate='sum')
else:
LSM.ungroup()
x, y, midRA, midDec = LSM._getXY()
f = LSM.getColValues('I', units=units, applyBeam=applyBeam)
......@@ -165,6 +174,15 @@ def group(LSM, algorithm, targetFlux=None, numClusters=100, FWHM=None,
try:
vobin.bin_voronoi()
patchCol = _tessellate.bins2Patches(vobin, root=root, pad_index=pad_index)
if byPatch:
newPatchNames = patchCol.copy()
origPatchNames = LSM.getPatchNames()
patchCol = np.zeros(len(LSM), dtype='S100')
for newPatchName, origPatchName in zip(newPatchNames, origPatchNames):
ind = np.array(LSM.getRowIndex(origPatchName))
patchCol[ind] = newPatchName
LSM.setColValues('Patch', patchCol, index=2)
else:
LSM.setColValues('Patch', patchCol, index=2)
except ValueError:
# Catch error in some cases with high target flux relative to
......
......@@ -619,7 +619,7 @@ class SkyModel(object):
raise RuntimeError('Sky model does not have patches.')
def _getXY(self, patchName=None, crdelt=None):
def _getXY(self, patchName=None, crdelt=None, byPatch=False):
"""
Returns lists of projected x and y values for all sources.
......@@ -629,6 +629,8 @@ class SkyModel(object):
If given, return x and y for specified patch only
crdelt: float, optional
Delta in degrees for sky grid
byPatch : bool, optional
Use patches instead of by sources
Returns
-------
......@@ -643,6 +645,12 @@ class SkyModel(object):
if len(self.table) == 0:
return [0], [0], 0, 0
if byPatch:
if not 'Patch' in self.table.keys():
raise ValueError('Sky model must be grouped before "byPatch" can be used.')
RA = self.getColValues('Ra', aggregate='wmean')
Dec = self.getColValues('Dec', aggregate='wmean')
else:
RA = self.getColValues('Ra')
Dec = self.getColValues('Dec')
if patchName is not None:
......@@ -1974,7 +1982,7 @@ class SkyModel(object):
def group(self, algorithm, targetFlux=None, numClusters=100, FWHM=None,
threshold=0.1, applyBeam=False, root='Patch', pad_index=False,
method='mid', facet=""):
method='mid', facet="", byPatch=False):
"""
Groups sources into patches.
......@@ -2033,6 +2041,8 @@ class SkyModel(object):
- '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
--------
......@@ -2045,7 +2055,7 @@ class SkyModel(object):
operations.group.group(self, algorithm, targetFlux=targetFlux,
numClusters=numClusters, FWHM=FWHM, threshold=threshold,
applyBeam=applyBeam, root=root, pad_index=pad_index, method=method,
facet=facet)
facet=facet, byPatch=byPatch)
def transfer(self, patchSkyModel, matchBy='name', radius=0.1):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment