* 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">
<select name="magnet" class="form-select" size="1">
<option value="oxford_profile.dat">Oxford</option>
<option value="oxford_profile.dat">Magnex</option>
<option value="magnex_profile.dat">Magnex</option>
</select>
</div>
</div>

View File

@ -12,7 +12,7 @@ import re
import numpy as np
from bokeh.plotting import figure
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
# Create your views here.
@ -144,23 +144,33 @@ def position(request):
print(request)
n1, element1 = extract_isotope_parts(request.GET.get('isotope1'))
isotope1 = Isotope.objects.filter(symbol=element1, n_nucleons=n1).get()
probe_length = float(request.GET.get('probe_length'))
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]
_fields = data[:,1]
_gradients = data[:,2]
freq = float(request.GET.get('freq'))
#gradient = float(request.GET.get('gradient'))
field_T = freq / isotope1.gamma
sample_diameter = 5e-3
gradient = float(request.GET.get('gradient'))
# create a plot (bokeh)
TOOLTIPS = [
("index", "$index"),
#("index", "$index"),
("(x,y)", "($x, $y)"),
("desc", "@desc"),
]
plot = figure(outer_width=500, outer_height=500, match_aspect=False, tooltips=TOOLTIPS)
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= [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.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.y_range = Range1d(-10, 10)
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.axis_label_text_color = "crimson"
plot.add_layout(ax2, 'left')
@ -192,10 +202,11 @@ def position(request):
for p in indices:
#vline = Span(location=_z_coords[p]*1e3, dimension='height', line_color='gray', line_width=1)
#plot.renderers.extend([vline])
#zpos = _z_coords[p] + (1117 - probe_length)
label = Label(
x=_z_coords[p]*1e3+25,
x=_z_coords[p]+25,
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_align="center", text_font_size="11pt",
border_line_color="#D5D9FF",
@ -204,8 +215,10 @@ def position(request):
y_range_name="gradient",
)
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=_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
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)
@ -215,13 +228,13 @@ def position(request):
plot.renderers.extend([hline0, hline1, hline2, label1])
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 = []
for isotope in Isotope.objects.all():
if isotope.gamma == 0: 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:
i_info = isotope_info(isotope, field_T)
#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")
#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(
x=frame_left,
y=frame_bottom,
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,
border_radius=5,
border_radius=2,
border_line_color="#D5D9FF", background_fill_color="white",
)
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
#plot.add_layout(data_table)
script, div = components(plot)
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