Skip to content

Commit

Permalink
Merge pull request #18 from BayaneMdW/model
Browse files Browse the repository at this point in the history
Model
  • Loading branch information
nicolasaunai authored Apr 16, 2021
2 parents 9c666dd + d887aa0 commit 4204d3e
Show file tree
Hide file tree
Showing 6 changed files with 730 additions and 266 deletions.
100 changes: 47 additions & 53 deletions space/coordinates/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,40 @@
import pandas as pd


def spherical_to_cartesian(R, theta, phi):
x = R * np.cos(theta)
y = R * np.sin(theta) * np.cos(phi)
z = R * np.sin(theta) * np.sin(phi)
def spherical_to_cartesian(r, theta, phi):
x = r * np.cos(theta)
y = r * np.sin(theta) * np.sin(phi)
z = r * np.sin(theta) * np.cos(phi)
return x, y, z

def cylindrical_to_cartesian(r, theta):
x = r * np.cos(theta)
y = r * np.sin(theta)
z = r * np.sin(theta)
return x, y, z

def cartesian_to_spherical(X, Y, Z):
r = np.sqrt(X ** 2 + Y ** 2 + Z ** 2)
theta = np.arccos(X / r)
phi = np.arctan2(Z, Y)
def cartesian_to_spherical(x, y, z):
r = np.sqrt(x ** 2 + y ** 2 + z ** 2)
theta = np.arccos(x / r)
phi = np.arctan2(y, z)
phi[z==0]=np.sign(y)*np.pi/2
return r, theta, phi


def base_choice(base, R, theta, phi):
if base == 'cartesian':
def choice_coordinate_system(R, theta, phi, **kwargs):
coord_sys = kwargs.get('coord_sys','cartesian')
if coord_sys == 'cartesian':
return spherical_to_cartesian(R, theta, phi)
elif base == 'spherical':
elif coord_sys == 'spherical':
return R, theta, phi
else:
print('Error : base parameter must be set to "cartesian" or "spherical" ')

print('Error : coord_sys parameter must be set to "cartesian" or "spherical" ')

def check_base(pos):
if ((hasattr(pos, 'R')) | (hasattr(pos, 'r'))) & (hasattr(pos, 'X')) | (hasattr(pos, 'x')):
base = 'spherical&cartesian'
elif (hasattr(pos, 'R')) | (hasattr(pos, 'r')):
base = 'spherical'
elif (hasattr(pos, 'X')) | (hasattr(pos, 'x')):
base = 'cartesian'
else:
print('must check the name of the variables : cartesian = (X,Y,Z) and spherical = (R,theta,phi)')

return base


def add_cst_radiuus(pos, cst):
base = check_base(pos)
if base == 'cartesian':
def add_cst_radiuus(pos, cst,coord_sys):
if coord_sys == 'cartesian':
r, theta, phi = cartesian_to_spherical(pos.X, pos.Y, pos.Z)
else:
r, theta, phi = pos.R, pos.theta, pos.phi
Expand Down Expand Up @@ -71,30 +66,29 @@ def to_swi(omni_data, msh_data, pos_msh):
o_data = omni_data.copy()
pos = pos_msh.copy()

o_data['Vx'] = X_swi[:, 0] * omni_data['Vx'] + X_swi[:, 1] * omni_data['Vy'] + X_swi[:, 2] * omni_data['Vz']
o_data['Vy'] = Y_swi[:, 0] * omni_data['Vx'] + Y_swi[:, 1] * omni_data['Vy'] + Y_swi[:, 2] * omni_data['Vz']
o_data['Vz'] = Z_swi[:, 0] * omni_data['Vx'] + Z_swi[:, 1] * omni_data['Vy'] + Z_swi[:, 2] * omni_data['Vz']

o_data['Bx'] = np.sign(omni_data['COA']) * (
X_swi[:, 0] * omni_data['Bx'] + X_swi[:, 1] * omni_data['By'] + X_swi[:, 2] * omni_data['Bz'])
o_data['By'] = np.sign(omni_data['COA']) * (
Y_swi[:, 0] * omni_data['Bx'] + Y_swi[:, 1] * omni_data['By'] + Y_swi[:, 2] * omni_data['Bz'])
o_data['Bz'] = np.sign(omni_data['COA']) * (
Z_swi[:, 0] * omni_data['Bx'] + Z_swi[:, 1] * omni_data['By'] + Z_swi[:, 2] * omni_data['Bz'])

data['Vx'] = X_swi[:, 0] * msh_data['Vx'] + X_swi[:, 1] * msh_data['Vy'] + X_swi[:, 2] * msh_data['Vz']
data['Vy'] = Y_swi[:, 0] * msh_data['Vx'] + Y_swi[:, 1] * msh_data['Vy'] + Y_swi[:, 2] * msh_data['Vz']
data['Vz'] = Z_swi[:, 0] * msh_data['Vx'] + Z_swi[:, 1] * msh_data['Vy'] + Z_swi[:, 2] * msh_data['Vz']

data['Bx'] = np.sign(omni_data['COA']) * (
X_swi[:, 0] * msh_data['Bx'] + X_swi[:, 1] * msh_data['By'] + X_swi[:, 2] * msh_data['Bz'])
data['By'] = np.sign(omni_data['COA']) * (
Y_swi[:, 0] * msh_data['Bx'] + Y_swi[:, 1] * msh_data['By'] + Y_swi[:, 2] * msh_data['Bz'])
data['Bz'] = np.sign(omni_data['COA']) * (
Z_swi[:, 0] * msh_data['Bx'] + Z_swi[:, 1] * msh_data['By'] + Z_swi[:, 2] * msh_data['Bz'])

pos['X'] = X_swi[:, 0] * pos_msh['X'] + X_swi[:, 1] * pos_msh['Y'] + X_swi[:, 2] * pos_msh['Z']
pos['Y'] = Y_swi[:, 0] * pos_msh['X'] + Y_swi[:, 1] * pos_msh['Y'] + Y_swi[:, 2] * pos_msh['Z']
pos['Z'] = Z_swi[:, 0] * pos_msh['X'] + Z_swi[:, 1] * pos_msh['Y'] + Z_swi[:, 2] * pos_msh['Z']

return data, pos, o_data


o_data['Vx'] = X_swi[:,0]*omni_data['Vx']+X_swi[:,1]*(omni_data['Vy']+29.8)+X_swi[:,2]*omni_data['Vz']
o_data['Vy'] = Y_swi[:,0]*omni_data['Vx']+Y_swi[:,1]*(omni_data['Vy']+29.8)+Y_swi[:,2]*omni_data['Vz']
o_data['Vz'] = Z_swi[:,0]*omni_data['Vx']+Z_swi[:,1]*(omni_data['Vy']+29.8)+Z_swi[:,2]*omni_data['Vz']

o_data['Bx'] = np.sign(omni_data['COA'])*(X_swi[:,0]*omni_data['Bx']+X_swi[:,1]*omni_data['By']+X_swi[:,2]*omni_data['Bz'])
o_data['By'] = np.sign(omni_data['COA'])*(Y_swi[:,0]*omni_data['Bx']+Y_swi[:,1]*omni_data['By']+Y_swi[:,2]*omni_data['Bz'])
o_data['Bz'] = np.sign(omni_data['COA'])*(Z_swi[:,0]*omni_data['Bx']+Z_swi[:,1]*omni_data['By']+Z_swi[:,2]*omni_data['Bz'])

data['Vx'] = X_swi[:,0]*msh_data['Vx']+X_swi[:,1]*msh_data['Vy']+X_swi[:,2]*msh_data['Vz']
data['Vy'] = Y_swi[:,0]*msh_data['Vx']+Y_swi[:,1]*msh_data['Vy']+Y_swi[:,2]*msh_data['Vz']
data['Vz'] = Z_swi[:,0]*msh_data['Vx']+Z_swi[:,1]*msh_data['Vy']+Z_swi[:,2]*msh_data['Vz']

data['Bx'] = np.sign(omni_data['COA'])*(X_swi[:,0]*msh_data['Bx']+X_swi[:,1]*msh_data['By']+X_swi[:,2]*msh_data['Bz'])
data['By'] = np.sign(omni_data['COA'])*(Y_swi[:,0]*msh_data['Bx']+Y_swi[:,1]*msh_data['By']+Y_swi[:,2]*msh_data['Bz'])
data['Bz'] = np.sign(omni_data['COA'])*(Z_swi[:,0]*msh_data['Bx']+Z_swi[:,1]*msh_data['By']+Z_swi[:,2]*msh_data['Bz'])


pos['X'] = X_swi[:,0]*pos_msh['X']+X_swi[:,1]*pos_msh['Y']+X_swi[:,2]*pos_msh['Z']
pos['Y'] = Y_swi[:,0]*pos_msh['X']+Y_swi[:,1]*pos_msh['Y']+Y_swi[:,2]*pos_msh['Z']
pos['Z'] = Z_swi[:,0]*pos_msh['X']+Z_swi[:,1]*pos_msh['Y']+Z_swi[:,2]*pos_msh['Z']


return data,pos,o_data

Loading

0 comments on commit 4204d3e

Please sign in to comment.