Exemple #1
0
def test_calc_healpix_for_region():

    ahp = HEALPix(nside=NSIDE, order='ring', frame=TETE())
    ahp_test = HEALPix(nside=NSIDE, order='ring', frame=TETE())

    for target_params in [LMC_params, SMC_params]:
        r = generate_sky_maps.CelestialRegion(target_params)
        r.calc_healpixels_for_region(ahp)
        region_pixels = np.unique(r.pixels)

        corners = calc_box_corners_astropy(target_params)

        n_points = 500
        l = np.linspace(corners[0], corners[1], n_points) * u.deg
        b = np.linspace(corners[2], corners[3], n_points) * u.deg

        LL, BB = np.meshgrid(l, b)
        coords = np.stack((LL.flatten(), BB.flatten()), axis=1)
        pointings = SkyCoord(coords[:, 0], coords[:, 1], frame=Galactic())

        coords_in_region = calc_points_in_circle_original(
            target_params, coords)

        pixels = ahp_test.skycoord_to_healpix(coords_in_region)
        test_pixels = np.unique(pixels.flatten())

        assert np.all(region_pixels == test_pixels)
Exemple #2
0
def test_tete_transforms():
    """
    We test the TETE transforms for proper behaviour here.

    The TETE transforms are tested for accuracy against JPL Horizons in
    test_solar_system.py. Here we are looking to check for consistency and
    errors in the self transform.
    """
    loc = EarthLocation.from_geodetic("-22°57'35.1", "-67°47'14.1", 5186 * u.m)
    time = Time('2020-04-06T00:00')
    p, v = loc.get_gcrs_posvel(time)

    gcrs_frame = GCRS(obstime=time, obsgeoloc=p, obsgeovel=v)
    moon = SkyCoord(169.24113968 * u.deg,
                    10.86086666 * u.deg,
                    358549.25381755 * u.km,
                    frame=gcrs_frame)

    tete_frame = TETE(obstime=time, location=loc)
    # need to set obsgeoloc/vel explicity or skycoord behaviour over-writes
    tete_geo = TETE(obstime=time, location=EarthLocation(*([0, 0, 0] * u.km)))

    # test self-transform by comparing to GCRS-TETE-ITRS-TETE route
    tete_coo1 = moon.transform_to(tete_frame)
    tete_coo2 = moon.transform_to(tete_geo)
    assert_allclose(tete_coo1.separation_3d(tete_coo2),
                    0 * u.mm,
                    atol=1 * u.mm)

    # test TETE-ITRS transform by comparing GCRS-CIRS-ITRS to GCRS-TETE-ITRS
    itrs1 = moon.transform_to(CIRS()).transform_to(ITRS())
    itrs2 = moon.transform_to(TETE()).transform_to(ITRS())
    # this won't be as close since it will round trip through ICRS until
    # we have some way of translating between the GCRS obsgeoloc/obsgeovel
    # attributes and the CIRS location attributes
    assert_allclose(itrs1.separation_3d(itrs2), 0 * u.mm, atol=100 * u.mm)

    # test round trip GCRS->TETE->GCRS
    new_moon = moon.transform_to(TETE()).transform_to(moon)
    assert_allclose(new_moon.separation_3d(moon), 0 * u.mm, atol=1 * u.mm)

    # test round trip via ITRS
    tete_rt = tete_coo1.transform_to(
        ITRS(obstime=time)).transform_to(tete_coo1)
    assert_allclose(tete_rt.separation_3d(tete_coo1), 0 * u.mm, atol=1 * u.mm)

    # ensure deprecated routine remains consistent
    # make sure test raises warning!
    with pytest.warns(AstropyDeprecationWarning, match='The use of'):
        tete_alt = _apparent_position_in_true_coordinates(moon)
    assert_allclose(tete_coo1.separation_3d(tete_alt),
                    0 * u.mm,
                    atol=100 * u.mm)
Exemple #3
0
def test_calc_healpixels_for_region():
    ahp = HEALPix(nside=NSIDE, order='ring', frame=TETE())
    NPIX = hp.nside2npix(NSIDE)
    map = np.zeros(NPIX)

    test_regions = [NGC288_params]

    for region in test_regions:
        r = generate_sky_maps.CelestialRegion(region)
        r.calc_healpixels_for_region(ahp)
        map[r.pixels] += 1.0

        # Approximate test: Compare the combined area of the HEALpixels to the
        # minimum (cartesian) area that the region should cover.
        # True area will always be greater.
        min_expected_area = np.pi * (NGC288_params['l_width'] * u.deg / 2.0)**2
        healpix_area = len(r.pixels) * ahp.pixel_area
        assert healpix_area > min_expected_area.to(u.steradian)

    fig = plt.figure(1, (10, 10))
    hp.mollview(map, title='Test of HEALpix regions')
    hp.graticule()
    plt.tight_layout()
    plt.savefig('test_cone_search_regions.png')
    plt.close(1)
def create_star_density_map(mapDir=STAR_MAP_DIR, nside=NSIDE):
    """Function to create a HEALPix object based on a map of Milky Way stellar
    density generated from the Trilegal galactic model.  These data are in
    Galactic coordinates, so this needs to be rotated in order to map it
    to healpix"""

    star_density_map = load_star_density_data(mapDir=mapDir,
                                              nside=nside,
                                              limiting_mag=24.7)
    hp_star_density = rotateHealpix(star_density_map)
    hp_log_star_density = np.log10(hp_star_density)

    ahp = HEALPix(nside=nside, order='ring', frame=TETE())

    return ahp, hp_log_star_density
Exemple #5
0
def plot_statistics_on_sky(data_dir, statistics):

    NSIDE=64
    ahp = HEALPix(nside=NSIDE, order='ring', frame=TETE())

    coords = SkyCoord(statistics[:,0]*u.deg, statistics[:,1]*u.deg, frame='icrs')
    pixel_index = ahp.skycoord_to_healpix(coords)

    NPIX = hp.nside2npix(NSIDE)
    pixels = np.zeros((NPIX), dtype='int')

    pixels[pixel_index] = statistics[:,5]

    fig = plt.figure(1,(10,10))
    hp.mollview(pixels, title="Gaia Parallax Distribution")
    hp.graticule()
    plt.tight_layout()
    plt.savefig(path.join(data_dir,'gaia_parallax_stddev_map.png'))
    plt.close(1)
Exemple #6
0
def test_regions():
    NPIX = hp.nside2npix(NSIDE)

    ahp = HEALPix(nside=NSIDE, order='ring', frame=TETE())

    #r = generate_sky_maps.CelestialRegion(LMC_params)
    r = generate_sky_maps.CelestialRegion(GalCenter_params)
    #r = generate_sky_maps.CelestialRegion(patho_params)
    #r = generate_sky_maps.CelestialRegion(NGC288_params)
    r.calc_healpixels_for_region(ahp, diagnostics=True)

    map = np.zeros(NPIX)
    map[r.pixels] += 1.0

    fig = plt.figure(1, (10, 10))
    hp.mollview(map, title='Test region')
    hp.graticule()
    plt.tight_layout()
    plt.savefig('region_test_plot.png')
    plt.close(1)
def retrieve_gaia_data_for_map():

    if len(argv) == 1:
        data_dir = input('Please enter the path to the output data directory: ')
    else:
        data_dir = argv[1]

    # Read the Galactic Plane survey priority pointing map, identify those
    # pixels above the given priority threshold, and calculate the spatial
    # coordinates of the corresponding pixels:
    ahp = HEALPix(nside=NSIDE, order='ring', frame=TETE())
    map = hp.read_map(path.join(MAPS_DIR,'GalPlane_priority_map_r.fits'))
    NPIX = hp.nside2npix(NSIDE)
    pixels = np.arange(0,NPIX,1, dtype='int')

    priority_min_threshold = 0.4
    index = (map >= priority_min_threshold,1,0)[0]
    priority_healpixels = np.unique(pixels[index])

    priority_coords = ahp.healpix_to_skycoord(priority_healpixels)
    c = priority_coords[0]

    # For each HEALpix pointing, query the Gaia catalog and retrieve a random
    # sampling of the point source catalog for that sky location:
    tap_service = init_tap_service()

    for i in range(0,len(priority_coords),1):
        coord = priority_coords[i]
        if not check_for_existing_output(data_dir, coord):
            try:
                data = run_async_gaia_tap_query(tap_service, coord)
                output_gaia_to_fits(data_dir,data,coord)
            except requests.exceptions.ConnectionError:
                tap_service = init_tap_service()
                data = run_async_gaia_tap_query(tap_service, coord)
                output_gaia_to_fits(data_dir,data,coord)
Exemple #8
0
            }
            SFR_list.append(sfr)

    return SFR_list


NSIDE = 64
NPIX = hp.nside2npix(NSIDE)

# Trilegal data is in Galactic coordinates, so this needs to be rotated in
# order to map it to healpix
star_density_map = load_star_density_map(limiting_mag=24.7)
hp_star_density = rotateHealpix(star_density_map)
hp_log_star_density = np.log10(hp_star_density)

ahp = HEALPix(nside=NSIDE, order='ring', frame=TETE())

# Galactic Plane survey regions, -85.0 < l <+85.0◦, -10.0 < b <+10.0◦
# Street: griz, cadence 2-3d
# Gonzales survey 1: i, N visits over 10yrs
# Gonzales survey 2: grizy, Year 1 only
# Bono shallow: ugrizy 2-3d cadence (WFD)
# Bono deep: izy, 2-3d cadence (WFD)
# Straeder: ugrizy 2-3d cadence or rolling
filterset_gp = {'u': 0.1, 'g': 0.3, 'r': 0.3, 'i': 0.3, 'z': 0.2, 'y': 0.1}
gp_region_pix1 = calc_hp_pixels_for_region(43.5, 0.0, 90.0, 20.0, 500, ahp)
gp_region_pix2 = calc_hp_pixels_for_region(317.5, 0.0, 90.0, 20.0, 500, ahp)
gp_region_pix = np.concatenate(
    (gp_region_pix1.flatten(), gp_region_pix2.flatten()))

filterset_Gonzalez_gp = {
Exemple #9
0
 def create_map(self):
     self.NSIDE = 64
     self.ahp = HEALPix(nside=self.NSIDE, order='ring', frame=TETE())
def test_astroby_skyfield_horizons():
    """
    ### Astropy 與 Skyfield 取得太陽座標對照表

    * 基本上,Astropy 的 get_obj 會得到從地心看太陽的 GCRS 赤道座標,對應於 Skyfield 的 earth.at(t).observe(sun).apparent()。

    * Astropy 用 gcrscoord.transform_to(GeocentricTrueEcliptic(equinox = t)) 將 GCRS 赤道座標轉成真時黃道座標(true ecliptic),
        對應於 Skyfield 的 gcrscoord.frame_latlon(ecliptic_frame)。
    """
    timestr = "2021-4-20 9:37"
    t_astropy = Time(timestr, scale='utc')
    solar_system_ephemeris.set('de430.bsp')
    sun_astropy_apparent = get_body('sun', t_astropy)
    t_skyfield = ts.utc(2021, 4, 20, 9, 37)
    sun_skyfield_astrometric = earth.at(t_skyfield).observe(sun).radec()
    sun_skyfield_apparent = earth.at(t_skyfield).observe(sun).apparent()
    # print(sun_skyfield_astrometric)
    print("\n比較 GCRS astrometric")
    print("sun_skyfield_astrometric", sun_skyfield_astrometric[0]._degrees,
          sun_skyfield_astrometric[1]._degrees, sun_skyfield_astrometric[2].km)
    # 比較 GCRS
    print("\n比較 GCRS apparent")
    print(sun_astropy_apparent)
    print('sun_astropy_apparent in (deg,deg,km) :',
          sun_astropy_apparent.ra.deg, sun_astropy_apparent.dec.deg,
          sun_astropy_apparent.distance.km)
    radec_skyfield = sun_skyfield_apparent.radec()
    print('sun_skyfield_apparent in (deg,deg,km) :',
          radec_skyfield[0]._degrees, radec_skyfield[1]._degrees,
          radec_skyfield[2].km)

    # 比較 GeocentricTrueEcliptic
    print('\n比較 GeocentricTrueEcliptic')
    sun_ecliptic_astropy = sun_astropy_apparent.transform_to(
        GeocentricTrueEcliptic(equinox=t_astropy))
    sun_ecliptic_skyfield = sun_skyfield_apparent.frame_latlon(ecliptic_frame)
    print(sun_ecliptic_astropy)
    print(sun_ecliptic_skyfield[1]._degrees, sun_ecliptic_skyfield[0]._degrees,
          sun_ecliptic_skyfield[2].km)

    # 比較 TETE
    print('\n比較 TreeEclipticTrueEquator(TETE)')
    sun_tete_astropy = sun_astropy_apparent.transform_to(
        TETE(obstime=t_astropy))
    sun_tete_skyfield = sun_skyfield_apparent.radec(epoch='date')
    print(sun_tete_astropy)
    print(sun_tete_skyfield[0]._degrees, sun_tete_skyfield[1]._degrees,
          sun_tete_skyfield[2].km)

    sun_by_earth = Horizons(id='10',
                            id_type='majorbody',
                            location='500',
                            epochs={
                                'start': "2021-4-20 9:37",
                                'stop': "2021-4-20 9:38",
                                'step': '1'
                            })
    sun_by_earth_ephem = sun_by_earth.ephemerides(quantities='1,2,4,20,31')
    print("jpl 資料")
    print(sun_by_earth_ephem['RA', 'DEC', 'RA_app', 'DEC_app', 'delta',
                             'ObsEclLon', 'ObsEclLat'])

    # 比較 AltAz
    print("\n比較 AltAz")
    location_astropy = EarthLocation(lon=121 * u.deg,
                                     lat=25 * u.deg,
                                     height=0 * u.m)
    moon_taipei_astropy = get_body('moon', t_astropy, location_astropy)
    # print(moon_taipei_astropy)
    _altaz_astropy = AltAz(obstime=t_astropy, location=location_astropy)
    moon_taipei_altaz_astropy = moon_taipei_astropy.transform_to(
        _altaz_astropy)
    print("moon_taipei_altaz_astropy: ", moon_taipei_altaz_astropy)

    taipei = earth + wgs84.latlon(25 * N, 121 * E, elevation_m=0)
    moon_taipei_skyfield = taipei.at(t_skyfield).observe(moon).apparent()
    alt, az, distance = moon_taipei_skyfield.altaz()
    print("moon_taipei_altaz_skyfield: ", az._degrees, alt._degrees,
          distance.km)

    moon_by_taipei = Horizons(id='301',
                              id_type='majorbody',
                              location={
                                  'lon': 121,
                                  'lat': 25,
                                  'elevation': 0
                              },
                              epochs={
                                  'start': "2021-4-20 9:37",
                                  'stop': "2021-4-20 9:38",
                                  'step': '1'
                              })
    moon_by_taipei_ephem = moon_by_taipei.ephemerides(quantities='1,2,4,20,31')
    print("moon_taipei_jpl (AZ EL)", moon_by_taipei_ephem['AZ', 'EL'])
def test_rges_survey_region():
    survey = galBulgeRubinRomanMetrics.RGESSurvey()
    ahp = HEALPix(nside=64, order='ring', frame=TETE())
    survey.calcHealpix(ahp)

    assert len(survey.pixels > 0)