def __init__(self, ns, name, sources, stations=None, ref_station=None, tags="iono", make_log=False): PiercePoints.PiercePoints.__init__(self, ns, name, sources, stations, height, make_log) if use_lonlat: earth_radius = 6365 # convert km to rad and km/h to rad/s W1 = Wavelength_1 / (earth_radius + height) W2 = Wavelength_2 / (earth_radius + height) Sp1 = (Speed_1 / (earth_radius + height)) / 3600 Sp2 = (Speed_2 / (earth_radius + height)) / 3600 else: # convert km to m and km/h to m/s W1 = Wavelength_1 * 1000 W2 = Wavelength_2 * 1000 Sp1 = Speed_1 / 3.6 Sp2 = Speed_2 / 3.6 self.ref_station = ref_station self._add_parm(name="TEC0", value=Meow.Parm(TEC0), tags=tags) self._add_parm(name="height", value=Meow.Parm(height), tags=tags) self._add_parm(name="Amp_1", value=Meow.Parm(Amp_1), tags=tags) self._add_parm(name="Amp_2", value=Meow.Parm(Amp_2), tags=tags) self._add_parm(name="Wavelength_1", value=Meow.Parm(W1), tags=tags) self._add_parm(name="Wavelength_2", value=Meow.Parm(W2), tags=tags) self._add_parm(name="Speed_1", value=Meow.Parm(Sp1), tags=tags) self._add_parm(name="Speed_2", value=Meow.Parm(Sp2), tags=tags) self._add_parm(name="Theta_1", value=Meow.Parm(Theta_1), tags=tags) self._add_parm(name="Theta_2", value=Meow.Parm(Theta_2), tags=tags) self.make_display_grid(W1, W2, Theta_1, Theta_2, Amp_1, Amp_2, TEC0)
def init_nodes (self,ns,tags=None,label=''): ifrs = Context.array.ifrs(); G = ns.gain; if not G(*ifrs[0]).initialized(): def1 = Meow.Parm(1,tags=tags); def0 = Meow.Parm(0,tags=tags); gains = []; for p,q in ifrs: gg = []; for corr in Context.correlations: if corr in Context.active_correlations: cc = corr.lower(); gain_ri = [ resolve_parameter(cc,G(p,q,cc,'r'),def1,tags="ifr gain real"), resolve_parameter(cc,G(p,q,cc,'i'),def0,tags="ifr gain imag") ]; gg.append(G(p,q,cc) << Meq.ToComplex(*gain_ri)); gains += gain_ri; else: gg.append(1); G(p,q) << Meq.Matrix22(*gg); pg_ifr_ampl = ParmGroup.ParmGroup(label,gains, individual_toggles=False, table_name="%s.fmep"%label,bookmark=False); Bookmarks.make_node_folder("%s (interferometer-based gains)"%label, [ G(p,q) for p,q in ifrs ],sorted=True,nrow=2,ncol=2); ParmGroup.SolveJob("cal_%s"%label, "Calibrate %s (interferometer-based gains)"%label,pg_ifr_ampl); return G;
def compute_jones(self, nodes, stations=None, tags=None, label='', **kw): stations = stations or Context.array.stations() g_ampl_def = Meow.Parm(1) g_phase_def = Meow.Parm(0) nodes = Jones.gain_ap_matrix(nodes, g_ampl_def, g_phase_def, tags=tags, series=stations) # make parmgroups for phases and gains self.pg_phase = ParmGroup.ParmGroup( label + "_phase", nodes.search(tags="solvable phase"), table_name="%s_phase.fmep" % label, bookmark=4) self.pg_ampl = ParmGroup.ParmGroup(label + "_ampl", nodes.search(tags="solvable ampl"), table_name="%s_ampl.fmep" % label, bookmark=4) # make solvejobs ParmGroup.SolveJob("cal_" + label + "_phase", "Calibrate %s phases" % label, self.pg_phase) ParmGroup.SolveJob("cal_" + label + "_ampl", "Calibrate %s amplitudes" % label, self.pg_ampl) return nodes
def source_list(ns): # figure out spectral index parameters if spectral_index is not None: spi_def = Meow.Parm(spectral_index) freq0_def = ref_freq else: spi_def = freq0_def = None if spectral_index1 is not None: spi_def1 = Meow.Parm(spectral_index1) freq0_def1 = ref_freq else: spi_def1 = freq0_def1 = None # and flux parameters i_def = Meow.Parm(1) quv_def = Meow.Parm(0) dir1 = Meow.Direction(ns, "3C343.1", 4.356645791155902, 1.092208429052697) dir0 = Meow.Direction(ns, "3C343", 4.3396003966265599, 1.0953677174056471) src1 = Meow.PointSource(ns, "3C343.1", dir1, I=Meow.Parm(6.02061051), Q=Meow.Parm(0.0179716185), U=quv_def, V=quv_def, spi=spi_def1, freq0=freq0_def1) src0 = Meow.PointSource(ns, "3C343", dir0, I=Meow.Parm(1.83336309), Q=Meow.Parm(0.0241450607), U=quv_def, V=quv_def, spi=spi_def1, freq0=freq0_def1) ## define a parmgroup for source parameters pg_src = ParmGroup.ParmGroup("source", src1.coherency().search(tags="solvable") + src0.coherency().search(tags="solvable"), table_name="sources.mep") ParmGroup.SolveJob("cal_sources", "Calibrate sources", pg_src) return [src1, src0]
def __init__(self, ns, name, sources, stations=None, height=None, make_log=False): MIM_model.__init__(self, ns, name, sources, stations) if isinstance(height, Meow.Parm): self._height = height else: self._height = Meow.Parm(height) self.ns.h << self._height.make() self._make_log = make_log
def source_list (ns,name="cps"): # figure out spectral index parameters if spectral_index is not None: spi_def = Meow.Parm(spectral_index); freq0_def = ref_freq; else: spi_def = freq0_def = None; i_def = Meow.Parm(1); quv_def = Meow.Parm(0); srcdir = Meow.LMDirection(ns,name,0,0); src = Meow.PointSource(ns,name,srcdir,I=i_def,Q=quv_def,U=quv_def,V=quv_def,spi=spi_def,freq0=freq0_def); ## define a parmgroup for source parameters ## now make a solvejobs for the source #pg_src = ParmGroup("source", #src.coherency().search(tags="solvable"), #table_name="sources.mep", #individual=True, #bookmark=True); ## now make a solvejobs for the source #options.append(pg_src.make_solvejob_menu("Calibrate source fluxes")); return [ src ];
def __init__(self, ns, name, sources, stations=None, ref_station=None, tags="iono", make_log=False): PiercePoints.PiercePoints.__init__(self, ns, name, sources, stations, height, make_log) self.ref_station = ref_station for nlo in range(N_long): for nla in range(N_lat): name = "N:" + str(nlo) + ":" + str(nla) self._add_parm(name=name, value=Meow.Parm(0.), tags=tags)
def __init__(self, ns, name, sources, stations=None, ref_station=None, tags="iono", make_log=False): PiercePoints.__init__(self, ns, name, sources, stations, height, make_log) self.ref_station = ref_station for i in range(rank): name = "KLParm:" + str(i) self._add_parm(name=name, value=Meow.Parm(0, tiling=record(time=1)), tags=tags)
def compute_jones(self, nodes, stations=None, tags=None, label='', inspectors=[], **kw): stations = stations or Context.array.stations() rot_def = Meow.Parm(0) nr = Jones.rotation_matrix(nodes("R"), rot_def, tags=tags, series=stations) ne = Jones.ellipticity_matrix(nodes("E"), rot_def, tags=tags, series=stations) for p in stations: nodes(p) << Meq.MatrixMultiply(nr(p), ne(p)) # make parmgroups for phases and gains self.pg_rot = ParmGroup.ParmGroup(label + "_leakage", nodes.search(tags="solvable"), table_name="%s_leakage.mep" % label, bookmark=True) # make solvejobs ParmGroup.SolveJob("cal_" + label + "_leakage", "Calibrate %s (leakage)" % label, self.pg_rot) # make inspector for parameters StdTrees.inspector(nodes('inspector'), self.pg_rot.nodes, bookmark=False) inspectors.append(nodes('inspector')) return nodes
def source_list (self,ns,max_sources=None,**kw): """Reads LSM and returns a list of Meow objects. ns is node scope in which they will be created. Keyword arguments may be used to indicate which of the source attributes are to be created as Parms, use e.g. I=Meow.Parm(tags="flux") for this. The use_parms option may override this. """; if self.filename is None: return []; if self.lsm is None: self.load(ns); # all=1 returns unsorted list, so use a large count instead, to get a sorted list plist = self.lsm.queryLSM(count=9999999); # parse the beam expression if self.beam_expr is not None: try: beam_func = eval("lambda r,fq:"+self.beam_expr); except: raise RuntimeError("invalid beam expression"); else: beam_func = None; # make list of direction,punit,I,I_apparent tuples parm = Meow.Parm(tags="source solvable"); srclist = []; for pu in plist: ra,dec,I,Q,U,V,spi,freq0,RM = pu.getEssentialParms(ns); if self.solve_pos: ra = parm.new(ra); dec = parm.new(dec); direction = Meow.Direction(ns,pu.name,ra,dec,static=not self.solve_pos); Iapp = I; if beam_func is not None: # if phase centre is already set (i.e. static), then lmn will be computed here, and we # can apply a beam expression lmn = direction.lmn_static(); if lmn is not None: r = sqrt(lmn[0]**2+lmn[1]**2); Iapp = I*beam_func(r,freq0*1e-9 or 1.4); # use 1.4 GHz if ref frequency not specified # append to list srclist.append((pu.name,direction,pu,I,Iapp)); # sort list by decreasing apparent flux from past.builtins import cmp from functools import cmp_to_key srclist.sort(key=cmp_to_key(lambda a,b:cmp(b[4],a[4]))); srclist_full = srclist; # extract active subset srclist = self._subset_parser.apply(self.lsm_subset,srclist_full,names=[src[0] for src in srclist_full]); # extract solvable subset solve_subset = self._subset_parser.apply(self.solve_subset,srclist_full,names=[src[0] for src in srclist_full]); solve_subset = set([src[0] for src in solve_subset]); # make copy of kw dict to be used for sources not in solvable set kw_nonsolve = dict(kw); # and update kw dict to be used for sources in solvable set if self.solvable_sources: if self.solve_I: kw.setdefault("I",parm); if self.solve_Q: kw.setdefault("Q",parm); if self.solve_U: kw.setdefault("U",parm); if self.solve_V: kw.setdefault("V",parm); if self.solve_spi: kw.setdefault("spi",parm); if self.solve_RM: kw.setdefault("RM",parm); if self.solve_pos: kw.setdefault("ra",parm); kw.setdefault("dec",parm); if self.solve_shape: kw.setdefault("sx",parm); kw.setdefault("sy",parm); kw.setdefault("phi",parm); # make Meow list source_model = [] ## Note: conversion from AIPS++ componentlist Gaussians to Gaussian Nodes ### eX, eY : multiply by 2 ### eP: change sign for name,direction,pu,I,Iapp in srclist: # print "%-20s %12f %12f"%(pu.name,I,Iapp); src = {}; ( src['ra'],src['dec'], src['I'],src['Q'],src['U'],src['V'], src['spi'],src['freq0'],src['RM'] ) = pu.getEssentialParms(ns) (eX,eY,eP) = pu.getExtParms() # scale 2 difference src['sx'] = eX*2 src['sy'] = eY*2 src['phi'] = -eP # override zero values with None so that Meow can make smaller trees if not src['RM']: src['RM'] = None; if not src['spi']: src['spi'] = None; if src['RM'] is None: src['freq0'] = None; ## construct parms or constants for source attributes ## if source is in solvable set (solvable_source_set of None means all are solvable), ## use the kw dict, else use the nonsolve dict for source parameters if name in solve_subset: solvable = True; kwdict = kw; else: solvable = False; kwdict = kw_nonsolve; for key,value in src.items(): meowparm = kwdict.get(key); if isinstance(meowparm,Meow.Parm): src[key] = meowparm.new(value); elif meowparm is not None: src[key] = value; if eX or eY or eP: # Gaussians if eY: size,phi = [src['sx'],src['sy']],src['phi']; else: size,phi = src['sx'],None; src = Meow.GaussianSource(ns,name=pu.name, I=src['I'],Q=src['Q'],U=src['U'],V=src['V'], direction=direction, spi=src['spi'],freq0=src['freq0'],RM=src['RM'], size=size,phi=phi); else: src = Meow.PointSource(ns,name=pu.name, I=src['I'],Q=src['Q'],U=src['U'],V=src['V'], direction=direction, spi=src['spi'],freq0=src['freq0'],RM=src['RM']); # check for beam LM if pu._lm is not None: src.set_attr('beam_lm',pu._lm); src.solvable = solvable; src.set_attr('Iapp',Iapp); source_model.append(src); return source_model;
def source_list(self, ns, max_sources=None, **kw): """Reads LSM and returns a list of Meow objects. ns is node scope in which they will be created. Keyword arguments may be used to indicate which of the source attributes are to be created as Parms, use e.g. I=Meow.Parm(tags="flux") for this. The use_parms option may override this. """ if self.filename is None: return [] # load the sky model if self.lsm is None: self.lsm = Tigger.load(self.filename) # sort by brightness import functools from past.builtins import cmp from functools import cmp_to_key sources = sorted( self.lsm.sources, key=cmp_to_key(lambda a, b: cmp(b.brightness(), a.brightness()))) # extract subset, if specified sources = SourceSubsetSelector.filter_subset(self.lsm_subset, sources, self._getTagValue) # get nulls subset if self.null_subset: nulls = set([ src.name for src in SourceSubsetSelector.filter_subset( self.null_subset, sources) ]) else: nulls = set() parm = Meow.Parm(tags="source solvable") # make copy of kw dict to be used for sources not in solvable set kw_nonsolve = dict(kw) # and update kw dict to be used for sources in solvable set # this will be a dict of lists of solvable subgroups parms = [] subgroups = {} if self.solvable_sources: subgroup_order = [] for sgname in _SubgroupOrder: if getattr(self, 'solve_%s' % sgname): sg = subgroups[sgname] = [] subgroup_order.append(sgname) # make Meow list source_model = [] for src in sources: is_null = src.name in nulls # this will be True if this source has solvable parms solvable = self.solvable_sources and not is_null and ( not self.lsm_solvable_tag or getattr(src, self.lsm_solvable_tag, False)) if solvable: # independent groups? if self.lsm_solve_group_tag: independent_sg = sgname = "%s:%s" % ( self.lsm_solve_group_tag, getattr(src, self.lsm_solve_group_tag, "unknown")) else: independent_sg = "" sgname = 'source:%s' % src.name if sgname in subgroups: sgsource = subgroups[sgname] else: sgsource = subgroups[sgname] = [] subgroup_order.append(sgname) # make dict of source parametrs: for each parameter we have a value,subgroup pair if is_null: attrs = dict(ra=src.pos.ra, dec=src.pos.dec, I=0, Q=None, U=None, V=None, RM=None, spi=None, freq0=None) else: attrs = dict( ra=src.pos.ra, dec=src.pos.dec, I=src.flux.I, Q=getattr(src.flux, 'Q', None), U=getattr(src.flux, 'U', None), V=getattr(src.flux, 'V', None), RM=getattr(src.flux, 'rm', None), freq0=getattr(src.flux, 'freq0', None) or (src.spectrum and getattr(src.spectrum, 'freq0', None)), spi=src.spectrum and getattr(src.spectrum, 'spi', None)) if not is_null and isinstance(src.shape, ModelClasses.Gaussian): attrs['lproj'] = src.shape.ex * math.sin(src.shape.pa) attrs['mproj'] = src.shape.ex * math.cos(src.shape.pa) attrs['ratio'] = src.shape.ey / src.shape.ex # construct parms or constants for source attributes, depending on whether the source is solvable or not # If source is solvable and this particular attribute is solvable, replace # value in attrs dict with a Meq.Parm. if solvable: for parmname, value in list(attrs.items()): sgname = _Subgroups.get(parmname, None) if sgname in subgroups: solvable = True parm = attrs[parmname] = ns[src.name]( parmname) << Meq.Parm(value or 0, tags=["solvable", sgname], solve_group=independent_sg) subgroups[sgname].append(parm) sgsource.append(parm) parms.append(parm) # construct a direction direction = Meow.Direction(ns, src.name, attrs['ra'], attrs['dec'], static=not solvable or not self.solve_pos) # construct a point source or gaussian or FITS image, depending on source shape class if src.shape is None or is_null: msrc = Meow.PointSource(ns, name=src.name, I=attrs['I'], Q=attrs['Q'], U=attrs['U'], V=attrs['V'], direction=direction, spi=attrs['spi'], freq0=attrs['freq0'], RM=attrs['RM']) elif isinstance(src.shape, ModelClasses.Gaussian): msrc = Meow.GaussianSource(ns, name=src.name, I=attrs['I'], Q=attrs['Q'], U=attrs['U'], V=attrs['V'], direction=direction, spi=attrs['spi'], freq0=attrs['freq0'], lproj=attrs['lproj'], mproj=attrs['mproj'], ratio=attrs['ratio']) if solvable and 'shape' in subgroups: subgroups['pos'] += direction.get_solvables() elif isinstance(src.shape, ModelClasses.FITSImage): msrc = Meow.FITSImageComponent(ns, name=src.name, filename=src.shape.filename, direction=direction) msrc.set_options(fft_pad_factor=(src.shape.pad or 2)) msrc.solvable = solvable # copy standard attributes from sub-objects for subobj in src.flux, src.shape, src.spectrum: if subobj: for attr, val in src.flux.getAttributes(): msrc.set_attr(attr, val) # copy all extra attrs from source object for attr, val in src.getExtraAttributes(): msrc.set_attr(attr, val) # make sure Iapp exists (init with I if it doesn't) if msrc.get_attr('Iapp', None) is None: msrc.set_attr('Iapp', src.flux.I) source_model.append(msrc) # if any solvable parms were made, make a parmgroup and solve job for them if parms: if os.path.isdir(self.filename): table_name = os.path.join(self.filename, "sources.fmep") else: table_name = os.path.splitext(self.filename)[0] + ".fmep" # make list of Subgroup objects for every non-empty subgroup sgs = [] for sgname in subgroup_order: sglist = subgroups.get(sgname, None) if sglist: sgs.append(Meow.ParmGroup.Subgroup(sgname, sglist)) # make main parm group pg_src = Meow.ParmGroup.ParmGroup("source parameters", parms, subgroups=sgs, table_name=table_name, table_in_ms=False, bookmark=True) # now make a solvejobs for the source Meow.ParmGroup.SolveJob("cal_source", "Solve for source parameters", pg_src) return source_model