def calc_uvw(sdmfile, scan=<NUM_LIT:0>, datetime=<NUM_LIT:0>, radec=()):
<EOL>try:<EOL><INDENT>import casautil<EOL><DEDENT>except ImportError:<EOL><INDENT>try:<EOL><INDENT>import pwkit.environments.casa.util as casautil<EOL><DEDENT>except ImportError:<EOL><INDENT>logger.info('<STR_LIT>')<EOL>return<EOL><DEDENT><DEDENT>me = casautil.tools.measures()<EOL>qa = casautil.tools.quanta()<EOL>logger.debug('<STR_LIT>')<EOL>assert os.path.exists(os.path.join(sdmfile, '<STR_LIT>')), '<STR_LIT>' % sdmfile<EOL>scans, sources = read_metadata(sdmfile, scan)<EOL>if (datetime == <NUM_LIT:0>) and (len(radec) == <NUM_LIT:0>):<EOL><INDENT>assert scan != <NUM_LIT:0>, '<STR_LIT>'   <EOL>logger.info('<STR_LIT>' % (scan, scans[scan]['<STR_LIT:source>']))<EOL>datetime = qa.time(qa.quantity(scans[scan]['<STR_LIT>'],'<STR_LIT:d>'), form="<STR_LIT>", prec=<NUM_LIT:8>)[<NUM_LIT:0>]<EOL>sourcenum = [kk for kk in sources.keys() if sources[kk]['<STR_LIT:source>'] == scans[scan]['<STR_LIT:source>']][<NUM_LIT:0>]<EOL>direction = me.direction('<STR_LIT>', str(np.degrees(sources[sourcenum]['<STR_LIT>']))+'<STR_LIT>', str(np.degrees(sources[sourcenum]['<STR_LIT>']))+'<STR_LIT>')<EOL><DEDENT>elif (datetime != <NUM_LIT:0>) and (len(radec) == <NUM_LIT:0>):<EOL><INDENT>assert scan != <NUM_LIT:0>, '<STR_LIT>'   <EOL>assert '<STR_LIT:/>' in datetime, '<STR_LIT>'<EOL>logger.info('<STR_LIT>' % (datetime, scan, scans[scan]['<STR_LIT:source>']))<EOL>sourcenum = [kk for kk in sources.keys() if sources[kk]['<STR_LIT:source>'] == scans[scan]['<STR_LIT:source>']][<NUM_LIT:0>]<EOL>direction = me.direction('<STR_LIT>', str(np.degrees(sources[sourcenum]['<STR_LIT>']))+'<STR_LIT>', str(np.degrees(sources[sourcenum]['<STR_LIT>']))+'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>assert '<STR_LIT:/>' in datetime, '<STR_LIT>'<EOL>assert len(radec) == <NUM_LIT:2>, '<STR_LIT>'<EOL>logger.info('<STR_LIT>' % (datetime, direction))<EOL>logger.info('<STR_LIT>')<EOL>ra = radec[<NUM_LIT:0>]; dec = radec[<NUM_LIT:1>]<EOL>direction = me.direction('<STR_LIT>', str(ra)+'<STR_LIT>', str(dec)+'<STR_LIT>')<EOL><DEDENT>sdm = sdmpy.SDM(sdmfile)<EOL>telescopename = sdm['<STR_LIT>'][<NUM_LIT:0>]['<STR_LIT>'].strip()<EOL>logger.debug('<STR_LIT>' % telescopename)<EOL>me.doframe(me.observatory(telescopename))<EOL>me.doframe(me.epoch('<STR_LIT>', datetime))<EOL>me.doframe(direction)<EOL>if scan != <NUM_LIT:0>:<EOL><INDENT>configid = [row.configDescriptionId for row in sdm['<STR_LIT>'] if scan == int(row.scanNumber)][<NUM_LIT:0>]<EOL>antidlist = [row.antennaId for row in sdm['<STR_LIT>'] if configid == row.configDescriptionId][<NUM_LIT:0>].split('<STR_LIT:U+0020>')[<NUM_LIT:2>:]<EOL>stationidlist = [ant.stationId for antid in antidlist for ant in sdm['<STR_LIT>'] if antid == ant.antennaId]<EOL><DEDENT>else:<EOL><INDENT>stationidlist = [ant.stationId for ant in sdm['<STR_LIT>']]<EOL><DEDENT>positions = [station.position.strip().split('<STR_LIT:U+0020>')<EOL>for station in sdm['<STR_LIT>'] <EOL>if station.stationId in stationidlist]<EOL>x = [float(positions[i][<NUM_LIT:2>]) for i in range(len(positions))]<EOL>y = [float(positions[i][<NUM_LIT:3>]) for i in range(len(positions))]<EOL>z = [float(positions[i][<NUM_LIT:4>]) for i in range(len(positions))]<EOL>ants = me.position('<STR_LIT>', qa.quantity(x, '<STR_LIT:m>'), qa.quantity(y, '<STR_LIT:m>'), qa.quantity(z, '<STR_LIT:m>'))<EOL>bls = me.asbaseline(ants)<EOL>uvwlist = me.expand(me.touvw(bls)[<NUM_LIT:0>])[<NUM_LIT:1>]['<STR_LIT:value>']<EOL>u = np.empty(len(uvwlist)/<NUM_LIT:3>); v = np.empty(len(uvwlist)/<NUM_LIT:3>); w = np.empty(len(uvwlist)/<NUM_LIT:3>)<EOL>nants = len(ants['<STR_LIT>']['<STR_LIT:value>'])<EOL>ord1 = [i*nants+j for i in range(nants) for j in range(i+<NUM_LIT:1>,nants)]<EOL>ord2 = [i*nants+j for j in range(nants) for i in range(j)]<EOL>key=[]<EOL>for new in ord2:<EOL><INDENT>key.append(ord1.index(new))<EOL><DEDENT>for i in range(len(key)):<EOL><INDENT>u[i] = uvwlist[<NUM_LIT:3>*key[i]]<EOL>v[i] = uvwlist[<NUM_LIT:3>*key[i]+<NUM_LIT:1>]<EOL>w[i] = uvwlist[<NUM_LIT:3>*key[i]+<NUM_LIT:2>]<EOL><DEDENT>return u, v, w<EOL>
Calculates and returns uvw in meters for a given SDM, time, and pointing direction.
    sdmfile is path to sdm directory that includes "Station.xml" file.
    scan is scan number defined by observatory.
    datetime is time (as string) to calculate uvw (format: '2014/09/03/08:33:04.20')
    radec is (ra,dec) as tuple in units of degrees (format: (180., +45.))