def print_arrayconfiguration(stnid, bandarr): stnpos, stnrot, stnrelpos, stnintilepos = \ getArrayBandParams(stnid, bandarr) print("Position:\n{}".format(stnpos)) print("Rotation:\n{}".format(stnrot)) print("Relative positions:\n{}".format(stnrelpos)) print("In-tile positions:\n{}".format(stnintilepos))
def output_rotmat_station(stnid, bandarr, output='default'): stnpos, stnrot, stnrelpos, stnintilepos = \ getArrayBandParams(stnid, bandarr) if output == 'default': output = os.path.join(ALIGNMENT_DEST, '{}_{}.txt'.format(stnid, bandarr)) header = _get_casacfg_header('rot', bandarr, stnid) np.savetxt(output, stnrot, fmt="%12f %12f %12f", header=header)
def horizon_to_station(stnid, refAz, refEl): # Algorithm does not depend on time but need it for casacore call. obstimestamp = "2000-01-01T12:00:00" obsstate = casacore.measures.measures() when = obsstate.epoch("UTC", obstimestamp) # Use antennafieldlib to get station position and rotation # (using HBA here but it shouldn't matter much if it were LBA) stnPos, stnRot, arrcfgpos_ITRF, stnIntilePos = \ antennafieldlib.getArrayBandParams(stnid, 'HBA') # Convert from ITRF to LOFAR station coordsys #arrcfgpos_stncrd = stnRot.T * arrcfgpos_ITRF.T pos_ITRF_X = str(stnPos[0,0])+'m' pos_ITRF_Y = str(stnPos[1,0])+'m' pos_ITRF_Z = str(stnPos[2,0])+'m' where = obsstate.position("ITRF", pos_ITRF_X, pos_ITRF_Y, pos_ITRF_Z) obsstate.doframe(where) obsstate.doframe(when) # Set Horizontal AZEL (not really necessary since request is already in # coordinate system, but acts as a check) # whatconv=obsstate.measure(what,'AZEL') # az = whatconv['m0']['value'] # el = whatconv['m1']['value'] # print "Horizontal coord. AZ, EL: {}deg, {}deg".format(numpy.rad2deg(az), # numpy.rad2deg(el)) az_stn=[] el_stn=[] for i in range(len(refAz)): refAz_i = np.deg2rad(float(refAz[i])) refEl_i = np.deg2rad(float(refEl[i])) what = obsstate.direction("AZEL", str(refAz_i)+"rad", str(refEl_i)+"rad") # Convert to Station Coordinate system. # First convert to ITRF whatconvITRF=obsstate.measure(what,'ITRF') lonITRF = whatconvITRF['m0']['value'] latITRF = whatconvITRF['m1']['value'] # then turn it into a vector xITRF = np.cos(lonITRF)*np.cos(latITRF) yITRF = np.sin(lonITRF)*np.cos(latITRF) zITRF = np.sin(latITRF) xyzITRF = np.matrix([[xITRF],[yITRF],[zITRF]]) # then rotate it using station's rotation matrix what_stn = stnRot.T * xyzITRF l_stn=what_stn[0,0] m_stn=what_stn[1,0] n_stn=what_stn[2,0] # now convert vector in station local coordinate system to az/el az_stn.append(np.rad2deg(np.arctan2(l_stn,m_stn))) el_stn.append(np.rad2deg(np.arcsin(n_stn))) return(az_stn, el_stn)
def plot_arrayconfiguration(stnid, bandarr, coordsys): """Plot array configurations""" tier = 'station' if stnid == 'ILT': tier = 'ILT' stnId_list = list_stations() pos = [] names = [] for stnid in stnId_list: names.append(stnid) stnpos, stnrot, stnrelpos, stnintilepos = \ getArrayBandParams(stnid, bandarr) pos.append(np.asarray(stnpos).squeeze().tolist()) pos = np.array(pos) else: if bandarr == 'tile': tier = 'tile' bandarr = 'HBA' stnpos, stnrot, stnrelpos, stnintilepos = getArrayBandParams(\ stnid, bandarr) if coordsys == 'local': stnrelpos = stnrelpos * stnrot stnintilepos = stnintilepos * stnrot if tier == 'tile': pos = np.asarray(stnintilepos) nameprefix = 'elem' else: pos = np.asarray(stnrelpos) nameprefix = 'ant' names = [nameprefix + str(elem) for elem in range(pos.shape[0])] # Plot fig = plt.figure() ax = fig.gca(projection='3d') ax.plot(pos[:, 0], pos[:, 1], pos[:, 2], '*') for idx, name in enumerate(names): ax.text(pos[idx, 0], pos[idx, 1], pos[idx, 2], name) ax.set_aspect('equal') plt.show()
def output_rotmat_station(stnid, bandarr, output='default'): """ Save a station bandarray's rotation matrix. :param stnid: Station ID. :param bandarr: 'HBA' or 'LBA' :param output: Name of output file. If set to 'default', will use default name convention, i.e. '<stnid>_<bandarr>.txt'. """ stnpos, stnrot, stnrelpos, stnintilepos = getArrayBandParams(stnid, bandarr) if output == 'default': output = os.path.join(ALIGNMENT_DEST, '{}_{}.txt'.format(stnid, bandarr)) header = _get_casacfg_header('rot', bandarr, stnid) np.savetxt(output, stnrot, fmt="%12f %12f %12f", header=header)
def output_arrcfg_station(stnid, bandarr, output='default'): """Output a station array configuration in a CASA simmos .cfg format. """ stnPos, stnRot, stnRelPos, stnIntilePos = getArrayBandParams( stnid, bandarr) header = _get_casacfg_header('station', bandarr, stnid) nrelems = stnRelPos.shape[0] outtable = np.zeros(nrelems, dtype=CASA_CFG_DTYPE) if bandarr == 'LBA': diam = 1.5 elif bandarr == 'HBA': diam = 3.0 outtable['X'] = np.squeeze(stnRelPos[:, 0]) outtable['Y'] = np.squeeze(stnRelPos[:, 1]) outtable['Z'] = np.squeeze(stnRelPos[:, 2]) outtable['Diam'] = diam outtable['Name'] = ['ANT' + str(elem) for elem in range(nrelems)] if output == 'default': output = os.path.join(CASA_CFG_DEST, stnid + "_" + bandarr + '.cfg') np.savetxt(output, outtable, fmt=CASA_CFG_FMT, header=header)
def cvcimage(cvcobj, filestep, cubeslice, req_calsrc=None, docalibrate=True, pbcor=False): """Image a CVC object. Parameters ---------- cvcobj : CVCfiles() The covariance cube files object containing visibility cubes. filestep : int The file index to select. cubeslice : int The cube index in file. req_calsrc : str The requested sky source. docalibrate : bool Perform calibration or not. pbcor : bool Perform primary beam correction or not. Returns ------- ll : array The l-direction cosine map. mm : array The m-direction cosine map. images : tuple Tuple of polarized image maps. polrep : str Polarization representation of the images tuple. t : datetime Observation time. freq : float Observation frequency. stnid : str Station id. phaseref : tuple Direction of phase reference used for imaging. """ t = cvcobj.samptimeset[filestep][cubeslice] freq = cvcobj.freqset[filestep][cubeslice] cvcdata_unc = cvcobj.getdata(filestep) stnid = cvcobj.stnsesinfo.get_stnid() bandarr = cvcobj.stnsesinfo.get_bandarr() band = cvcobj.stnsesinfo.get_band() rcumode = cvcobj.stnsesinfo.get_rcumode() pointingstr = cvcobj.stnsesinfo.get_pointingstr() # Get/Compute ant positions stnPos, stnRot, antpos, stnIntilePos \ = antennafieldlib.getArrayBandParams(stnid, bandarr) septon = cvcobj.stnsesinfo.is_septon() if septon: elmap = cvcobj.stnsesinfo.get_septon_elmap() for tile, elem in enumerate(elmap): antpos[tile] = antpos[tile] + stnIntilePos[elem] # stn2Dcoord = stnRot.T * antpos.T # Apply calibration datatype = cvcobj.stnsesinfo.get_datatype() if datatype == 'acc': cvcdata, caltabhead = calibrationtables.calibrateACC( cvcdata_unc, rcumode, stnid, t, docalibrate) else: sb, nz = modeparms.freq2sb(freq) cvcdata, caltabhead = calibrationtables.calibrateXST( cvcdata_unc, sb, rcumode, stnid, t, docalibrate) cvpol = dataIO.cvc2cvpol(cvcdata) # Determine if allsky FoV if band == '10_90' or band == '30_90' or septon: allsky = True else: allsky = False # Determine phaseref if req_calsrc is not None: pntstr = ilisa.observations.directions.std_pointings(req_calsrc) elif allsky: pntstr = ilisa.observations.directions.std_pointings('Z') else: pntstr = pointingstr phaseref = pntstr.split(',') skyimage = True if skyimage: # Phase up visibilities cvpu, UVWxyz = phaseref_xstpol(cvpol[:, :, cubeslice, ...].squeeze(), t, freq, stnPos, antpos, phaseref) # Make image on phased up visibilities polrep, images, ll, mm = xst2skyim_stn2Dcoord(cvpu, UVWxyz.T, freq, include_autocorr=False, allsky=allsky, polrep_req='XY') if pbcor and canuse_dreambeam: # Get dreambeam jones: pointing = (float(phaseref[0]), float(phaseref[1]), 'STN') jonesfld, stnbasis, j2000basis = primarybeampat('LOFAR', stnid, bandarr, 'Hamaker', freq, pointing=pointing, obstime=t, lmgrid=(ll, mm)) ijones = numpy.linalg.inv(jonesfld) bri_ant = numpy.array([[images[0], images[1]], [images[2], images[3]]]) bri_ant = numpy.moveaxis(numpy.moveaxis(bri_ant, 0, -1), 0, -1) ijonesH = numpy.conj(numpy.swapaxes(ijones, -1, -2)) bri_xy_iau = numpy.matmul(numpy.matmul(ijones, bri_ant), ijonesH) images = (bri_xy_iau[:, :, 0, 0], bri_xy_iau[:, :, 0, 1], bri_xy_iau[:, :, 1, 0], bri_xy_iau[:, :, 1, 1]) if canuse_stokes and polrep == 'XY': images = convertxy2stokes(images[0], images[1], images[2], images[3]) polrep = 'Stokes' else: vis_S0 = cvpol[0, 0, cubeslice, ...].squeeze() + cvpol[0, 0, cubeslice, ...].squeeze() nfhimages, ll, mm = nearfield_grd_image(vis_S0, antpos, freq, include_autocorr=True) polrep = 'S0' images = numpy.real(nfhimages) return ll, mm, images, polrep, t, freq, stnid, phaseref
import casacore.quanta.quantity import ilisa.antennameta.antennafieldlib as antennafieldlib if __name__ == "__main__": # Algorithm does not depend on time but need it for casacore call. obstimestamp = "2000-01-01T12:00:00" stnid = sys.argv[1] (refAz, refEl) = sys.argv[2].split(',') # az,el in units degrees refAz = numpy.deg2rad(float(refAz)) refEl = numpy.deg2rad(float(refEl)) obsstate = casacore.measures.measures() when = obsstate.epoch("UTC", obstimestamp) # Use antennafieldlib to get station position and rotation # (using HBA here but it shouldn't matter much if it were LBA) stnPos, stnRot, arrcfgpos_ITRF, stnIntilePos = \ antennafieldlib.getArrayBandParams(stnid, 'HBA') # Convert from ITRF to LOFAR station coordsys arrcfgpos_stncrd = stnRot.T * arrcfgpos_ITRF.T pos_ITRF_X = str(stnPos[0, 0]) + 'm' pos_ITRF_Y = str(stnPos[1, 0]) + 'm' pos_ITRF_Z = str(stnPos[2, 0]) + 'm' where = obsstate.position("ITRF", pos_ITRF_X, pos_ITRF_Y, pos_ITRF_Z) what = obsstate.direction("AZEL", str(refAz) + "rad", str(refEl) + "rad") obsstate.doframe(where) obsstate.doframe(when) # Set Horizontal AZEL (not really necessary since request is already in # coordinate system, but acts as a check) whatconv = obsstate.measure(what, 'AZEL')
def inspect_arrayconfiguration(view, stnid, bandarr, coordsys='local'): """Plot different kinds of array configurations.""" if stnid == 'ILT': stns = list_stations() pos = [] names = [] for stn in stns: names.append(stn) stnpos, stnrot, stnrelpos, stnintilepos = getArrayBandParams( stn, bandarr) pos.append(np.asarray(stnpos).squeeze().tolist()) pos = np.array(pos) else: tier = None if bandarr == 'tile': tier = 'tile' bandarr = 'HBA' stnpos, stnrot, stnrelpos, stnintilepos = getArrayBandParams( stnid, bandarr) if coordsys == 'local': stnrelpos = stnrelpos * stnrot stnintilepos = stnintilepos * stnrot if tier == 'tile': pos = np.asarray(stnintilepos) nameprefix = 'elem' else: if bandarr == 'HBA': nameprefix = 'tile' else: nameprefix = 'ant' pos = np.asarray(stnrelpos) names = [nameprefix + str(elem) for elem in range(pos.shape[0])] # Set coord. labels: if coordsys == 'local': xlbl = 'p' ylbl = 'q' zlbl = 'r' else: # ITRF xlbl = 'X' ylbl = 'Y' zlbl = 'Z' if view == 'print': for idx in range(len(names)): print(names[idx], pos[idx, 0], pos[idx, 1], pos[idx, 2]) else: # Plot # #from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.gca(projection='3d') ax.set_title("Array configuration of {} {} in coordsys {}".format( stnid, bandarr, coordsys)) ax.set_xlabel(xlbl) ax.set_ylabel(ylbl) ax.set_zlabel(zlbl) # ax.set_aspect('equal') ax.plot(pos[:, 0], pos[:, 1], pos[:, 2], '*') for idx, name in enumerate(names): ax.text(pos[idx, 0], pos[idx, 1], pos[idx, 2], ' ' + name, fontsize=6) if stnid != 'ILT' and coordsys == 'local': # (zmin,zmax) = ax.get_zlim3d() ax.set_zlim(-0.5, 0.5) plt.show()