示例#1
0
def insert_ts_list(ts_map, ts_cut, nside):
    ts_px = numpy.argwhere(ts_map>ts_cut)
    table = ""
    for px in ts_px.T[0]:
        ts = round(ts_map[px],2)
        ra, dec = pix_to_sky(px,nside)
        #ra, dec = hp.pix2ang(nside, px, lonlat=True)
        ra = round(ra, 2)
        dec = round(dec, 2)
        table += content.format(ts, ra, dec)
    return table
示例#2
0
def max_ts(map_path, ts_cut):
    ts_map, header = hp.read_map(map_path, h=True)
    header = dict(header)
    nside = header['NSIDE']
    ts_max = round(numpy.nanmax(ts_map),2)
    px_max = numpy.nanargmax(ts_map)
    ra_max, dec_max = pix_to_sky(px_max,nside)
    # hp.pix2ang(nside, px_max, lonlat=True)
    ra_max = round(ra_max, 2)
    dec_max = round(dec_max, 2)
    ts_list = insert_ts_list(ts_map, ts_cut, nside)
    return ts_max, ra_max, dec_max, ts_list, nside
示例#3
0
def get_coverage(ft2file, ligo_map_file, met_t1, met_t2, theta_cut,
                 zenith_cut):
    ft2data = pyfits.getdata(ft2file)

    ligo_map = hp.read_map(ligo_map_file)

    ligo_ra, ligo_dec = pix_to_sky(range(ligo_map.shape[0]), 512)

    # Filter out pixels with too low probability to gain speed

    interesting_idx = (ligo_map > 1e-7)

    print("Kept %s pixels for considerations in LIGO map" %
          np.sum(interesting_idx))

    # Get entries from the FT2 file every 10 s (cadence)

    start, ra_scz, dec_scz, ra_zenith, dec_zenith = _gtmktime(ft2data,
                                                              met_t1,
                                                              met_t2,
                                                              cadence=30)

    print("\nCoverage will be computed from %.1f to %.1f\n" %
          (start.min(), start.max()))

    coverage = np.zeros_like(start)

    for i, (t, rz, dz, rz2, dz2) in enumerate(
            zip(start, ra_scz, dec_scz, ra_zenith, dec_zenith)):
        # Get the angular distance between the current pointing and
        # all the LIGO pixels

        d = getAngularDistance(rz, dz, ligo_ra[interesting_idx],
                               ligo_dec[interesting_idx])

        zenith = getAngularDistance(rz2, dz2, ligo_ra[interesting_idx],
                                    ligo_dec[interesting_idx])

        # Select the LIGO pixels within the LAT FOV

        idx = (d < theta_cut) & (zenith < zenith_cut)

        coverage[i] = np.sum(ligo_map[interesting_idx][idx])

        sys.stdout.write("\r%.1f percent completed" %
                         ((i + 1) / float(coverage.shape[0]) * 100.0))

    sys.stdout.write("\n")

    return start, coverage
示例#4
0
    else:

        mmin = hpx_ul.min()

    if args.max_percentile != 100:

        mmax = np.percentile(hpx_ul[idx],
                             args.max_percentile,
                             interpolation='nearest')

        mmax_idx = (hpx_ul == mmax).nonzero()[0][0]

        #print mmax_idx

        ra, dec = pix_to_sky(mmax_idx, nside)

        print("%s percentile is %s, at %s, %s" %
              (args.max_percentile, mmax, ra, dec))

    else:

        mmax = hpx_ul.max()

    # Now set to nan all negative or zero pixels

    idx = hpx_ul < 0
    hpx_ul[idx] = np.nan
    if args.cmap == 'jet':
        background = 'w'
        background = 'ivory'
示例#5
0
            ra = ra_dec.ra.degree
            dec = ra_dec.dec.degree
            l = l_b.l.degree
            b = l_b.b.degree

            if hpmap is not None:
                nside = 32
                my_finder = ContourFinder(hpmap, nside)
                hpx = my_finder.map

                idx = sky_to_pix(ra, dec, nside)
                prob = hpx[idx]

                indexes = my_finder.find_contour(0.9)
                cra, cdec = pix_to_sky(indexes, nside)

                cel = SkyCoord(ra=cra * u.degree,
                               dec=cdec * u.degree,
                               frame='fk5')
                gal = cel.transform_to('galactic')
                cl, cb = gal.l.degree, gal.b.degree
                print 'plotting countour...%d points' % len(cl)
                galactic(f,
                         ax,
                         cl,
                         cb,
                         symbol='circle',
                         size=1,
                         color='magenta',
                         prob=None)
        z_title = r'Flux Upper Bound (0.1-1 GeV) [10$^{%.0f}$ cm$^{-2}$ s$^{-1}$]' % np.log10(
            magnitude)
    elif args.map_type == 'TS':
        z_title = r'TS '
        magnitude = 1
    elif args.map_type == 'SIG':
        z_title = r'$\sigma$ '
        magnitude = 1
    else:
        print 'Unrecognized map type %s. Use EFLUX, FLUX or TS' % args.map_type
        exit()
        pass

    MAXVALUE = round(np.nanmax(hpx_ul), 2)
    px_max = np.nanargmax(hpx_ul)
    ra_max, dec_max = pix_to_sky(px_max, nside)

    print 'Minimum Value = ', hpx_ul[idx].min()
    print 'Maximum Value = ', MAXVALUE
    print 'RA,DEC=%f %f MAX= %f' % (ra_max, dec_max, MAXVALUE)

    norm = args.zscale
    ticks = np.logspace(np.log10(mmin / magnitude), np.log10(mmax / magnitude),
                        4),
    if norm == 'linear':
        norm = None
        ticks = np.linspace(mmin / magnitude, mmax / magnitude, 4),
        #mmin=0
        pass
    print 'Normalization of the axis:', norm
    if args.zoom is None: