* added gradient calculation

* added magnet selection
* calculate probe position
This commit is contained in:
Markus Rosenstihl 2025-04-22 21:33:49 +02:00
parent 0a902eb619
commit ef59bd1aa2
4 changed files with 4027 additions and 2000 deletions

View File

@ -46,7 +46,7 @@
<div class="col"> <div class="col">
<select name="magnet" class="form-select" size="1"> <select name="magnet" class="form-select" size="1">
<option value="oxford_profile.dat">Oxford</option> <option value="oxford_profile.dat">Oxford</option>
<option value="oxford_profile.dat">Magnex</option> <option value="magnex_profile.dat">Magnex</option>
</select> </select>
</div> </div>
</div> </div>

View File

@ -12,7 +12,7 @@ import re
import numpy as np import numpy as np
from bokeh.plotting import figure from bokeh.plotting import figure
from bokeh.embed import components from bokeh.embed import components
from bokeh.models import Label, Node, MathML, Range1d, Span from bokeh.models import Label, Node, MathML, Range1d, Span, ColumnDataSource, DataTable, TableColumn
from isotopapp.models import Isotope from isotopapp.models import Isotope
# Create your views here. # Create your views here.
@ -144,23 +144,33 @@ def position(request):
print(request) print(request)
n1, element1 = extract_isotope_parts(request.GET.get('isotope1')) n1, element1 = extract_isotope_parts(request.GET.get('isotope1'))
isotope1 = Isotope.objects.filter(symbol=element1, n_nucleons=n1).get() isotope1 = Isotope.objects.filter(symbol=element1, n_nucleons=n1).get()
probe_length = float(request.GET.get('probe_length'))
print(os.path.abspath(".")) print(os.path.abspath("."))
data = np.loadtxt(request.GET.get('magnet')) gradient_magnet = request.GET.get('magnet')
if gradient_magnet == "oxford_profile.dat":
step = 5e-3/6
cryo_length = 1113.0
offset = cryo_length / step - probe_length / step
elif gradient_magnet == "magnex_profile.dat":
step = 1e-3
cryo_length = 1262.2
offset = -(cryo_length / step - probe_length / step) # other direction
data = np.loadtxt(gradient_magnet)
_z_coords = data[:,0] _z_coords = data[:,0]
_fields = data[:,1] _fields = data[:,1]
_gradients = data[:,2] _gradients = data[:,2]
freq = float(request.GET.get('freq')) freq = float(request.GET.get('freq'))
#gradient = float(request.GET.get('gradient'))
field_T = freq / isotope1.gamma field_T = freq / isotope1.gamma
sample_diameter = 5e-3 sample_diameter = 5e-3
gradient = float(request.GET.get('gradient'))
# create a plot (bokeh) # create a plot (bokeh)
TOOLTIPS = [ TOOLTIPS = [
("index", "$index"), #("index", "$index"),
("(x,y)", "($x, $y)"), ("(x,y)", "($x, $y)"),
("desc", "@desc"),
] ]
plot = figure(outer_width=500, outer_height=500, match_aspect=False, tooltips=TOOLTIPS) plot = figure(outer_width=500, outer_height=500, match_aspect=False, tooltips=TOOLTIPS)
frame_left = Node(target="frame", symbol="left", offset=5) frame_left = Node(target="frame", symbol="left", offset=5)
@ -170,15 +180,15 @@ def position(request):
#plot.ellipse(x=[0], y=[0], width=5, height=5, color="#D5D9FF", alpha=0.8, line_width=1, line_color="black") #plot.ellipse(x=[0], y=[0], width=5, height=5, color="#D5D9FF", alpha=0.8, line_width=1, line_color="black")
#plot.ellipse(x=[0], y= [2.5], width=5, height=5, color="#D5D9FF", alpha=0.4, line_width=1, line_color="black") #plot.ellipse(x=[0], y= [2.5], width=5, height=5, color="#D5D9FF", alpha=0.4, line_width=1, line_color="black")
#plot.ellipse(x=[0], y=[-2.5], width=5, height=5, color="#D5D9FF", alpha=0.4, line_width=1, line_color="black") #plot.ellipse(x=[0], y=[-2.5], width=5, height=5, color="#D5D9FF", alpha=0.4, line_width=1, line_color="black")
plot.xaxis[0].axis_label = 'z in mm' plot.xaxis[0].axis_label = 'steps'
plot.yaxis[0].axis_label = 'B0 in T' plot.yaxis[0].axis_label = 'B0 in T'
plot.line(x=_z_coords*1e3, y=_fields, color="navy", line_width=2) plot.line(x=_z_coords, y=_fields, color="navy", line_width=2)
plot.yaxis[0].axis_label_text_color = "navy" plot.yaxis[0].axis_label_text_color = "navy"
plot.y_range = Range1d(-10, 10) plot.y_range = Range1d(-10, 10)
plot.extra_y_ranges['gradient'] = Range1d(-200, 200) plot.extra_y_ranges['gradient'] = Range1d(-200, 200)
plot.line(x=_z_coords * 1e3, y=_gradients, color="crimson", line_width=2 , y_range_name="gradient") plot.line(x=_z_coords, y=_gradients, color="crimson", line_width=2 , y_range_name="gradient")
ax2 = LinearAxis(y_range_name="gradient", axis_label="g in T/m") ax2 = LinearAxis(y_range_name="gradient", axis_label="g in T/m")
ax2.axis_label_text_color = "crimson" ax2.axis_label_text_color = "crimson"
plot.add_layout(ax2, 'left') plot.add_layout(ax2, 'left')
@ -192,10 +202,11 @@ def position(request):
for p in indices: for p in indices:
#vline = Span(location=_z_coords[p]*1e3, dimension='height', line_color='gray', line_width=1) #vline = Span(location=_z_coords[p]*1e3, dimension='height', line_color='gray', line_width=1)
#plot.renderers.extend([vline]) #plot.renderers.extend([vline])
#zpos = _z_coords[p] + (1117 - probe_length)
label = Label( label = Label(
x=_z_coords[p]*1e3+25, x=_z_coords[p]+25,
y=-(np.sign(_z_coords[p])*30) + (_gradients[p]), y=-(np.sign(_z_coords[p])*30) + (_gradients[p]),
text=f"{_z_coords[p]*1e3:.2f},{_gradients[p]:.1f}T/m", text=f"{_z_coords[p]:.0f}\n{_gradients[p]:.1f}T/m",
text_baseline="middle", text_baseline="middle",
text_align="center", text_font_size="11pt", text_align="center", text_font_size="11pt",
border_line_color="#D5D9FF", border_line_color="#D5D9FF",
@ -204,8 +215,10 @@ def position(request):
y_range_name="gradient", y_range_name="gradient",
) )
plot.add_layout(label) plot.add_layout(label)
#plot.circle(x=_z_coords[indices]*1e3, y=_fields[indices], radius=2, color="gray") #plot.circle(x=_z_coords[indices]*1e3, y=_fields[indices], radius=2, color="gray")
plot.circle(x=_z_coords[indices]*1e3, y=_gradients[indices], radius=2, color="gray",y_range_name="gradient" ) plot.circle(x=_z_coords[indices], y=_gradients[indices], radius=2, color="gray",y_range_name="gradient" )
# plot the B0 field hlines # plot the B0 field hlines
hline0 = Span(location=0, dimension='width', line_color='black', line_width=4) hline0 = Span(location=0, dimension='width', line_color='black', line_width=4)
hline1 = Span(location=field_T, dimension='width', line_color='gray', line_width=2) hline1 = Span(location=field_T, dimension='width', line_color='gray', line_width=2)
@ -215,13 +228,13 @@ def position(request):
plot.renderers.extend([hline0, hline1, hline2, label1]) plot.renderers.extend([hline0, hline1, hline2, label1])
for i in indices: for i in indices:
plot.line(x=[_z_coords[i]*1e3, _z_coords[i]*1e3], y=[_fields[i], _gradients[i]/20. ] , color="gray", line_dash="dashed" ) plot.line(x=[_z_coords[i], _z_coords[i]], y=[_fields[i], _gradients[i]/20. ] , color="gray", line_dash="dashed" )
close_isotopes = [] close_isotopes = []
for isotope in Isotope.objects.all(): for isotope in Isotope.objects.all():
if isotope.gamma == 0: continue if isotope.gamma == 0: continue
if not isotope.stable: continue if not isotope.stable: continue
z = (freq/isotope.gamma-field_T)/gradient z = (freq/isotope.gamma-field_T)/_gradients[0]
if abs(z) <= sample_diameter: if abs(z) <= sample_diameter:
i_info = isotope_info(isotope, field_T) i_info = isotope_info(isotope, field_T)
#i_info[3] = f"{z*1e3:.1f} mm" #i_info[3] = f"{z*1e3:.1f} mm"
@ -230,19 +243,33 @@ def position(request):
#label = Label(x=2.6, y=z*1e3, text=f"{isotope.n_nucleons}{isotope.symbol}", text_baseline="middle", text_align="left", text_font_size="16pt") #label = Label(x=2.6, y=z*1e3, text=f"{isotope.n_nucleons}{isotope.symbol}", text_baseline="middle", text_align="left", text_font_size="16pt")
#plot.add_layout(label) #plot.add_layout(label)
text_label = f"{isotope1.n_nucleons}{isotope1.symbol}: {freq:.1f} MHz\nProbe position:\n"
for i in indices:
text_label += f"{_gradients[i]:.2f}T/m: {abs(round(offset + _z_coords[i]))}\n"
citation = Label( citation = Label(
x=frame_left, x=frame_left,
y=frame_bottom, y=frame_bottom,
anchor="bottom_left", anchor="bottom_left",
text=f"{isotope1.n_nucleons}{isotope1.symbol}: {freq:.1f} MHz\ng={gradient:.1f} T/m\n5 mm sample dia.", text=text_label.strip(),
padding=5, padding=5,
border_radius=5, border_radius=2,
border_line_color="#D5D9FF", background_fill_color="white", border_line_color="#D5D9FF", background_fill_color="white",
) )
plot.add_layout(citation) plot.add_layout(citation)
bokeh_table_data = {"pos":[_z_coords[p] for p in indices] , "gradients":[_gradients[p] for p in indices]}
source = ColumnDataSource(bokeh_table_data)
columns = [
TableColumn(field="pos", title="Position"),
TableColumn(field="gradients", title="Gradient / T/m"),
]
data_table = DataTable(source=source, columns=columns, width=400, height=280)
#show(data_table)
# boke plot # boke plot
#plot.add_layout(data_table)
script, div = components(plot) script, div = components(plot)
ans = sorted(close_isotopes, key=lambda x: float(x[3])) ans = sorted(close_isotopes, key=lambda x: float(x[3]))

2000
isotables/magnex_profile.dat Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff