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

Adjust merge to exclude duplicate components

parent f7271dda
No related branches found
No related tags found
1 merge request!171Adjust merge to exclude duplicate components
Pipeline #61577 passed
...@@ -5,12 +5,28 @@ Append a LOFAR skymodel to an existing one ...@@ -5,12 +5,28 @@ Append a LOFAR skymodel to an existing one
import os, logging import os, logging
import lsmtool import lsmtool
import numpy
######################################################################## ########################################################################
def main(inmodel1, inmodel2, outmodel = 'output.skymodel'): def main(inmodel1, inmodel2, outmodel = 'output.skymodel', radius=30/3600, keep='from2'):
"""
Merge two LOFAR skymodel text files.
Parameters
----------
inmodel1 : str
Name (path) of input model #1
inmodel2 : str
Name (path) of input model #2
outmodel : str, optional
Name (path) of output merged model
radius : float, optional
Matching radius in degrees for determining duplicates
keep : str, optional
When duplicates are found, keep those from model #1 ('from1') or from
model #2 ('from2')
"""
logging.info('Reading ' + inmodel1) logging.info('Reading ' + inmodel1)
s1 = lsmtool.load(inmodel1) s1 = lsmtool.load(inmodel1)
logging.info('Reading ' + inmodel2) logging.info('Reading ' + inmodel2)
...@@ -22,7 +38,10 @@ def main(inmodel1, inmodel2, outmodel = 'output.skymodel'): ...@@ -22,7 +38,10 @@ def main(inmodel1, inmodel2, outmodel = 'output.skymodel'):
s2.group('single') s2.group('single')
logging.info('Adding skymodel ' + inmodel2 + ' to ' + inmodel1) logging.info('Adding skymodel ' + inmodel2 + ' to ' + inmodel1)
s1.concatenate(s2, inheritPatches=True)
# The following call will merge the two models, identifing (by position) duplicate
# sources/components that are present in both
s1.concatenate(s2, matchBy='position', radius=radius, keep=keep)
s1.setPatchPositions() s1.setPatchPositions()
s1.write(outmodel) s1.write(outmodel)
...@@ -36,11 +55,14 @@ if __name__ == '__main__': ...@@ -36,11 +55,14 @@ if __name__ == '__main__':
parser.add_argument('--inmodel1', type=str, default=None, help='input/output skymodel.') parser.add_argument('--inmodel1', type=str, default=None, help='input/output skymodel.')
parser.add_argument('--inmodel2', type=str, default=None, help='skymodel to append') parser.add_argument('--inmodel2', type=str, default=None, help='skymodel to append')
parser.add_argument('--outmodel', type=str, default='output.skymodel', help='output skymodel name') parser.add_argument('--outmodel', type=str, default='output.skymodel', help='output skymodel name')
parser.add_argument('--radius', type=float, default=30/3600, help='matching radius in degrees')
parser.add_argument('--keep', type=str, default='from2', help='keep duplicates from model 1 or 2')
args = parser.parse_args() args = parser.parse_args()
format_stream = logging.Formatter("%(asctime)s\033[1m %(levelname)s:\033[0m %(message)s","%Y-%m-%d %H:%M:%S") format_stream = logging.Formatter("%(asctime)s\033[1m %(levelname)s:\033[0m %(message)s","%Y-%m-%d %H:%M:%S")
format_file = logging.Formatter("%(asctime)s %(levelname)s: %(message)s","%Y-%m-%d %H:%M:%S") format_file = logging.Formatter("%(asctime)s %(levelname)s: %(message)s","%Y-%m-%d %H:%M:%S")
logging.root.setLevel(logging.INFO) logging.root.setLevel(logging.INFO)
main(inmodel1 = os.path.expandvars(args.inmodel1), inmodel2 = os.path.expandvars(args.inmodel2), outmodel = os.path.expandvars(args.outmodel)) main(inmodel1 = os.path.expandvars(args.inmodel1), inmodel2 = os.path.expandvars(args.inmodel2),
outmodel = os.path.expandvars(args.outmodel), radius=args.radius, keep=args.keep)
...@@ -29,6 +29,23 @@ inputs: ...@@ -29,6 +29,23 @@ inputs:
prefix: --outmodel= prefix: --outmodel=
separate: false separate: false
shellQuote: false shellQuote: false
- id: radius
type: float?
default: 0.00833
inputBinding:
prefix: --radius=
separate: false
shellQuote: false
doc: Matching radius in degrees for identifying duplicate components
- id: keep
type: string?
default: 'from2'
inputBinding:
prefix: --keep=
separate: false
shellQuote: false
doc: Keep duplicate components from model 1 or model 2
outputs: outputs:
- id: skymodel_out - id: skymodel_out
type: File type: File
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment