Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup CI(GH Actions) for pull requests and pushes #15

Merged
merged 5 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/test_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Python package

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install -r requirements_dev.txt
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
pip install pytest-cov
pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
if: matrix.python-version == '3.8'
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
yml: ./codecov.yml
fail_ci_if_error: true
46 changes: 46 additions & 0 deletions .github/workflows/test_pull_requests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Python package

on: [pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install -r requirements_dev.txt
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
pip install pytest-cov
pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
if: matrix.python-version == '3.8'
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
yml: ./codecov.yml
fail_ci_if_error: true
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ space
:target: https://space.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://codecov.io/gh/LaboratoryOfPlasmaPhysics/space/branch/main/graph/badge.svg?branch=main
:target: https://codecov.io/gh/LaboratoryOfPlasmaPhysics/space/branch/main
:alt: Coverage Status



Expand Down
4 changes: 4 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ coverage==4.5.4
Sphinx==1.8.5
twine==1.14.0

ddt
pandas
numpy
matplotlib
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
with open('HISTORY.rst') as history_file:
history = history_file.read()

requirements = ['pandas', 'numpy', 'matplotlib']
requirements = ['pandas', 'numpy', 'matplotlib', 'scipy']

setup_requirements = []

Expand Down
135 changes: 72 additions & 63 deletions space/coordinates/coordinates.py
Original file line number Diff line number Diff line change
@@ -1,91 +1,100 @@
import numpy as np
import pandas as pd
from datetime import timedelta, datetime


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)
y = R * np.sin(theta) * np.cos(phi)
z = R * np.sin(theta) * np.sin(phi)
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)
return r,theta,phi

def BaseChoice(base,R,theta,phi):
if base=='cartesian' :
return spherical_to_cartesian(R,theta,phi)
elif base=='spherical' :
return R,theta,phi
else :

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)
return r, theta, phi


def base_choice(base, R, theta, phi):
if base == 'cartesian':
return spherical_to_cartesian(R, theta, phi)
elif base == 'spherical':
return R, theta, phi
else:
print('Error : base 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' )):
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' )) :
elif (hasattr(pos, 'R')) | (hasattr(pos, 'r')):
base = 'spherical'
elif (hasattr(pos, 'X' )) | (hasattr(pos, 'x' )) :
elif (hasattr(pos, 'X')) | (hasattr(pos, 'x')):
base = 'cartesian'
else :
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':
r,theta,phi = CartesianToSpherical(pos.X,pos.Y,pos.Z)
else :
r,theta,phi = pos.R, pos.theta, pos.phi
r=r+cst
x,y,z = spherical_to_cartesian(r,theta,phi)
return pd.DataFrame({'X' : x, 'Y' : y, 'Z' :z})

def SWI_base(omni_data):
norm_V =np.sqrt(omni_data.Vx**2+(omni_data.Vy+29.8)**2+omni_data.Vz**2)
X = np.array([-np.array([vx,vy+29.8,vz])/V for vx,vy,vz,V in zip( omni_data.Vx.values, omni_data.Vy.values, omni_data.Vz.values,norm_V)])
B = np.array([np.array([bx,by,bz]) for bx,by,bz in zip( np.sign(omni_data.COA.values)*omni_data.Bx.values, np.sign(omni_data.COA.values)*omni_data.By.values, np.sign(omni_data.COA.values)*omni_data.Bz.values)])
def add_cst_radiuus(pos, cst):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

radiuus ?

base = check_base(pos)
if base == 'cartesian':
r, theta, phi = cartesian_to_spherical(pos.X, pos.Y, pos.Z)
else:
r, theta, phi = pos.R, pos.theta, pos.phi
r = r + cst
x, y, z = spherical_to_cartesian(r, theta, phi)
return pd.DataFrame({'X': x, 'Y': y, 'Z': z})


Z = np.cross(X,B)
def swi_base(omni_data):
norm_V = np.sqrt(omni_data.Vx ** 2 + (omni_data.Vy + 29.8) ** 2 + omni_data.Vz ** 2)
X = np.array([-np.array([vx, vy + 29.8, vz]) / V for vx, vy, vz, V in
zip(omni_data.Vx.values, omni_data.Vy.values, omni_data.Vz.values, norm_V)])
B = np.array([np.array([bx, by, bz]) for bx, by, bz in zip(np.sign(omni_data.COA.values) * omni_data.Bx.values,
np.sign(omni_data.COA.values) * omni_data.By.values,
np.sign(omni_data.COA.values) * omni_data.Bz.values)])

norm_cross = np.array(np.sqrt(Z[:,0]**2+Z[:,1]**2+Z[:,2]**2))
Z = np.array([z/n for z,n in zip(Z,norm_cross)])
Y = np.cross(Z,X)
return X,Y,Z
Z = np.cross(X, B)

norm_cross = np.array(np.sqrt(Z[:, 0] ** 2 + Z[:, 1] ** 2 + Z[:, 2] ** 2))
Z = np.array([z / n for z, n in zip(Z, norm_cross)])
Y = np.cross(Z, X)
return X, Y, Z


def to_swi(omni_data, msh_data, pos_msh):
X_swi, Y_swi, Z_swi = SWI_base(omni_data)
X_swi, Y_swi, Z_swi = swi_base(omni_data)
data = msh_data.copy()
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'] + 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
Loading