def mms_pgs_mphigeo(mag_temp, pos_temp): """ Generates the 'mphigeo' transformation matrix """ pos_data = get_data(pos_temp) if pos_data is None: logging.error('Error with position data') return # the following is heisted from the IDL version # transformation to generate other_dim dim for mphigeo from thm_fac_matrix_make # All the conversions to polar and trig simplifies to this. # But the reason the conversion is why this is the conversion that is done, is lost on me. # The conversion swaps the x & y components of position, reflects over x=0,z=0 then projects into the xy plane pos_conv = np.stack( (-pos_data.y[:, 1], pos_data.y[:, 0], np.zeros(len(pos_data.times)))) pos_conv = np.transpose(pos_conv, [1, 0]) store_data(pos_temp, data={'x': pos_data.times, 'y': pos_conv}) # transform into GSE because the particles are in GSE cotrans(name_in=pos_temp, name_out=pos_temp, coord_in='gei', coord_out='gse') # create orthonormal basis set z_basis = tnormalize(mag_temp, return_data=True) x_basis = tcrossp(z_basis, pos_temp, return_data=True) x_basis = tnormalize(x_basis, return_data=True) y_basis = tcrossp(z_basis, x_basis, return_data=True) return (x_basis, y_basis, z_basis)
def test_tnormalize(self): """ tests for normalizing tplot variables""" store_data('test_tnormalize', data={ 'x': [1, 2, 3, 4, 5], 'y': [[3, 2, 1], [1, 2, 3], [10, 5, 1], [8, 10, 14], [70, 20, 10]] }) norm = tnormalize('test_tnormalize') normalized_data = get_data(norm) self.assertTrue( np.round(normalized_data.y[0, :], 4).tolist() == [0.8018, 0.5345, 0.2673]) self.assertTrue( np.round(normalized_data.y[1, :], 4).tolist() == [0.2673, 0.5345, 0.8018]) self.assertTrue( np.round(normalized_data.y[2, :], 4).tolist() == [0.8909, 0.4454, 0.0891]) self.assertTrue( np.round(normalized_data.y[3, :], 4).tolist() == [0.4216, 0.527, 0.7379]) self.assertTrue( np.round(normalized_data.y[4, :], 4).tolist() == [0.9526, 0.2722, 0.1361])
def xgse(mag_temp): """ Generates the 'xgse' transformation matrix """ mag_data = get_data(mag_temp) # xaxis of this system is X of the gse system. Z is mag field x_axis = np.zeros((len(mag_data.times), 3)) x_axis[:, 0] = 1 # create orthonormal basis set z_basis = tnormalize(mag_temp, return_data=True) y_basis = tcrossp(z_basis, x_axis, return_data=True) y_basis = tnormalize(y_basis, return_data=True) x_basis = tcrossp(y_basis, z_basis, return_data=True) return (x_basis, y_basis, z_basis)
def cart_trans_matrix_make(x, y, z): ndim = x.ndim if ndim == 2: ex = tnormalize(x, return_data=True) ey = tnormalize(y, return_data=True) ez = tnormalize(z, return_data=True) mat_out = np.concatenate([ex, ey, ez], 1).reshape(x.shape[0], 3, 3) elif ndim == 1: ex = x/np.sqrt((x*x).sum()) ey = y/np.sqrt((y*y).sum()) ez = z/np.sqrt((z*z).sum()) mat_out = np.array([ex, ey, ez]).T return mat_out
def dsi2j2000(name_in=None, name_out=None, no_orb=False, J20002DSI=False, noload=False): """ This function transform a time series data between the DSI and J2000 coordinate systems Parameters: name_in : str input tplot variable to be transformed name_out : str Name of the tplot variable in which the transformed data is stored J20002DSI : bool Set to transform data from J2000 to DSI. If not set, it transforms data from DSI to J2000. Returns: None """ if (name_in is None) or (name_in not in tplot_names(quiet=True)): print('Input of Tplot name is undifiend') return if name_out is None: print('Tplot name for output is undifiend') name_out = 'result_of_dsi2j2000' # prepare for transformed Tplot Variable reload = not noload dl_in = get_data(name_in, metadata=True) get_data_array = get_data(name_in) time_array = get_data_array[0] time_length = time_array.shape[0] dat = get_data_array[1] # Get the SGI axis by interpolating the attitude data dsiz_j2000 = erg_interpolate_att(name_in, noload=noload)['sgiz_j2000'] # Sun direction in J2000 sundir = np.array([[1., 0., 0.]]*time_length) if no_orb: store_data('sundir_gse', data={'x': time_array, 'y': sundir}) else: # Calculate the sun directions from the instantaneous satellite locations if reload: tr = get_timespan(name_in) orb(trange=time_string([tr[0] - 60., tr[1] + 60.])) tinterpol('erg_orb_l2_pos_gse', time_array) scpos = get_data('erg_orb_l2_pos_gse-itrp')[1] sunpos = np.array([[1.496e+08, 0., 0.]]*time_length) sundir = sunpos - scpos store_data('sundir_gse', data={'x': time_array, 'y': sundir}) tnormalize('sundir_gse', newname='sundir_gse') # Derive DSI-X and DSI-Y axis vectors in J2000. # The elementary vectors below are the definition of DSI. The detailed relationship # between the spin phase, sun pulse timing, sun direction, and the actual subsolar point # on the spining s/c body should be incorporated into the calculation below. if reload: cotrans(name_in='sundir_gse', name_out='sundir_j2000', coord_in='gse', coord_out='j2000') sun_j2000 = get_data('sundir_j2000') dsiy = tcrossp(dsiz_j2000['y'], sun_j2000[1], return_data=True) dsix = tcrossp(dsiy, dsiz_j2000['y'], return_data=True) dsix_j2000 = {'x': time_array, 'y': dsix} dsiy_j2000 = {'x': time_array, 'y': dsiy} if not J20002DSI: print('DSI --> J2000') mat = cart_trans_matrix_make( dsix_j2000['y'], dsiy_j2000['y'], dsiz_j2000['y']) j2000x_in_dsi = np.dot(mat, np.array([1., 0., 0.])) j2000y_in_dsi = np.dot(mat, np.array([0., 1., 0.])) j2000z_in_dsi = np.dot(mat, np.array([0., 0., 1.])) mat = cart_trans_matrix_make( j2000x_in_dsi, j2000y_in_dsi, j2000z_in_dsi) dat_new = np.einsum("ijk,ik->ij", mat, dat) else: print('J2000 --> DSI') mat = cart_trans_matrix_make( dsix_j2000['y'], dsiy_j2000['y'], dsiz_j2000['y']) dat_new = np.einsum("ijk,ik->ij", mat, dat) store_data(name_out, data={'x': time_array, 'y': dat_new}, attr_dict=dl_in) options(name_out, 'ytitle', '\n'.join(name_out.split('_')))