def _run(prefix=None, predict=False, **kw): if predict: args = ['{0}={1}'.format(a, b) for a, b in kw.iteritems()] utils.xrun(cab['binary'], args) return if kw.get('niter', 0) > 0: if kw.get('operation', None) not in [ 'clark', 'hogbom', 'csclean', 'multiscale', 'entropy' ]: kw['operation'] = 'csclean' images = { "restored": ['{0}.restored.{1}'.format(prefix, a) for a in ['fits', 'img']], "model": ['{0}.model.{1}'.format(prefix, a) for a in ['fits', 'img']], "residual": ['{0}.residual.{1}'.format(prefix, a) for a in ['fits', 'img']], } elif kw.get('niter', 0) == 0: kw["operation"] = 'image' images = { "image": ['{0}.dirty.{1}'.format(prefix, a) for a in ['fits', 'img']], } for key, value in images.iteritems(): kw[key] = value[1] args = ['{0}={1}'.format(a, b) for a, b in kw.iteritems()] utils.xrun(cab['binary'], args) print('Converting CASA iamges to FITS images') for fits, img in images.itervalues(): im = pyrap.images.image(img) im.tofits(fits, overwrite=True, velocity=kw.get('prefervelocity', False)) rm_fr(img)
import os import sys sys.path.append("/scratch/stimela") import utils CONFIG = os.environ["CONFIG"] INPUT = os.environ["INPUT"] MSDIR = os.environ["MSDIR"] OUTDIR = os.environ["OUTPUT"] cab = utils.readJson(CONFIG) args = [] for param in cab['parameters']: value = param['value'] name = param['name'] if value in [None, False]: continue elif value is True: value = "" elif name == 'hdf5files': files = value continue args += ['{0}{1} {2}'.format(cab['prefix'], name, value)] utils.xrun("h5toms.py", args + files)
elif name == 'output': outimage = value continue elif name == 'stack': stack = True continue elif name == 'unstack': unstack = True continue elif name == 'unstack-chunk': chunk = value continue elif name == 'fits-axis': axis = value continue elif value is True: value = "" args.append( '{0}{1} {2}'.format(cab['prefix'], name, value) ) if stack and axis: args.append( '{0}stack {1}:{2}'.format(cab['prefix'], outimage, axis)) outimage = None elif unstack and axis: args.append( '{0}unstack {1}:{2}:{3}'.format(cab['prefix'], outimage, axis, chunk)) outimage = None else: outimage = '{0}output {1}'.format(cab['prefix'], outimage) utils.xrun(cab['binary'], args+[inimage, outimage or ""])
import sys import os import json sys.path.append("/scratch/stimela") import utils CONFIG = os.environ["CONFIG"] INPUT = os.environ["INPUT"] OUTPUT = os.environ["OUTPUT"] MSDIR = os.environ["MSDIR"] cab = utils.readJson(CONFIG) args = {} tasksuite = None for param in cab['parameters']: name = param['name'] value = param['value'] if value is None: continue args[name] = value kwargs = "'{}'".format(json.dumps(args)) ARGS = ["flag_autocorr_drifts", "-s antenna_mod", kwargs] utils.xrun(cab['binary'], ARGS)
def main(): for i, arg in enumerate(sys.argv): if (arg[0] == '-') and arg[1].isdigit(): sys.argv[i] = ' ' + arg parser = ArgumentParser(description="Reliability estimator and" " direction-dependent sources selection tool." " M. L. L Sebokolodi <*****@*****.**>") add = parser.add_argument add("-v","--version", action="version",version= "{:s} version {:s}".format(parser.prog, __version__)) add("-i", "--image", dest="image", help=" FITS image name") add("-p", "--psfimage", dest="psf", default=None, help=" Point Spread Function (PSF) Fits image name. Default = None") add("-ds", "--disable-smoothing", dest="disable_smoothing", action="store_true", help=" Smooth data before running source finder.") add("-s", "--source-finder", dest="source_finder", default="pybdsm", help=" Source finder name. Default='pybdsm'.") add("-catype", "--catalog-format", dest="catalogue_format", default="gaul", help=" Type of a catalogue. Gaussian cataog is 'gaul', source list is 'srl'") add("--to-pybdsm", dest="to_pybdsm", action="append", help=" PyBDSM process_image option. E.g 'thresh_pix=1,thresh_pix=2'") add("-log", "--log-level",dest="log_level", type=int, default=0, help=" Python logging module, where info=0, debug=1, critial=2 and abort=3.") add("-od", "--output-dir", dest="outdir", default=None, help=" Output products will be dumped here. System Default will be generated.") add("-pref", "-dir-prefix", dest="prefix", default=None, help=" Prefix for output products. System default will be generated.") add("-apsf", "--add-psfcorr", dest="add_psfcorr", action="store_true", default=False, help=" Adds PSF correlation for density estimations. The PSF " " image must be provided. Default is False. To set True add -apsf") add("-alv", "--add-localvar", dest="add_locvar", action="store_true", default=False, help=" Include local variance for density estimations. See -apsf.") add("-dn", "--do-nearsources", dest="do_nearsources", action="store_true", default=False, help=" Adds number of neighbours for density estimations. See -apsf") add("-dmp", "--do-relplots", dest="do_relplots", action="store_false", default=True, help=" Make reliability density plot. Default is True." " To disable add -dmp on the command line.") add("-drel", "--reset-rel", dest="reset_rel", action="store_true", default=False, help=" Assigns R=0 for sources with cf < 0.002 and" "R > 0.60.") add("-beam", "--beam-cluster", dest="do_beam", default=False, action="store_true", help= " Increases the Gaussian groupings by 20 percent the" " beam size. Default is False.") add("-pcr", "--psfcorr-region", dest="psfcorr_region", type=int, default=5, help=" The size of the region to correlate, in beam sizes." " Default value is 5 beam sizes.") add("-lr", "--local-region", dest="local_region", default=10, help=" The area to compute the local variance, in beam sizes." " Default value is 10 beam sizes.") add("-rel_rm", "--rel-rmsrc", dest="rel_rmsrc", action="append", default=None, help=" Delete sources within a radius;" " e.g ra, dec, radius (in degrees). For more than" " one region: ra1,dec1,radius1:ra2,dec2,radius2. Default is None.") add("-ps", "--positive-smooth", dest="pos_smooth", type=float, default=2.0, help=" Masking threshold in the positive image, e.g pixels 2x noise" " will be masked. Default is 2.0.") add("-ns", "--negative-smooth", dest="neg_smooth", type=float, default=2.0, help=" Similar to -ps. Applied to negative image.") add('-pisl', "--thresh-isl", dest="thresh_isl", type=float, default=3, help=" Source finding threshold for forming islands. For positive image." " Default is 3.") add("-ppix", "--thresh-pix", dest="thresh_pix", type=float, default=5, help=" Source finding threshold for model fitting. For positive image." " Default is 5.") add("-nisl", "--negthreshold-isl", dest="neg_thresh_isl", type=float, default=3, help=" Similar to -pisl but applied" " to the negative image. Default is 3.") add("-npix", "--negthreshold-pix", dest="neg_thresh_pix", type=float, default=5, help=" Similar to -ppix but applied" " for negative image. Default is 5.") add("-snr_thr", "--snr-threshold", dest="snr_thresh", type=float, default=40, help=" SNR threshold. High SNR Sources have SNR > 40x min(SNR)" " Default is 40.") add("-pc_thr", "--psfcorr-threshold", dest="psfcorr_thresh", type=float, default=0.5, help="Correlation factor (CF) threshold." "High CF sources have CF > 0.5. Default is 0.5.") add("-nneg", "--num-negatives",dest="num_negatives", type=float, default=4, help="Number of neigbouring (NN) negative detections. Default is 4." "High NN sources have NN > 4.") add("-nrgn", "--neg-region", dest="neg_region", type=float, default=10, help="The size of a region to find -nneg. Default is 10.") add("-phrm", "--phasecenter-remove", dest="phase_center_rm", type=float, default=None, help="The radius excluded from" " direction-dependent source selection. NB: this radius is w.r.t to" " the phase center. Default is None.") add('-jc', '--json-config', dest='config', default=None, help='Json config file : No default') add("-smp", "--save-posmask", dest="savemask_pos", action="store_true", default=False, help="If specified, positive mask is saved.") add("-smn", "--save-negmask", dest="savemask_neg", action="store_true", default=False, help=" If specified, the negative mask is saved.") args = parser.parse_args() to_pybdsm = args.to_pybdsm[0].split(",") if args.to_pybdsm else None pybdsm_opts = dict([ items.split("=") for items in to_pybdsm ] ) \ if to_pybdsm else {} for key, val in pybdsm_opts.iteritems(): if not callable(val): try: pybdsm_opts[key] = eval(key) except NameError: pybdsm_opts[key] = val if not args.image: print("ATTENTION: No image provided. Unless specified inside JSON file otherwise" " the execution is aborted") # making outdirectory def get_prefix(prefix, imagename, outdir): if prefix is None: prefix = os.path.basename(imagename.split(",")[0]).split(".")[:-1] prefix = ".".join(prefix) outdir = outdir or prefix +"_"+ os.path.join(datetime.datetime.now().\ strftime("%Y-%m-%d-%H")) outdir = os.path.abspath(outdir) if not os.path.exists(outdir): os.makedirs(outdir) prefix = outdir +"/"+ prefix return prefix if args.config: keys = [] images = args.image.split(",") if args.image else None with open(args.config) as conf: jdict = json.load(conf) for key,val in jdict.items(): if isinstance(val, unicode): jdict[key] = str(val) prefix = get_prefix(jdict["prefix"], images[0] if images else jdict["imagename"], jdict["outdir"]) reldict = jdict["reliability"] ddict = jdict["dd_tagging"] sourcefin = jdict["source_finder_opts"] for key, val in reldict.iteritems(): if isinstance(val, unicode): reldict[key] = str(val) for key, val in ddict.iteritems(): if isinstance(val, unicode): ddict[key] = str(val) reldict.update(sourcefin) enable = ddict["enable"] ddict.pop("enable") if args.image: psfs = args.psf.split(",") if args.psf else [None] if len(images) != len(psfs): psfs = [psfs[0]]*len(images) for i, (image, psf) in enumerate(zip(images, psfs)): prefix = get_prefix(jdict["prefix"], images[0] if images else jdict["imagename"], jdict["outdir"]) if len(images) >1: prefix = prefix + "-%04d"%i reldict["prefix"] = prefix mc = rel.load(image, psf, **reldict) pmodel, nmodel, step = mc.get_reliability() reldict["prefix"] = prefix ddict["pmodel"] = pmodel ddict["nmodel"] = nmodel ddict["prefix"] = prefix ddict["imagename"] = image ddict["local_step"] = step if enable: dc = dd.load( psfname=psf, **ddict) pmodel, nmodel = dc.source_selection() pmodel.save( prefix+".lsm.html") nmodel.save( prefix+"_negative.lsm.html") utils.xrun("tigger-convert", ["--rename -f", prefix + ".lsm.html"]) else: image = jdict["imagename"] psf = jdict["psfname"] reldict["prefix"] = prefix mc = rel.load(image, psf, **reldict) pmodel, nmodel, step = mc.get_reliability() ddict["pmodel"] = pmodel ddict["nmodel"] = nmodel ddict["prefix"] = prefix ddict["imagename"] = image ddict["local_step"] = step if enable: dc = dd.load(psfname=psf, **ddict) pmodel, nmodel = dc.source_selection() pmodel.save( prefix+".lsm.html") nmodel.save( prefix+"_negative.lsm.html") else: images = args.image.split(",") psfs = args.psf.split(",") if args.psf else [None] psfregion = args.psfcorr_region locregion = args.local_region if len(images) != len(psfs): psfs = [psfs[0]]*len(images) for i, (image, psf) in enumerate(zip(images, psfs)): prefix = get_prefix(args.prefix, images[0], args.outdir) if len(images) >1: prefix = prefix + "-%04d"%i mc = rel.load(imagename=image, psfname=psf, sourcefinder_name= args.source_finder, makeplots=args.do_relplots, saveformat=args.catalogue_format, do_psf_corr=args.add_psfcorr, do_local_var=args.add_locvar, psf_corr_region=psfregion, local_var_region=locregion, rel_excl_src=args.rel_rmsrc, pos_smooth=args.pos_smooth, neg_smooth=args.neg_smooth, loglevel=args.log_level, thresh_isl=args.thresh_isl, thresh_pix=args.thresh_pix, neg_thresh_isl=args.neg_thresh_isl, neg_thresh_pix= args.neg_thresh_pix, prefix=prefix, reset_rel=args.reset_rel, do_nearsources=args.do_nearsources, increase_beam_cluster= args.do_beam, savemask_neg=args.savemask_neg, savemask_pos=args.savemask_pos, no_smooth=args.disable_smoothing, **pybdsm_opts) # assignign reliability values pmodel, nmodel, step = mc.get_reliability() # direction dependent detection tagging dc = dd.load(imagename=image, psfname=psf, pmodel=pmodel, nmodel=nmodel, local_step=step, snr_thresh=args.snr_thresh, high_corr_thresh=args.psfcorr_thresh, negdetec_region= args.neg_region, negatives_thresh=args.num_negatives, phasecenter_excl_radius=args.phase_center_rm, prefix=prefix, loglevel=args.log_level) # tagging pmodel, nmodel = dc.source_selection() pmodel.save( prefix+".lsm.html") nmodel.save( prefix+"_negative.lsm.html") utils.xrun("tigger-convert", ["--rename -f", prefix + ".lsm.html"])
continue if name == 'scale': if isinstance(value, (int, float)): value = '{0}asec'.format(value) if name == 'datacolumn': name = 'data-column' # new interface as of WSCLEAN 2.5 - here for compat if name in 'size trim nwlayers-for-size beam-shape channel-range interval'.split( ): if isinstance(value, int): value = '{0} {0}'.format(value) elif hasattr(value, '__iter__'): if len(value) == 1: value.append(value[0]) value = ' '.join(map(str, value)) if name in 'spws multiscale-scales pol'.split(): if hasattr(value, '__iter__'): value = ','.join(map(str, value)) if value is True: arg = '{0}{1}'.format(cab['prefix'], name) else: arg = '{0}{1} {2}'.format(cab['prefix'], name, value) args.append(arg) utils.xrun(cab['binary'], args + [mslist])
args = [] for param in cab['parameters']: name = param['name'] value = param['value'] if value in [False, None]: continue if name in 'channels timeslots corrs stations ddid field str'.split(): if name in 'channels timeslots'.split(): value = ':'.join(value) else: value = ','.join(value) if value is True: value = "" if name == 'msname': msname = value if isinstance(msname, str): msname = [msname] continue if name=='flagged-any': args += ['{0}flagged-any {1}'.format(cab['prefix'], a) for a in value] continue args.append( '{0}{1} {2}'.format(cab['prefix'], name, value) ) utils.xrun(cab['binary'], args+msname)
import os import sys sys.path.append('/scratch/stimela') import utils CONFIG = os.environ["CONFIG"] INPUT = os.environ["INPUT"] MSDIR = os.environ["MSDIR"] cab = utils.readJson(CONFIG) args = [] for param in cab['parameters']: name = param['name'] value = param['value'] if name == "noise-map": args += [value] continue if value is None: continue elif value is False: continue if param["dtype"] == "bool" and value: args += ['{0}{1}'.format(cab['prefix'], name)] continue args += ['{0}{1} {2}'.format(cab['prefix'], name, value)] utils.xrun(cab['binary'], args)
import os import sys sys.path.append("/scratch/stimela") import utils CONFIG = os.environ["CONFIG"] INPUT = os.environ["INPUT"] OUTPUT = os.environ["OUTPUT"] MSDIR = os.environ["MSDIR"] cab = utils.readJson(CONFIG) args = [] for param in cab['parameters']: name = param['name'] value = param['value'] if name == 'ms': mslist = ' '.join(value) continue if value in [None, False]: continue if value is True: value = "" args += ['{0}{1} {2}'.format(cab['prefix'], name, value)] utils.xrun("mask_ms.py", args + [mslist])
import utils CONFIG = os.environ["CONFIG"] INPUT = os.environ["INPUT"] MSDIR = os.environ["MSDIR"] cab = utils.readJson(CONFIG) args = [] msname = None for param in cab['parameters']: name = param['name'] value = param['value'] if value is None: continue elif value is False: continue elif value is True: value = '' elif name == 'msname': msname = ' '.join(value) continue args += ['{0}{1} {2}'.format(cab['prefix'], name, value)] if msname: utils.xrun(cab['binary'], args+[msname]) else: raise RuntimeError('MS name has not be specified')
options["me.epe_enable"] = 1 perr = numpy.random.randn(NANT) * rms_perr, numpy.random.randn( NANT) * rms_perr ll, mm = " ".join(map(str, perr[0])), " ".join(map(str, perr[-1])) options['oms_pointing_errors.pe_l.values_str'] = "'%s'" % ll options['oms_pointing_errors.pe_l.values_str'] = "'%s'" % mm field_center = params.pop("field-center", None) if field_center and skymodel: if field_center.lower() == "ms": ftab = table(msname + "/FIELD") ra, dec = ftab.getcol("PHASE_DIR")[params.get('field-id', 0)][0] field_center = "J2000,%frad,%frad" % (ra, dec) tmp = "recentered_" + os.path.basename(skymodel) utils.xrun("tigger-convert", ["--recenter", field_center, skymodel, tmp, "-f"]) options["tiggerlsm.filename"] = tmp prefix = ['-s {}'.format(saveconf) if saveconf else '' ] + ["--mt {0} -c {1} [{2}]".format(threads, tdlconf, section)] suffix = [ "%s/Siamese/turbo-sim.py =_simulate_MS" % os.environ["MEQTREES_CATTERY_PATH"] ] args = [] for key, value in options.iteritems(): if isinstance(value, str) and value.find(' ') > 0: value = '"{:s}"'.format(value) args.append('{0}={1}'.format(key, value))
elif name == 'parset': parset = [value] continue elif name == 'model-list': if isinstance(value, str): value = [value] for i, val in enumerate(value): if not os.path.exists(val.split("@")[0]): value[i] = os.path.basename(val) value = ':'.join(value) elif isinstance(value, list): value = ",".join(map(str, value)) args[name] = value # available jones terms joneses = "g b dd".split() soljones = args.pop("sol-jones") for jones in joneses: if jones.lower() not in soljones.lower(): jopts = filter(lambda a: a.startswith("{0:s}-".format(jones)), args.keys()) for item in jopts: del args[item] opts = ["{0:s}sol-jones {1:s}".format(cab["prefix"], soljones)] + \ ['{0}{1} {2}'.format(cab['prefix'], name, value) for name,value in args.iteritems()] utils.xrun(cab['binary'], parset + opts)
def run_meqtrees(msname): prefix = ["--mt %d -c %s [%s]" % (THREADS, TDL, SECTION)] suffix = [ "%s/Calico/calico-stefcal.py =stefcal" % os.environ["MEQTREES_CATTERY_PATH"] ] options = {} options.update(params) if jdict.pop("add-vis-model", 0): options["read_ms_model"] = 1 options["ms_sel.model_column"] = model_column taql = jdict.get('data-selection', None) if taql: options["ms_sel.ms_taql_str"] = taql args = [] for key, value in options.iteritems(): if isinstance(value, str) and value.find(' ') > 0: value = '"{:s}"'.format(value) args.append('{0}={1}'.format(key, value)) args = prefix + args + suffix utils.xrun(cab['binary'], args + ['-s {}'.format(saveconf) if saveconf else '']) print("MeqTrees Done!") # now plot the gains if makeplots: print("Preparing to make gain plots") import Owlcat.Gainplots as plotgains feed_tab = table(msname + "/FEED") print("Extracting feed type from MS") feed_type = set(feed_tab.getcol("POLARIZATION_TYPE")['array']) feed_type = "".join(feed_type) print("Feed type is [%s]" % feed_type) if feed_type.upper() in ["XY", "YX"]: feed_type = "XY" else: feed_type = "RL" if gjones: print("Making Gain plots (G)...") plotgains.make_gain_plots(gjones_gains, prefix=gjones_plotprefix, feed_type=feed_type) if bjones: print("Making Gain plots (B)...") plotgains.make_gain_plots(bjones_gains, gain_label='B', prefix=bjones_plotprefix, feed_type=feed_type) if ddjones: print("Making differential gain plots...") plotgains.make_diffgain_plots(ddjones_gains, prefix=ddjones_plotprefix, feed_type=feed_type) if ifrjones: print("Making IFR gain plots...") plotgains.make_ifrgain_plots(ifrjones_gains, prefix=ifrjones_plotprefix, feed_type=feed_type) sys.exit(0)
continue if name == "port2tigger": port2tigger = value continue if name == "steps.doWriteCat": writecat = value if name == "steps.doParameterise": parameterise = value if name == "import.inFile": image = value wstd.write('{0}={1}\n'.format(name, value)) wstd.close() utils.xrun('sofia_pipeline.py', [sofia_file]) if not port2tigger: sys.exit(0) # convert to data file to Tigger LSM # First make dummy tigger model tfile = tempfile.NamedTemporaryFile(suffix='.txt') tfile.flush() if image and writecat and parameterise: pass else: sys.exit(0) prefix = os.path.splitext(image)[0]
source.setAttribute("I_peak_err", src["E_peak_flux"]) else: source.setAttribute("I_peak", src["Total_flux"]) source.setAttribute("I_peak_err", src["E_Total_flux"]) if spi_do: # Check if start frequency is provided if not provided raise error. # It is used to define tigger source spectrum index frequency if freq0: spi, spi_err = (src['Spec_Indx'], src['E_Spec_Indx']) source.spectrum = ModelClasses.SpectralIndex(spi, freq0) source.setAttribute('spi_error', spi_err) else: raise RuntimeError("No start frequency (freq0) provided.") return source with pyfits.open(outfile) as hdu: data = hdu[1].data for i, src in enumerate(data): model.sources.append(tigger_src(src, i)) wcs = WCS(image) centre = wcs.getCentreWCSCoords() model.ra0, model.dec0 = map(numpy.deg2rad, centre) model.save(tname_lsm) # Rename using CORPAT utils.xrun("tigger-convert", [tname_lsm, "--rename -f"])
with pyfits.open(predict) as _hdu: if hasattr(_hdu, '__iter__'): hdu = _hdu[0] else: hdu = _hdu cdelt = hdu.header.get('CDELT1', None) if cdelt: cell = '{:f}arcsec'.format(abs(cdelt) * 3600) if cell is None: raise RuntimeError( 'The size of a pixel in this FITS image was not specified \ in FITS header (CDELT1/2), or as parameter for this module ("cellsize"). Cannot proceed' ) utils.xrun('python /scratch/code/predict_from_fits.py', [predict, options['ms'], cell, tfile.name]) predict_vis(msname=options['ms'], image=tfile.name, column=options.get('data', 'MODEL_DATA'), chanchunk=options.get('chanchunk', None), chanstart=options.get('img_chanstart', 0), chanstep=options.get('img_chanstep', 1)) tfile.close() else: _run(prefix, **options) os.chdir(OUTPUT) os.system('rm -r {}'.format(tdir))
img ="{:s}.{:s}".format(prefix, image) if image == 'flux': _images = [img] elif nterms>1: _images = ["%s.tt%d"%(img,d) for d in range(nterms)] if image=="image": if nterms==2: alpha = img+".alpha" alpha_err = img+".alpha.error" _images += [alpha,alpha_err] if nterms==3: beta = img+".beta" beta_err = img+".beta.error" _images += [beta,beta_err] else: _images = [img] convert += _images for _image in convert: sys.stdout.write(_image) if _image in STD_IMAGES and (not os.path.exists(_image)): raise RuntimeError("Standard output from CASA clean task not found. Something went wrong durring cleaning, take a look at the logs and such") elif os.path.exists(_image): task = crasa.CasaTask("exportfits", **dict(imagename=_image, fitsimage=_image+".fits", overwrite=True)) task.run() if not keep_casa_images: for _image in convert: utils.xrun("rm", ["-rf", _image])
import os import sys sys.path.append("/scratch/stimela") import utils CONFIG = os.environ["CONFIG"] INPUT = os.environ["INPUT"] OUTPUT = os.environ["OUTPUT"] cab = utils.readJson(CONFIG) params = cab["parameters"] args = [] for param in params: if param['value'] in [False, None]: continue elif param['value'] is True: arg = "{0}{1}".format(cab["prefix"], param["name"]) else: arg = "{0}{1} {2}".format(cab["prefix"], param["name"], param["value"]) args.append(arg) utils.xrun(cab["binary"], args)
name = param['name'] value = param['value'] if value in [False, None]: continue if value is True: value = "" # Positional arguments if name == 'input-skymodel': inlsm= value continue elif name == 'tag': tag = value continue params[name] = value #TODO: Need fix tigger-tag, these kludges are annoying if params.pop('transfer-tags', False) in [True, ""]: if params.get('tolerance', None) is None: raise RuntimeError("Parameter 'tolerance' is required when 'transfer-tags' is enables") args = ['{0}transfer-tags {1}:{2}'.format(cab['prefix'], inlsm, params.pop('tolerance'))] inlsm = params.get('output') else: args = [] args += ['{0}{1} {2}'.format(cab['prefix'], name, value) for name, value in params.iteritems()] utils.xrun(cab['binary'], args+[inlsm, tag])
if name == "primary-beam": value = "'{}'".format(value) if name == 'pa-range' and hasattr(value, '__iter__'): value = ','.join(value) if value is True: value = "" if name == 'pa-from-ms' and hasattr(value, '__iter__'): mslist = value continue if name == 'field-id'and hasattr(value, '__iter__'): field = value continue # Positional arguments if name == 'input-skymodel': inlsm = value continue elif name == 'output-skymodel': outlsm = value continue args.append( '{0}{1} {2}'.format(cab['prefix'], name, value) ) if mslist: if len(field)==0: field = [0]*len(mslist) pa_from_ms = ','.join(['{0}:{1}'.format(ms, i) for ms,i in zip(mslist, field)]) args.append('--pa-from-ms {}'.format(pa_from_ms)) utils.xrun(cab['binary'], args + [inlsm, outlsm])
for param in cab['parameters']: name = param['name'] value = param['value'] if value is None: continue if name == 'msname': list_doc['general']['msname'] = value.split('/')[-1] continue for key, val in list_doc.items(): if type(val) == dict: for k1, v1 in val.items(): if type(v1) == dict: for k2, v2 in v1.items(): if k2 == name: list_doc[key][k1][k2] = value else: if k1 == name: list_doc[key][k1] = value else: if key == name: list_doc[key] = value edited_file = 'rfinder_default.yml' with open(edited_file, "w") as f: yaml.dump(list_doc, f) utils.xrun('rfinder -c', [edited_file])
params = cab["parameters"] _positional = ['antenna-file'] positional = [] for item in _positional: param = filter( lambda a: a['name']==item, params)[0] value = param['value'] params.remove(param) if value: positional.append(value) args = [] for param in params: key = param['name'] value = param['value'] if value in [None, False]: continue if value is True: arg = '{0}{1}'.format(cab['prefix'], key) elif hasattr(value, '__iter__'): arg = ' '.join(['{0}{1} {2}'.format(cab['prefix'], key, val) for val in value]) else: if isinstance(value, str): value = '"{}"'.format(value) arg = '{0}{1} {2}'.format(cab['prefix'], key, value) args.append(arg) utils.xrun(cab['binary'], args+['--nolog']+positional)
hdulist = fitsio.open(imagename) if isinstance(hdulist, list): hdu = hdulist[0] else: hdu = hdulist tfile = tempfile.NamedTemporaryFile(suffix='.fits') tfile.flush() nchan = hdu.data.shape[0] sys.stdout.write('Creating template image\n') os.system('rm -fr {0}'.format(tfile.name)) utils.xrun('lwimager', [ 'ms=' + msname, 'fits=' + tfile.name, 'data=psf', 'npix=64', 'mode=mfs', 'nchan={:d}'.format(nchan), 'img_nchan={:d}'.format(nchan), 'prefervelocity=False', 'cellsize={0}'.format(cell) ]) sys.stdout.write( 'Created template image. Will now proceed to simulate FITS model into MS\n' ) with fitsio.open(tfile.name) as hdu0: header = hdu0[0].header tfile.close() naxis = hdu.header['NAXIS'] raNpix = hdu.header['NAXIS1'] decNpix = hdu.header['NAXIS2']
OUTDIR = os.environ["OUTPUT"] HOME = os.environ["HOME"] cab = utils.readJson(CONFIG) args = [] overwrite = False for param in cab['parameters']: value = param['value'] name = param['name'] if value in [None, False]: continue elif name == "overwrite": overwrite = value continue elif value is True: value = "" elif name == 'mvffiles': files = value continue elif name == "credentials_dir" and value: os.system("cp -rf {0:s} {1:s}/.aws".format(value, HOME)) continue args += ['{0}{1} {2}'.format(cab['prefix'], name, value)] if overwrite: os.system("rm -fr {0:s}".format(" ".join(files))) utils.xrun(cab["binary"], args + files)