コード例 #1
0
def coordshift(ra, dec, rashift, decshift):
  # shift ra and dec by rashift and decshift
  # ra: string in the hh:mm:ss.ss format
  # dec: string in the dd.mm.ss.ss format
  # rashift: float in arcsec
  # dechift: float in arcsec
  (hh, mm, ss) = cm.ratohms(cm.hmstora(*ra.split(":")) + rashift/3600)
  ra = str(hh)+":"+str(mm)+":"+ '%.3f' % ss
  (dd, mm, ss) = cm.dectodms(cm.dmstodec(*dec.split(".",2)) + decshift/3600)
  dec = "+"+str(dd)+"."+str(mm)+"."+ '%.3f' % ss
  return ra, dec
コード例 #2
0
# toplabel in months
#ax.set_(r'')

types = np.dtype({'names':['name', 'ra', 'dec'], 'formats':['S100','S100','S100']})
data = np.loadtxt(sys.argv[1], comments='#', usecols=(0,1,2), unpack=False, dtype=types)
me = pm.measures()
position = me.position('wgs84',qa.quantity(3826600.961,'m'),qa.quantity(460953.402,'m'),qa.quantity(5064881.136,'m')) # superterp
me.doframe(position)

y=1
for obj in data:
        print "Work on: ", obj['name']
        rah, ram, ras = obj['ra'].split(':')
        ra = cm.hmstora(float(rah), float(ram), float(ras)) # in deg
        decd, decm, decs = obj['dec'].split(':')
        dec = cm.dmstodec(float(decd), float(decm), float(decs)) # in deg
        for d in xrange(360):
                # count how many h the source is at elev>30 when sun is at elev<0
                observable = 0
                for h in xrange(24):
                        t = 2456293.5-2400000.5+d+h/24. # MJD for 1/1/2013 + the hours
                        obj_elev, sun_elev = get_elev(t,ra,dec)
                        #print "RESULTS:", obj_elev, sun_elev
                        if obj_elev>30 and sun_elev<0: observable+=1
                # plot in greyscale from 0 to 12 h
                print d,y,observable
                ax.plot(d,y,c=str(observable/24.))
        ax.text(1,y,obj['name'])
        y+=1

ax.set_ylim(ymin=0, ymax=y)
コード例 #3
0
def read_skymodel(skymodel, fields=[]):
    """
    Read a skymodel file (BBS format)
    skymodel -- the skymodel file generated by PyBDSM
    fields -- list of fields to load
    Return:
    numpy array with all the sources in the skymodel
    """
    names = []
    formats = []
    usecols = []
    converters = {}
    filling_values = {}

    f = open(skymodel, 'r')
    header = f.readline()
    # remove useless part of the header
    header = re.sub(r'\s', '', header)
    header = re.sub(r'\)=format', '', header)
    header = re.sub(r'#\(', '', header)
    headers = header.split(',')
    for i, h in enumerate(headers):

        if not h in fields and fields != []: continue

        # if there's a default value, set it and remove it from the header name
        if re.search('=', h):
            default_value = re.sub(r'.*=', '', h).replace('\'','')
            filling_values[i]=default_value 
            h = re.sub(r'=.*', '', h)

        names.append(h)
        usecols.append(i)

        if h == "Ra":
            formats.append(np.float)
            converters[i] = lambda x: cm.hmstora(float(x.split(':')[0]),float(x.split(':')[1]),float(x.split(':')[2])) if x else 0.0

        elif h == "Dec":
            formats.append(np.float)
            converters[i] = lambda x: cm.dmstodec(float(x.split('.')[0]),float(x.split('.')[1]),float(x.split('.')[2])) if x else 0.0

        elif h == "I" or h == "Q" or h == "U" or h == "V" or h == "ReferenceFrequency" or h == "MajorAxis" or h == "MinorAxis" or h == "Orientation":
            formats.append(np.float)
            if not i in filling_values:
                if h == "I": filling_values[i]=1
                else: filling_values[i]=0
            else:
                filling_values[i]=np.float(filling_values[i])

        # note that SpectralIndex also end up as a string with no comma!!
        else:
            formats.append('S100')

    types = np.dtype({'names':names,'formats':formats})

    n = len(types)-1

    # generator
    def fileiter(skymodel, n):
        for line in open(skymodel,'r'):
            # remove comments, patches and white lines
            if line[0] == '#' or line[0] == ',' or len(line) == 1: continue
            #  remove commas inside [] for spidx and leave one space
            spidx_part = re.search(r'\[.*\]', line).group(0).replace(',',' ')
            spidx_part = re.sub('\s{2,}', ' ', spidx_part)
            line = re.sub(r'\[.*\]', spidx_part, line)
            # add the missing commas at the end of the lines
            n_commas = line.count(',')
            missing_commas = n - n_commas
            yield line+','*missing_commas

    skymodel_data = np.genfromtxt(fileiter(skymodel, n), names=names, comments='#', unpack=True, dtype=formats, delimiter=',', autostrip=True, usecols=usecols, converters=converters, filling_values=filling_values)
    if 'SpectralIndex' in skymodel_data.dtype.fields:
        for skymodel_datum in skymodel_data:
            skymodel_datum['SpectralIndex'] = skymodel_datum['SpectralIndex'].replace(' ',',')

    return skymodel_data
コード例 #4
0
  ccname = cc[PosName]
  ccra = cc[PosRA]
  ccdec = cc[PosDec]
  ccpatch = cc[PosPatch]
  ccspidx = cc[PosSpidx]
  ccI = float(cc[PosI])
   
  # first do the coordinate shift (assuming mask and spidx image have correct coordinates!)
  if shift != None:
    (ra, dec) = coordshift(ra, dec, rashift, decshift)
    ccra = ra; ccdec = dec

  if mask != None:
    (a,b,_,_) = maskdata.toworld([0,0,0,0])
    (_, _, pixY, pixX) = maskdata.topixel([a, b, \
      math.radians(cm.dmstodec(*ccdec.split(".",2))), math.radians(cm.hmstora(*ccra.split(":")))])
    try:
      # != is a XOR for booleans
      if (not maskval[math.floor(pixY)][math.floor(pixX)]) != reverse:
        totFluxMask += ccI
        if patchprefix == None:
            if verbose: print("Removing component \"",ccname,"\" because it is masked.")
            continue
        else:
            if verbose: print("Renameing patch for \"",ccname,"\" because it is masked.")
            # add to the list of patches to update
            if ccpatch not in patchtoupdate: patchtoupdate.append(ccpatch)
      else:
        totFluxOutMask += ccI

    except:
コード例 #5
0
                  usecols=(0, 1, 2),
                  unpack=False,
                  dtype=types)
me = pm.measures()
position = me.position('wgs84', qa.quantity(3826600.961, 'm'),
                       qa.quantity(460953.402, 'm'),
                       qa.quantity(5064881.136, 'm'))  # superterp
me.doframe(position)

y = 1
for obj in data:
    print("Work on: ", obj['name'])
    rah, ram, ras = obj['ra'].split(':')
    ra = cm.hmstora(float(rah), float(ram), float(ras))  # in deg
    decd, decm, decs = obj['dec'].split(':')
    dec = cm.dmstodec(float(decd), float(decm), float(decs))  # in deg
    for d in range(360):
        # count how many h the source is at elev>30 when sun is at elev<0
        observable = 0
        for h in range(24):
            t = 2456293.5 - 2400000.5 + d + h / 24.  # MJD for 1/1/2013 + the hours
            obj_elev, sun_elev = get_elev(t, ra, dec)
            #print "RESULTS:", obj_elev, sun_elev
            if obj_elev > 30 and sun_elev < 0: observable += 1
        # plot in greyscale from 0 to 12 h
        print(d, y, observable)
        ax.plot(d, y, c=str(observable / 24.))
    ax.text(1, y, obj['name'])
    y += 1

ax.set_ylim(ymin=0, ymax=y)