casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
astro_stations2simdata.py
Go to the documentation of this file.
00001 from simutil import simutil
00002 
00003 pdbi = {'long': '05:54:28.5', # deg East
00004         'lat': '44:38:02.0',  # deg
00005         'alt': 2550,          # m
00006         'diam': 15,           # m
00007         'a': 'w27 e04 E24 E68 N29 N46',
00008         'b': 'W27 W12 E12 E23 N20 N46',
00009         'c': 'W12 W09 E04 E10 N11 N17',
00010         'd': 'W08 W05 E03 N02 N07 N11'}
00011 
00012 def dms2d(dms):
00013     """
00014     Given a d:m:s string, return it as a float in degrees.
00015     """
00016     d, m, s = map(float, dms.split(':'))
00017     m += s / 60.0
00018     m /= 60.0
00019     if dms[0] == '-':
00020         d -= m
00021     else:
00022         d += m
00023     return d
00024 
00025 def astro_stations2simdata(aststatfn):
00026     """
00027     Reads aststatfn and writes it to simdata compatible antennalists
00028     pdbi-a.cfg, pdbi-b.cfg, pdbi-c.cfg, and pdbi-d.cfg.
00029 
00030     aststatfn: gildas-src-mmmxxx/packages/astro/etc/astro_stations.dat
00031                1st line is ignored: 800  / Largest baseline length
00032                The rest are:
00033                             ITRF relative to PdBI center (m)
00034                Station      X          Y              Z
00035     simdatfn:  simdata compatible configuration file, in ITRF.
00036     """
00037     mysim = simutil()
00038     pdbi['itrf'] = mysim.locxyz2itrf(dms2d(pdbi['lat']), dms2d(pdbi['long']),
00039                                      locz=pdbi['alt'])
00040     
00041     statdict = {}
00042     asf = open(aststatfn, 'r')
00043     line = asf.readline()         # Skip 1st line.
00044     for line in asf:
00045         stn, xstr, ystr, zstr = line.strip().split()
00046         statdict[stn] = [float(c) + d for (c, d) in zip((xstr, ystr, zstr), pdbi['itrf'])]
00047     asf.close()
00048     for cfg in ('a', 'b', 'c', 'd'):
00049         stns = [s.upper() for s in pdbi[cfg].split()]
00050         ofile = open('pdbi-' + cfg + '.cfg', 'w')
00051         ofile.write('# observatory=IRAM_PDB\n') # Is the _ necessary?
00052         ofile.write('# coordsys=XYZ\n')
00053         ofile.write('#\n')
00054         ofile.write('# Plateau de Bure %s configuration,\n' % cfg.upper())
00055         ofile.write('# converted to simdata format from\n#  %s\n#    (%s)\n'
00056                     % (aststatfn, time.strftime("%Y-%m-%d",
00057                                                 time.localtime(os.path.getmtime(aststatfn)))))
00058         ofile.write('# by recipes.astro_stations2simdata\n')
00059         ofile.write('#\n')
00060         ofile.write('#       X              Y                Z       Diam  Station\n')
00061         for stn in stns:
00062             ofile.write('% 14.12g  % 14.12g  % 14.12g  %4.1f  %s\n' %
00063                         (statdict[stn][0],
00064                          statdict[stn][1],
00065                          statdict[stn][2],
00066                          pdbi['diam'],
00067                          stn))
00068         ofile.close()
00069