Skip to content

Commit

Permalink
More prints swapped
Browse files Browse the repository at this point in the history
  • Loading branch information
kstppd committed Aug 28, 2024
1 parent 0dc998b commit a4522a3
Show file tree
Hide file tree
Showing 36 changed files with 234 additions and 198 deletions.
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
1 change: 1 addition & 0 deletions 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 Down
3 changes: 2 additions & 1 deletion 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 @@ -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', 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
11 changes: 6 additions & 5 deletions pyCalculations/fieldtracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import pytools as pt
import warnings
from scipy import interpolate
import logging

def dynamic_field_tracer( vlsvReader_list, x0, max_iterations, dx):
''' Field tracer in a dynamic time frame
Expand Down Expand Up @@ -119,7 +120,7 @@ def static_field_tracer( vlsvReader, x0, max_iterations, dx, direction='+', bvar
coordinates = np.array([x,y,z])
# Debug:
if( len(x) != sizes[0] ):
print("SIZE WRONG: " + str(len(x)) + " " + str(sizes[0]))
logging.info("SIZE WRONG: " + str(len(x)) + " " + str(sizes[0]))

# Create grid interpolation
interpolator_face_B_0 = interpolate.RectBivariateSpline(coordinates[indices[0]] - 0.5*dcell[indices[0]], coordinates[indices[1]], face_B[indices[0]], kx=2, ky=2, s=0)
Expand All @@ -144,17 +145,17 @@ def static_field_tracer( vlsvReader, x0, max_iterations, dx, direction='+', bvar
coordinates = np.array([x,y,z])
# Debug:
if( len(x) != sizes[0] ):
print("SIZE WRONG: " + str(len(x)) + " " + str(sizes[0]))
logging.info("SIZE WRONG: " + str(len(x)) + " " + str(sizes[0]))

# Create grid interpolation
interpolator_vol_B_0 = interpolate.RectBivariateSpline(coordinates[indices[0]], coordinates[indices[1]], vol_B[indices[0]], kx=2, ky=2, s=0)
interpolator_vol_B_1 = interpolate.RectBivariateSpline(coordinates[indices[0]], coordinates[indices[1]], vol_B[indices[1]], kx=2, ky=2, s=0)
interpolators = [interpolator_vol_B_0, interpolator_vol_B_1]#, interpolator_face_B_2]
elif centering == 'node':
print("Nodal variables not implemented")
logging.info("Nodal variables not implemented")
return
else:
print("Unrecognized centering:", centering)
logging.info("Unrecognized centering:", centering)
return

#######################################################
Expand Down Expand Up @@ -217,7 +218,7 @@ def fg_trace(vlsvReader, fg, seed_coords, max_iterations, dx, multiplier, stop_c
z = np.arange(mins[2], maxs[2], dcell[2]) + 0.5*dcell[2]

if centering is None:
print("centering keyword not set! Aborting.")
logging.info("centering keyword not set! Aborting.")
return False

# Create grid interpolation object for vector field (V). Feed the object the component data and locations of measurements.
Expand Down
1 change: 1 addition & 0 deletions pyCalculations/find_x_and_o.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from scipy.signal import convolve2d
from shapely import geometry
from numpy import linalg as LA
import logging

## This script searches for the x and o points from the 2D simulations. It assumes polar plane. If you use equatorial plane change the z_array to y_array and it's limits.
## It uses the contours of grad(flux_function) to find the extrema and Hessian matrix to define the type of the point (minima, maxima, saddle)
Expand Down
1 change: 1 addition & 0 deletions pyCalculations/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'''In this file there are functions that have something to do with fitting data
'''

import logging
def subtract_1d_polynomial_fit( x, y ):
''' Fits 1d polynomial into the data, subtracts it from the given data and returns the subtracted data.
Expand Down
3 changes: 2 additions & 1 deletion pyCalculations/fourier.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#

# Function for taking 1d and 2d fourier transforms here.
import logging

def fourier( t, y, kaiserwindowparameter=0 ):
''' Function for returning fourier series and frequencies of some given arrays t and y
Expand Down Expand Up @@ -54,7 +55,7 @@ def fourier( t, y, kaiserwindowparameter=0 ):

#for i in xrange(len(get_data(t))-1):
# if t != get_data(t)[i+1] - get_data(t)[i]:
# print "Gave bad timestep to plot_fourier, the time step in array t must be constant (for now)"
# logging.info "Gave bad timestep to plot_fourier, the time step in array t must be constant (for now)"
# Use kaiser window on y
import numpy as np
y_tmp = get_data(y) * np.kaiser(len(get_data(y)), kaiserwindowparameter)
Expand Down
1 change: 1 addition & 0 deletions pyCalculations/gyrophaseangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import numpy as np
import pylab as pl
from rotation import rotateVectorToVector
import logging

def gyrophase_angles_from_file( vlsvReader, cellid):
''' Calculates the gyrophase angle angle distribution for a given cell with a given file
Expand Down
7 changes: 4 additions & 3 deletions pyCalculations/ids3d.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import logging

# finds the cell ids which are needed to plot a 2d cut through out of a 3d mesh # WARNING! works only if cellids is sorted
def ids3d(cellids, depth, reflevel,
Expand All @@ -21,7 +22,7 @@ def ids3d(cellids, depth, reflevel,
for i in range(reflevel+1):
depth = int(pro*size*2**i) + 1 # goes from 1 to Nmax
if depth > int(size*2**i):
print("depth error ",depth,i)
logging.info("depth error ",depth,i)
depth -= 1
depths.append(depth)

Expand Down Expand Up @@ -91,7 +92,7 @@ def idmesh3d(idlist, data, reflevel, xsize, ysize, zsize, xyz, datadimension):
elif np.ndim(datadimension) == 1:
dpoints = np.zeros(np.append(dims, (datadimension[0], datadimension[1])).astype(int))
else:
print("Error finding data dimension in idmesh3d")
logging.info("Error finding data dimension in idmesh3d")
return -1

######################
Expand Down Expand Up @@ -171,7 +172,7 @@ def idmesh3d2(idlist, data, reflevel, xsize, ysize, zsize, datadimension):
elif np.ndim(datadimension) == 1:
dpoints = np.zeros(np.append(dims, (datadimension[0], datadimension[1])).astype(int))
else:
print("Error finding data dimension in idmesh3d")
logging.info("Error finding data dimension in idmesh3d")
return -1

######################
Expand Down
Loading

0 comments on commit a4522a3

Please sign in to comment.