Skip to content

Commit

Permalink
Merge branch 'master' into zeroth-order-intp
Browse files Browse the repository at this point in the history
  • Loading branch information
alhom authored Sep 18, 2024
2 parents 29411e1 + ef2dceb commit aca66c5
Show file tree
Hide file tree
Showing 60 changed files with 2,303 additions and 804 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python import test

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:

latest:

runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4
- name: Set up Python #${{ matrix.python-version }}
uses: actions/setup-python@v3
# with:
# python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m pip install numpy scipy matplotlib scikit-image # add versions to matrix
- name: Trial imports
run: python -c 'import pytools as pt'

import-matrix:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.9", "3.10", "3.11"]
# matplotlib-version: ["3.3.0", "3.5.3"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m pip install numpy scipy matplotlib scikit-image # add versions to matrix
- name: Trial imports
run: python -c 'import pytools as pt'


lint:

runs-on: ubuntu-latest
#continue-on-error: true
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python -m pip install numpy scipy matplotlib scikit-image # add versions to matrix
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --extend-exclude=trash_can,pyMayaVi
# 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 --extend-exclude=trash_can,pyMayaVi
9 changes: 8 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#################################################

# Install dependencies:
sudo apt-get install mayavi2 python-matplotlib python-numpy python-scipy ipython
sudo apt-get install python-matplotlib python-numpy python-scipy ipython

# Set pythonpath environment variable:
echo "export PYTHONPATH=$PYTHONPATH:$HOME/analysator" >> $HOME/.bashrc
Expand Down Expand Up @@ -36,12 +36,19 @@ export PTBACKEND=Qt5Agg
#################################################
export PTNOLATEX=1

#Analysator is using logging. It is controlled by setting the enviroment variable ANALYSATOR_LOG_LEVEL
#################################################
Supported: INFO (default)

# MayaVi2 support (deprecated)
#################################################
Some old plotting tools requiring the MayaVi2 visualization library can be activated
by setting the environment variable:
export PTMAYAVI2=1

This naturally depends on mayavi, so:
sudo apt-get install mayavi2

# For setting the default output directory (default: $HOME/Plots)
#################################################
export PTOUTPUTDIR=/proj/USERNAME/Plots/
Expand Down
6 changes: 3 additions & 3 deletions examples/generate_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ def cavitoncontours(ax, XmeshXY,YmeshXY, extmaps, requestvariables=False):
# it has access to the name of the .vlsv file, and then calls plot_vdf to
# create insets on top of the variable map.
def insetVDF(ax, XmeshXY,YmeshXY, pass_maps):
if requestvariables==True:
return []
# if requestvariables==True: # Never triggers, copy-paste leftovers?
# return []
# pass_maps is a list of numpy arrays, not used here.
from mpl_toolkits.axes_grid1.inset_locator import inset_axes

Expand Down Expand Up @@ -365,7 +365,7 @@ def insetVDF(ax, XmeshXY,YmeshXY, pass_maps):
vmin=1e-2,
vmax=1e0,
pass_vars=['E','B','V'],
expression=expr_Slippage)
expression=pt.plot.plot_helpers.expr_Slippage)


# Plot beam number density with inset VDF
Expand Down
2 changes: 1 addition & 1 deletion examples/multi_panel_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


# Avoids opening a figure window
if str(matplotlib.get_backend()) is not 'Agg':
if str(matplotlib.get_backend()) != 'Agg':
plt.switch_backend('Agg')

fileLocation="/proj/vlasov/2D/BCH/bulk/"
Expand Down
1 change: 1 addition & 0 deletions pyCalculations/backstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#

import numpy as np
import logging

def extract_velocity_cells_sphere( vlsvReader, cellid, origin, radius ):
''' Extracts the velocity cells inside some given sphere
Expand Down
3 changes: 2 additions & 1 deletion pyCalculations/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'''

# List of functions and classes that should be imported into the interface
import logging
from intpol_file import vlsv_intpol_file
from intpol_points import vlsv_intpol_points
from cutthrough import cut_through, cut_through_step, cut_through_curve, cut_through_swath
Expand All @@ -57,5 +58,5 @@
import fit
from fieldtracer import static_field_tracer, static_field_tracer_3d
from fieldtracer import dynamic_field_tracer
from non_maxwellianity import epsilon_M
from interpolator_amr import AMRInterpolator

7 changes: 4 additions & 3 deletions pyCalculations/cut3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#NOT IMPLEMENTED YET

import numpy as np
import logging

def cut3d( vlsvReader, xmin, xmax, ymin, ymax, zmin, zmax, variable, operator="pass", trim_array=False ):
''' Retrieves variables for the given 3d cut
Expand Down Expand Up @@ -62,8 +63,8 @@ def cut3d( vlsvReader, xmin, xmax, ymin, ymax, zmin, zmax, variable, operator="p
# Read the cell lengths:
##################################################
# Get xmax, xmin and xcells_ini
mesh_limits = f.get_spatial_mesh_extent()
mesh_size = f.get_spatial_mesh_size()
mesh_limits = vlsvReader.get_spatial_mesh_extent()
mesh_size = vlsvReader.get_spatial_mesh_size()
xmax = mesh_limits[3]
xmin = mesh_limits[0]
xcells = mesh_size[0]
Expand Down Expand Up @@ -102,7 +103,7 @@ def cut3d( vlsvReader, xmin, xmax, ymin, ymax, zmin, zmax, variable, operator="p
min_coordinates[1] + j*cell_lengths[1],
min_coordinates[2] + k*cell_lengths[2]
])
#print str(k) + " " + str(j) + " " + str(i) + " " + str(np.shape(array))
#logging.info str(k) + " " + str(j) + " " + str(i) + " " + str(np.shape(array))
array[k][j][i] = vlsvReader.read_variable(variable, cellids=vlsvReader.get_cellid(coordinates), operator=operator)

# Close optimization
Expand Down
47 changes: 24 additions & 23 deletions pyCalculations/cutthrough.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import numpy as np
import sys
import logging

def get_cellids_coordinates_distances( vlsvReader, xmax, xmin, xcells, ymax, ymin, ycells, zmax, zmin, zcells, cell_lengths, point1, point2 ):
''' Calculates coordinates to be used in the cut_through. The coordinates are calculated so that every cell gets picked in the coordinates.
Expand Down Expand Up @@ -59,7 +60,7 @@ def get_cellids_coordinates_distances( vlsvReader, xmax, xmin, xcells, ymax, ymi
# Get the cell id
cellid = vlsvReader.get_cellid(iterator)
if cellid == 0:
print("ERROR, invalid cell id!")
logging.info("ERROR, invalid cell id!")
return
# Get the max and min boundaries:
min_bounds = vlsvReader.get_cell_coordinates(cellid) - 0.5 * cell_lengths
Expand Down Expand Up @@ -127,8 +128,8 @@ def cut_through( vlsvReader, point1, point2 ):
cut_through = cut_through(vlsvReader, [0,0,0], [2,5e6,0])
cellids = cut_through[0]
distances = cut_through[1]
print \"Cell ids: \" + str(cellids)
print \"Distance from point 1 for every cell: \" + str(distances)
logging.info \"Cell ids: \" + str(cellids)
logging.info \"Distance from point 1 for every cell: \" + str(distances)
'''
# Transform point1 and point2 into numpy array:
point1 = np.array(point1)
Expand All @@ -151,9 +152,9 @@ def cut_through( vlsvReader, point1, point2 ):

# Make sure point1 and point2 are inside bounds
if vlsvReader.get_cellid(point1) == 0:
print("ERROR, POINT1 IN CUT-THROUGH OUT OF BOUNDS!")
logging.info("ERROR, POINT1 IN CUT-THROUGH OUT OF BOUNDS!")
if vlsvReader.get_cellid(point2) == 0:
print("ERROR, POINT2 IN CUT-THROUGH OUT OF BOUNDS!")
logging.info("ERROR, POINT2 IN CUT-THROUGH OUT OF BOUNDS!")

#Calculate cell lengths:
cell_lengths = np.array([(xmax - xmin)/(float)(xcells), (ymax - ymin)/(float)(ycells), (zmax - zmin)/(float)(zcells)])
Expand All @@ -167,7 +168,7 @@ def cut_through_swath(vlsvReader, point1, point2, width, normal):
init_cut = cut_through(vlsvReader, point1, point2)
init_cids = init_cut[0].data

print('swath initial CellIds', init_cids)
logging.info('swath initial CellIds' + str(init_cids))

#find the other vector spanning the swath
s = np.array(point2)-np.array(point1)
Expand All @@ -183,7 +184,7 @@ def cut_through_swath(vlsvReader, point1, point2, width, normal):
out_cids.append(temp_cut[0].data)

init_cut[0] = np.array(out_cids)
print(init_cut[0])
logging.info(init_cut[0])
return init_cut

def cut_through_step( vlsvReader, point1, point2 ):
Expand All @@ -203,18 +204,18 @@ def cut_through_step( vlsvReader, point1, point2 ):
cut_through = cut_through_step(vlsvReader, [0,0,0], [2,5e6,0])
cellids = cut_through[0]
distances = cut_through[1]
print \"Cell ids: \" + str(cellids)
print \"Distance from point 1 for every cell: \" + str(distances)
logging.info \"Cell ids: \" + str(cellids)
logging.info \"Distance from point 1 for every cell: \" + str(distances)
'''
# Transform point1 and point2 into numpy array:
point1 = np.array(point1)
point2 = np.array(point2)

# Make sure point1 and point2 are inside bounds
if vlsvReader.get_cellid(point1) == 0:
print("ERROR, POINT1 IN CUT-THROUGH OUT OF BOUNDS!")
logging.info("ERROR, POINT1 IN CUT-THROUGH OUT OF BOUNDS!")
if vlsvReader.get_cellid(point2) == 0:
print("ERROR, POINT2 IN CUT-THROUGH OUT OF BOUNDS!")
logging.info("ERROR, POINT2 IN CUT-THROUGH OUT OF BOUNDS!")

# Find path
distances = point2-point1
Expand All @@ -223,9 +224,9 @@ def cut_through_step( vlsvReader, point1, point2 ):
derivative = distances/abs(distances[largestindex])

# Re=6371000.
# print("distances",distances/Re)
# print("largestindex",largestindex)
# print("derivative",derivative)
# logging.info("distances",distances/Re)
# logging.info("largestindex",largestindex)
# logging.info("derivative",derivative)

# Get parameters from the file to determine a good length between points (step length):
# Get xmax, xmin and xcells_ini
Expand All @@ -241,7 +242,7 @@ def cut_through_step( vlsvReader, point1, point2 ):
cellids = [vlsvReader.get_cellid(point1)]
coordinates = [point1]
finalcellid = vlsvReader.get_cellid(point2)
#print(" cellids init ",cellids,finalcellid)
#logging.info(" cellids init ",cellids,finalcellid)

# Loop until final cellid is reached
while True:
Expand All @@ -251,7 +252,7 @@ def cut_through_step( vlsvReader, point1, point2 ):
distances.append( np.linalg.norm( newcoordinate - point1 ) )
coordinates.append(newcoordinate)
cellids.append(newcellid)
#print(distances[-1]/Re,np.array(coordinates[-1])/Re,cellids[-1])
#logging.info(distances[-1]/Re,np.array(coordinates[-1])/Re,cellids[-1])

if newcellid==finalcellid:
break
Expand Down Expand Up @@ -280,8 +281,8 @@ def cut_through_curve(vlsvReader, curve):
cut_through_curve = cut_through(vlsvReader, [[0,0,0], [2,5e6,0]])
cellids = cut_through[0]
distances = cut_through[1]
print \"Cell ids: \" + str(cellids)
print \"Distance from point 1 for every cell: \" + str(distances)
logging.info \"Cell ids: \" + str(cellids)
logging.info \"Distance from point 1 for every cell: \" + str(distances)
'''
# init cut_through static values, then do what cut_through does for each segment
# Get parameters from the file to determine a good length between points (step length):
Expand All @@ -305,7 +306,7 @@ def cut_through_curve(vlsvReader, curve):
cell_lengths = np.array([(xmax - xmin)/(float)(xcells), (ymax - ymin)/(float)(ycells), (zmax - zmin)/(float)(zcells)])

if(len(curve) < 2):
print("ERROR, less than 2 points in a curve")
logging.info("ERROR, less than 2 points in a curve")
return None

cellIds = []
Expand All @@ -316,9 +317,9 @@ def cut_through_curve(vlsvReader, curve):
point2 = np.array(curve[i+1])
# Make sure point1 and point2 are inside bounds
if vlsvReader.get_cellid(point1) == 0:
print("ERROR, POINT1 IN CUT-THROUGH-CURVE OUT OF BOUNDS!")
logging.info("ERROR, POINT1 IN CUT-THROUGH-CURVE OUT OF BOUNDS!")
if vlsvReader.get_cellid(point2) == 0:
print("ERROR, POINT2 IN CUT-THROUGH-CURVE OUT OF BOUNDS!")
logging.info("ERROR, POINT2 IN CUT-THROUGH-CURVE OUT OF BOUNDS!")
cut = get_cellids_coordinates_distances( vlsvReader, xmax, xmin, xcells, ymax, ymin, ycells, zmax, zmin, zcells, cell_lengths, point1, point2)
ccid = cut[0].data
cedges = cut[1].data
Expand All @@ -331,7 +332,7 @@ def cut_through_curve(vlsvReader, curve):
edges.append(edgestart+cedges[ci])
coords.append(cut[2].data[ci])

#print('sum of diffs', np.sum(np.diff(edges)))
#logging.info('sum of diffs', np.sum(np.diff(edges)))
#reduce the cellIDs and edges
reduct = True
if reduct:
Expand All @@ -351,7 +352,7 @@ def cut_through_curve(vlsvReader, curve):
cid0 = c1
rEdges.append(edges[-1])
rCoords.append(coords[-1])
#print('sum of r-diffs', np.sum(np.diff(rEdges)))
#logging.info('sum of r-diffs', np.sum(np.diff(rEdges)))
else:
rCellIds = cellIds
rEdges = edges
Expand Down
Loading

0 comments on commit aca66c5

Please sign in to comment.