Beispiel #1
0
def get_gal(c):
    gl_all = Longitude(c.galactic.l)
    gl_all.wrap_angle = 180 * u.deg

    gl_start = np.array(gl_all.rad[np.argmax(gl_all) + 1:])
    gl_end = np.array(gl_all.rad[:np.argmax(gl_all)])
    gb_start = np.array(c.galactic.b.rad[np.argmax(gl_all) + 1:])
    gb_end = np.array(c.galactic.b.rad[:np.argmax(gl_all)])
    gl = np.concatenate((gl_start, gl_end)) * (-1)
    gb = np.concatenate((gb_start, gb_end))

    gl0 = np.full(90, gl[0])
    gl1 = np.full(90, gl[len(gl) - 1])
    gb0 = np.linspace(-1.57, gb[0], 90)
    gb1 = np.linspace(gb[len(gb) - 1], -1.57, 90)
    for i in range(len(gl) - 1):
        if (gl[i] * gl[i + 1] < 0 and gl[i] > 3):
            print gl[i], gl[i + 1]
            gl2 = np.full(90, gl[i])
            gb2 = np.linspace(gb[i], 1.57, 90)
            gl3 = np.full(90, gl[i + 1])
            gb3 = np.linspace(1.57, gb[i + 1], 90)
            gl = np.concatenate((gl0, gl[:i], gl2, gl3, gl[i + 1:], gl1))
            gb = np.concatenate((gb0, gb[:i], gb2, gb3, gb[i + 1:], gb1))
            break

    print i
    return gl, gb
Beispiel #2
0
def preprocessing(data, sample_fctr=1, threshold=9500):

    global sample_factor
    sample_factor = sample_fctr

    # 1/ transforms parallax data into distances in parsec
    data_metrics = data
    data_metrics['parallax'] = data_metrics['parallax'].to(
        u.parsec, equivalencies=u.parallax())

    # 2/ Adapt data metrics to a numpy array
    np_data_metrics = np.transpose(
        np.array([
            data_metrics['ra'], data_metrics['dec'], data_metrics['parallax'],
            data_metrics['pmra'], data_metrics['pmdec']
        ]))

    # 3/ Sample data: if a specific sampling is requested or too many points
    n_points = len(np_data_metrics)
    if n_points * sample_factor > threshold:
        sample_factor = threshold / n_points

    if (sample_factor != 1):
        np.random.seed(0)
        idx = np.random.choice(np_data_metrics.shape[0],
                               replace=False,
                               size=int(sample_factor *
                                        np_data_metrics.shape[0]))
        np_data_metrics = np_data_metrics[idx, :]

    # 4/ Change coordinates from Spherical to Cartesian coordinate system
    ra = Longitude(np_data_metrics[:, 0], unit=u.deg)
    ra.wrap_angle = 180 * u.deg
    dec = Latitude(np_data_metrics[:, 1], unit=u.deg)
    dist = Distance(np_data_metrics[:, 2], unit=u.parsec)
    sphe_coordinates = SkyCoord(ra,
                                dec,
                                distance=dist,
                                frame='icrs',
                                representation_type='spherical')
    cart_coordinates = sphe_coordinates.cartesian

    # 5/ Adapt data to normalize it correctly
    data_sphe_adapted = np.transpose(
        np.array([
            sphe_coordinates.ra, sphe_coordinates.dec,
            sphe_coordinates.distance
        ]))
    data_cart_adapted = np.transpose(
        np.array([cart_coordinates.x, cart_coordinates.y, cart_coordinates.z]))
    data_pm_adapted = np_data_metrics[:, 3:5]
    data_all_adapted = np.append(data_cart_adapted, data_pm_adapted, axis=1)

    return (data_sphe_adapted, data_cart_adapted, data_all_adapted)
def preprocessing(data, sample_factor=None):
    #Preprocessing
    data_metrics = data
    data_metrics['parallax'] = data_metrics['parallax'].to(
        u.parsec, equivalencies=u.parallax())
    #Adapt data metrics to a numpy array
    np_data_metrics = np.transpose(
        np.array([
            data_metrics['ra'], data_metrics['dec'], data_metrics['parallax'],
            data_metrics['pmra'], data_metrics['pmdec']
        ]))
    #Sample data
    if (sample_factor != None):
        np.random.seed(0)
        idx = np.random.choice(np_data_metrics.shape[0],
                               size=int(sample_factor *
                                        np_data_metrics.shape[0]),
                               replace=False)
        np_data_metrics = np_data_metrics[idx, :]
    #Change coordinates from Spherical to Cartesian coordinate system
    ra = Longitude(np_data_metrics[:, 0], unit=u.deg)
    ra.wrap_angle = 180 * u.deg
    dec = Latitude(np_data_metrics[:, 1], unit=u.deg)
    dist = Distance(np_data_metrics[:, 2], unit=u.parsec)
    sphe_coordinates = SkyCoord(ra,
                                dec,
                                distance=dist,
                                frame='icrs',
                                representation_type='spherical')
    cart_coordinates = sphe_coordinates.cartesian
    #Adapt data to normalize it correctly
    data_sphe_adapted = np.transpose(
        np.array([
            sphe_coordinates.ra, sphe_coordinates.dec,
            sphe_coordinates.distance
        ]))
    data_cart_adapted = np.transpose(
        np.array([cart_coordinates.x, cart_coordinates.y, cart_coordinates.z]))
    data_pm_adapted = np_data_metrics[:, 3:5]
    data_all_adapted = np.append(data_cart_adapted, data_pm_adapted, axis=1)
    return (data_sphe_adapted, data_cart_adapted, data_all_adapted)
Beispiel #4
0
    # To plot the celestial equator in galactic coordinates
    alpha = np.linspace(-180., 180., 3600.)
    delta0 = np.zeros(len(alpha))
    cline_0 = SkyCoord(ra=alpha * u.degree, dec=(delta0 - 10) * u.degree)
    gl_0, gb_0 = get_gal(cline_0)
    cline_1 = SkyCoord(ra=alpha * u.degree, dec=(delta0 + 30) * u.degree)
    gl_1, gb_1 = get_gal(cline_1)
    sPath_1 = get_path(gl_1, gb_1)
    cline_2 = SkyCoord(ra=alpha * u.degree, dec=(delta0 - 50) * u.degree)
    gl_2, gb_2 = get_gal(cline_2)
    sPath_2 = get_path(gl_2, gb_2)

    cpsr_S = SkyCoord(ra=ra_S * u.deg, dec=dec_S * u.deg)
    gl_S = Longitude(cpsr_S.galactic.l)
    gl_S.wrap_angle = 180 * u.deg
    cpsr_N = SkyCoord(ra=ra_N * u.deg, dec=dec_N * u.deg)
    gl_N = Longitude(cpsr_N.galactic.l)
    gl_N.wrap_angle = 180 * u.deg
    cpsr_MWA = SkyCoord(ra=ra_MWA * u.deg, dec=dec_MWA * u.deg)
    gl_MWA = Longitude(cpsr_MWA.galactic.l)
    gl_MWA.wrap_angle = 180 * u.deg

    plt.figure(figsize=(10, 6), dpi=300)
    bx = plt.subplot(111, projection='mollweide')
    #bx = plt.subplot(111, projection = 'aitoff')

    p_S = bx.scatter(-gl_S.rad,
                     cpsr_S.galactic.b.rad,
                     1.5,
                     lw=0,
Beispiel #5
0
 def displayText(self, value, locale):
     a = Longitude(value, u.deg)
     a.wrap_angle = 180 * u.deg
     value = str(
         a.to_string(unit=u.degree, precision=0, sep=("°", "'", "''")))
     return super(LongDelegate, self).displayText(value, locale)