packages/vaex-astro/vaex/astro/transformations.py
def add_virtual_columns_proper_motion_eq2gal(self, long_in="ra", lat_in="dec", pm_long="pm_ra", pm_lat="pm_dec", pm_long_out="pm_l", pm_lat_out="pm_b",
                                            name_prefix="__proper_motion_eq2gal",
                                            right_ascension_galactic_pole=192.85,
                                            declination_galactic_pole=27.12,
                                            propagate_uncertainties=False,
                                            radians=False, inverse=False):
    """Transform/rotate proper motions from equatorial to galactic coordinates

    Taken from http://arxiv.org/abs/1306.2945

    :param long_in: Name/expression for right ascension
    :param lat_in: Name/expression for declination
    :param pm_long: Proper motion for ra
    :param pm_lat: Proper motion for dec
    :param pm_long_out:  Output name for output proper motion on l direction
    :param pm_lat_out: Output name for output proper motion on b direction
    :param name_prefix:
    :param radians: input and output in radians (True), or degrees (False)
    :parap inverse: (For internal use) convert from galactic to equatorial instead
    :return:
    """
    """mu_gb =  mu_dec*(cdec*sdp-sdec*cdp*COS(ras))/cgb $
      - mu_ra*cdp*SIN(ras)/cgb"""
    long_in_original = long_in = self._expr(long_in)
    lat_in_original = lat_in = self._expr(lat_in)
    pm_long = self._expr(pm_long)
    pm_lat = self._expr(pm_lat)
    if not radians:
        long_in = long_in * np.pi/180
        lat_in = lat_in * np.pi/180
    c1_name = name_prefix + "_C1"
    c2_name = name_prefix + "_C2"
    right_ascension_galactic_pole = math.radians(right_ascension_galactic_pole)
    declination_galactic_pole = math.radians(declination_galactic_pole)
    self[c1_name] = c1 = np.sin(declination_galactic_pole) * np.cos(lat_in) - np.cos(declination_galactic_pole)*np.sin(lat_in)*np.cos(long_in-right_ascension_galactic_pole)
    self[c2_name] = c2 = np.cos(declination_galactic_pole) * np.sin(long_in - right_ascension_galactic_pole)
    c1 = self[c1_name]
    c2 = self[c2_name]
    if inverse:
        self[pm_long_out] = ( c1 * pm_long + -c2 * pm_lat)/np.sqrt(c1**2+c2**2)
        self[pm_lat_out] =  ( c2 * pm_long +  c1 * pm_lat)/np.sqrt(c1**2+c2**2)
    else:
        self[pm_long_out] = ( c1 * pm_long + c2 * pm_lat)/np.sqrt(c1**2+c2**2)
        self[pm_lat_out] =  (-c2 * pm_long + c1 * pm_lat)/np.sqrt(c1**2+c2**2)
    if propagate_uncertainties:
        self.propagate_uncertainties([self[pm_long_out], self[pm_lat_out]])
def add_virtual_columns_proper_motion_eq2gal(self, long_in="ra", lat_in="dec", pm_long="pm_ra", pm_lat="pm_dec", pm_long_out="pm_l", pm_lat_out="pm_b",
                                            name_prefix="__proper_motion_eq2gal",
                                            right_ascension_galactic_pole=192.85,
                                            declination_galactic_pole=27.12,
                                            propagate_uncertainties=False,
                                            radians=False, inverse=False):
    """Transform/rotate proper motions from equatorial to galactic coordinates

    Taken from http://arxiv.org/abs/1306.2945

    :param long_in: Name/expression for right ascension
    :param lat_in: Name/expression for declination
    :param pm_long: Proper motion for ra
    :param pm_lat: Proper motion for dec
    :param pm_long_out:  Output name for output proper motion on l direction
    :param pm_lat_out: Output name for output proper motion on b direction
    :param name_prefix:
    :param radians: input and output in radians (True), or degrees (False)
    :parap inverse: (For internal use) convert from galactic to equatorial instead
    :return:
    """
    """mu_gb =  mu_dec*(cdec*sdp-sdec*cdp*COS(ras))/cgb $
      - mu_ra*cdp*SIN(ras)/cgb"""
    long_in_original = long_in = self._expr(long_in)
    lat_in_original = lat_in = self._expr(lat_in)
    pm_long = self._expr(pm_long)
    pm_lat = self._expr(pm_lat)
    if not radians:
        long_in = long_in * np.pi/180
        lat_in = lat_in * np.pi/180
    c1_name = name_prefix + "_C1"
    c2_name = name_prefix + "_C2"
    right_ascension_galactic_pole = math.radians(right_ascension_galactic_pole)
    declination_galactic_pole = math.radians(declination_galactic_pole)
    self[c1_name] = c1 = np.sin(declination_galactic_pole) * np.cos(lat_in) - np.cos(declination_galactic_pole)*np.sin(lat_in)*np.cos(long_in-right_ascension_galactic_pole)
    self[c2_name] = c2 = np.cos(declination_galactic_pole) * np.sin(long_in - right_ascension_galactic_pole)
    c1 = self[c1_name]
    c2 = self[c2_name]
    if inverse:
        self[pm_long_out] = ( c1 * pm_long + -c2 * pm_lat)/np.sqrt(c1**2+c2**2)
        self[pm_lat_out] =  ( c2 * pm_long +  c1 * pm_lat)/np.sqrt(c1**2+c2**2)
    else:
        self[pm_long_out] = ( c1 * pm_long + c2 * pm_lat)/np.sqrt(c1**2+c2**2)
        self[pm_lat_out] =  (-c2 * pm_long + c1 * pm_lat)/np.sqrt(c1**2+c2**2)
    if propagate_uncertainties:
        self.propagate_uncertainties([self[pm_long_out], self[pm_lat_out]])
Transform/rotate proper motions from equatorial to galactic coordinates

    Taken from http://arxiv.org/abs/1306.2945

    :param long_in: Name/expression for right ascension
    :param lat_in: Name/expression for declination
    :param pm_long: Proper motion for ra
    :param pm_lat: Proper motion for dec
    :param pm_long_out:  Output name for output proper motion on l direction
    :param pm_lat_out: Output name for output proper motion on b direction
    :param name_prefix:
    :param radians: input and output in radians (True), or degrees (False)
    :parap inverse: (For internal use) convert from galactic to equatorial instead
    :return: