diff --git a/lsmtool/operations/group.py b/lsmtool/operations/group.py index 573e5a4579348dfe9edda0c841e4d364971f3d41..ddb3400d9c3fe461e67a40e2267e46f143f18925 100644 --- a/lsmtool/operations/group.py +++ b/lsmtool/operations/group.py @@ -363,7 +363,8 @@ def group(LSM, algorithm, targetFlux=None, patchNames=None, weightBySize=False, elif algorithm.lower() == 'tessellate' or algorithm.lower() == 'voronoi': history += ', targetFlux = {0}'.format(targetFlux) LSM._addHistory("GROUP ({0})".format(history)) - LSM.setPatchPositions(method=method, applyBeam=applyBeam) + if algorithm.lower() != 'every': + LSM.setPatchPositions(method=method, applyBeam=applyBeam) LSM._info() return 0 @@ -381,6 +382,12 @@ def addEvery(LSM): names = LSM.getColValues('Name').copy() for i, name in enumerate(names): names[i] = name + '_patch' + RAs = LSM.getColValues('Ra', units='degree') + Decs = LSM.getColValues('Dec', units='degree') + patchDict = {} + for name, ra, dec in zip(names, RAs, Decs): + patchDict.update({name: [ra, dec]}) + LSM.table.meta.update(patchDict) LSM.setColValues('Patch', names, index=2) diff --git a/lsmtool/skymodel.py b/lsmtool/skymodel.py index 068157f747ade631d811ee923f8ce2f6417597d3..c597e43d3e2396629fc85cece5dae56b03103c38 100644 --- a/lsmtool/skymodel.py +++ b/lsmtool/skymodel.py @@ -214,14 +214,12 @@ class SkyModel(object): self.hasPatches = True # Check if any patches have undefined positions + patchDict = {} for patchName in self.getPatchNames(): if patchName not in self.table.meta: - self.log.warning('Patch positions are undefined for one or more ' - 'patches. Setting positions to the mid point of ' - 'each patch... (if this is not what you want, please ' - 'set the positions with the setPatchPositions() method).') - self.setPatchPositions(method='mid') - break + patchDict.update({patchName: None}) + if patchDict: + self.setPatchPositions(patchDict=patchDict, method='mid') else: self.hasPatches = False @@ -643,6 +641,13 @@ class SkyModel(object): else: patchDict = self.getPatchPositions(method=method, applyBeam=applyBeam, perPatchProjection=perPatchProjection) + else: + # Get positions for those patches that need them + patchNames = [patch for patch, pos in iteritems(patchDict) if pos is None] + patchDictNoPos = self.getPatchPositions(method=method, applyBeam=applyBeam, + patchName=patchNames, + perPatchProjection=perPatchProjection) + patchDict.update(patchDictNoPos) for patch, pos in iteritems(patchDict): if type(pos[0]) is str or type(pos[0]) is float: