Example #1
0
def equatorial_to_ecliptic(input_xyz, backwards=False):
    '''
        Convert an cartesian vector from mean equatorial to mean ecliptic.
        backwards=True converts backwards, from ecliptic to equatorial.
        input:
            input_xyz - np.array length 3
            backwards - boolean
        output:
            output_xyz - np.array length 3
    '''
    direction = -1 if backwards else +1
    rotation_matrix = mpc.rotate_matrix(-mpc.Constants.ecl * direction)
    output_xyz = np.dot(rotation_matrix, input_xyz.reshape(-1, 1)).flatten()
    return output_xyz
Example #2
0
    def __init__(self):

        # Filing ...
        #self.HP     = '_healpix.txt'

        # Healpix ...
        self.HP_nside = 16
        self.HP_order = 'nested'
        self.HPix = HEALPix(nside=self.HP_nside, order=self.HP_order)
        self.HP_npix = self.HPix.npix

        # sqlite database specs ...
        self.db_filename = 'sifter.db'

        # MPC Observatory list:
        self.obsCodes = mpc.Observatory()
Example #3
0
def ecliptic_to_equatorial(input, backwards=False):
    '''
    Rotates a cartesian vector or Cov-Matrix from mean ecliptic to mean equatorial.
    
    Backwards=True converts backwards, from equatorial to ecliptic.
    
    inputs:
    -------
    input : 1-D or 2-D arrays
     - If 1-D, then len(input) must be 3 or 6
     - If 2-D, then input.shape must be (6,6)
     
    output:
    -------
    output : np.ndarray
     - same shape as input
    '''

    # Ensure we have an array
    input = np.atleast_1d(input)

    # The rotation matricees we may use
    direction = -1 if backwards else +1
    R3 = mpc.rotate_matrix(mpc.Constants.ecl * direction)
    R6 = np.block([[R3, np.zeros((3, 3))], [np.zeros((3, 3)), R3]])

    # Vector input => Single rotation operation
    if input.ndim == 1 and input.shape[0] in [3, 6]:
        R = R6 if input.shape[0] == 6 else R3
        output = R @ input

    # Matrix (CoV) input => R & R.T
    elif input.ndim == 2 and input.shape == (6, 6):
        R = R6
        output = R @ input @ R.T

    # Unknown input
    else:
        sys.exit(
            f'Does not compute: input.ndim=={input.ndim} , input.shape={input.shape}'
        )

    assert output.shape == input.shape
    return output
Example #4
0
def get_heliocentric_equatorial_XYZ_from_MPC(times, obs_code='500',
                                             verbose=False):
    '''
    Get the heliocentric EQUATORIAL vector coordinates of the
    observatory at the time jd_utc.
    '''
    # MPC_library imported here, as it is an optional dependancy
    from mpcpp import MPC_library as mpc
    obsCodes = mpc.Observatory()
    helio_OBS_equ = []
    # Make sure time is an array or list
    times_utc = np.array([times]) if (isinstance(times, int) |
                                      isinstance(times, float)) else times
    for jd_utc in times_utc:
        hom = obsCodes.getObservatoryPosition(obsCode=obs_code, jd_utc=jd_utc,
                                              old=False)
        helio_OBS_equ.append(hom)
        if verbose:
            print('MPC XYZ:')
            print(f'Heliocentric position of observatory: {hom} au\n')

    return np.array(helio_OBS_equ)
def ecliptic_to_equatorial(input_xyz, backwards=False):
    '''
    Convert a cartesian vector from mean ecliptic to mean equatorial.
    backwards=True converts backwards, from equatorial to ecliptic.
    input:
        input_xyz - np.array length 3 or 6
        backwards - boolean
    output:
        output_xyz - np.array length 3 or 6

    ### Is this HELIOCENTRIC or BARYCENTRIC??? Either way seems to work...
    '''
    direction = -1 if backwards else +1
    if isinstance(input_xyz, list):
        input_xyz = np.array(input_xyz)
    rotation_matrix = mpc.rotate_matrix(mpc.Constants.ecl * direction)
    output_xyz = np.zeros_like(input_xyz)
    output_xyz[:3] = np.dot(rotation_matrix,
                            input_xyz[:3].reshape(-1, 1)).flatten()
    if len(output_xyz) == 6:
        output_xyz[3:6] = np.dot(rotation_matrix,
                                 input_xyz[3:6].reshape(-1, 1)).flatten()
    return output_xyz
Example #6
0
 def __init__(self):
     # MPC Observatory list:
     self.obsCodes = mpc.Observatory()
Example #7
0
    input_xyz = list(hor_in_table.as_array()[0])
    expected_output_xyz = np.array(list(hor_out_table.as_array()[0]))

    # Call the function we want to test
    output_xyz = parse_input.ecliptic_to_equatorial(input_xyz)

    # Each element should be within 15mm or 1.5mm/day
    error = np.abs(expected_output_xyz - output_xyz)
    assert np.all(error[:3] < 1e-13)  # XYZ accurate to 15 milli-metres
    assert np.all(error[3:6] < 1e-14)  # V accurate to 1.5 milli-metres/day
    print('test_ecliptic_to_equatorial successful!')


# Getting the rotn matrix ecliptic_to_equatorial & vice-versa
direction = -1
R3_eq_to_ecl = mpc.rotate_matrix(mpc.Constants.ecl * direction)
R6_eq_to_ecl = np.block([[R3_eq_to_ecl, np.zeros((3, 3))],
                         [np.zeros((3, 3)), R3_eq_to_ecl]])
direction = +1
R3_ecl_to_eq = mpc.rotate_matrix(mpc.Constants.ecl * direction)
R6_ecl_to_eq = np.block([[R3_ecl_to_eq, np.zeros((3, 3))],
                         [np.zeros((3, 3)), R3_ecl_to_eq]])

names_of_variables = ('input_helio_ecl_cov', 'expected_bary_eq_cov',
                      'comments')
# see 'https://www.visiondummy.com/2014/04/geometric-interpretation-covariance-matrix/'
values_for_each_test = [
    (np.eye(6), np.eye(6), 'rotating identity does nothing'),
    (np.zeros([6, 6]), np.zeros([6, 6]), 'rotating zeros does nothing'),
    (R6_ecl_to_eq, R6_ecl_to_eq, 'when input CoV ~ Rotn Matrix'),
    (R6_eq_to_ecl, R6_eq_to_ecl, 'when input CoV ~ Rotn Matrix'),