Skip to content
Snippets Groups Projects
Commit 73eab16c authored by Yngve Levinsen's avatar Yngve Levinsen
Browse files

added new functions to default import __init__.py

renamed fieldmapy -> fieldmap
split out example for fieldmap, added map files for testing
some minor  modifications of the functions
parent a85c8f40
No related branches found
No related tags found
No related merge requests found
Pipeline #5578 passed with warnings
__all__ = ["TraceWin", "installed", "lib_tw"] __all__ = ["fieldmap", "installed", "lib_tw", "SP_Relativity", "TraceWin" "TTF"]
from . import TraceWin from . import TraceWin
from . import installed from . import installed
from . import lib_tw from . import lib_tw
from . import fieldmap
This diff is collapsed.
from ess import fieldmap from ess import fieldmap
import os
''' '''
Example Example
...@@ -8,28 +9,61 @@ scans the folder and converts all files, assumes all are binary fieldmaps, to AS ...@@ -8,28 +9,61 @@ scans the folder and converts all files, assumes all are binary fieldmaps, to AS
The dimension of the field is also needed. The dimension of the field is also needed.
If you need to cut the field, the n_enter and n_exit should be adjusted. If you need to cut the field, the n_enter and n_exit should be adjusted.
''' '''
mypath = 'Data/FM/' # where the fieldmaps are stored plot = False # Make comparison plots
fieldmap_dim = 3 mypath = 'maps' # where the fieldmaps are stored
#fieldmap_dim = 2
#fieldmap_dim = 1
n_enter = 0 #Number of lines to be removed from entrance of fieldmap n_enter = 0 #Number of lines to be removed from entrance of fieldmap
n_exit = 0 #Number of lines to be removed from exit of fieldmap n_exit = 0 #Number of lines to be removed from exit of fieldmap
onlyfiles = [f for f in os.listdir(mypath) if os.path.isfile(os.path.join(mypath, f))]
for f in onlyfiles: if plot:
if f[0]!=".": from matplotlib import pyplot as plt
if (n_enter+n_exit>0): for f in os.listdir(mypath):
Header, Field = fieldmap.cut_fieldmap_length(f, fieldmap_dim, n_enter, n_exit, 'b')
else: print(f)
Header, Field = fieldmap.read_binary_fieldmap(mypath+f, fieldmap_dim) fullpath=os.path.join(mypath,f)
ftype=''
if 'ascii' in f:
ftype='a'
elif 'binary' in f:
ftype='b'
fdim=0
if '1D' in f:
fdim=1
elif '2D' in f:
fdim=2
elif '3D' in f:
fdim=3
save_to_ascii(Header, Field, fieldmap.fieldmap_dim, 'Data/FM/ASCII/', f) if (n_enter or n_exit):
Header, Field = fieldmap.cut_fieldmap_length(fullpath, fdim, n_enter, n_exit, ftype)
else:
Header, Field = fieldmap.read_fieldmap(fullpath, fdim, ftype)
fieldmap.save_to_ascii(Header, Field, 'new_'+f)
oldfield = fieldmap.field_on_axis(Header,Field, fdim)
origfield = fieldmap.field_on_axis_from_file(fullpath, fdim, 'a')
newfield = fieldmap.field_on_axis_from_file('new_'+f, fdim, 'a')
if plot:
# Plot for comparison
plt.figure()
plt.title(f)
if fdim==1:
plt.plot(oldfield,label='old')
plt.plot(newfield,label='new')
plt.plot(origfield,label='orig')
else:
plt.plot(oldfield[0,:], oldfield[1,:], label='old')
plt.plot(newfield[0,:], newfield[1,:], label='new')
plt.plot(origfield[0,:], origfield[1,:],label='orig')
plt.legend()
else:
if fdim==1:
avg_diff=sum(newfield-oldfield)/len(newfield)
else:
avg_diff=sum(newfield[1,:]-oldfield[1,:])/len(newfield[1,:])
print("Average diff",avg_diff)
test = False if plot:
#%pylab inline plt.show()
if test == True:
#field = field_on_axis_from_file('Data/FM/MB_W_coupler.edz', 3, 'b')
field = field_on_axis_from_file('Data/FM/ASCII/Spoke_W_coupler.edz', 3, 'a')
plot(field[0,:], field[1,:])
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment