plot sample
This commit is contained in:
parent
1a10e6d778
commit
8968691622
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||||
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
||||||
@ -7,6 +6,7 @@
|
|||||||
.center {
|
.center {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
width: 60%;
|
width: 60%;
|
||||||
|
border: 3px solid #90befb;
|
||||||
border: 3px solid #a5addb;
|
border: 3px solid #a5addb;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
@ -16,45 +16,49 @@
|
|||||||
|
|
||||||
<form action="result">
|
<form action="result">
|
||||||
<div class="row row-cols-6">
|
<div class="row row-cols-6">
|
||||||
<div class="col"> <label class="form-label">Source isotope:</label></div>
|
<div class="col"><label class="form-label">Source isotope:</label></div>
|
||||||
|
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<select name="isotope1" class="form-select" size="1">
|
<select name="isotope1" class="form-select" size="1">
|
||||||
{% for i in isotopes %}
|
{% for i in isotopes %}
|
||||||
<option value="{{ i.0 }}">{{ i.1 }}</option>
|
<option value="{{ i.0 }}">{{ i.1 }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
{# <input type="text" name="isotope1" class="form-control" placeholder="Current isotope">#}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row row-cols-6">
|
<div class="row row-cols-6">
|
||||||
<div class="col"><label class="form-label">Source frequency in MHz:</label></div>
|
<div class="col"><label class="form-label">Source frequency in MHz:</label></div>
|
||||||
<div class="col"><input type="number" name="freq" class="form-control" step="any" value=100 placeholder="Larmor frequency in MHz"></div>
|
<div class="col">
|
||||||
|
<input type="number" name="freq" class="form-control" step="any" value=100
|
||||||
|
placeholder="Larmor frequency in MHz">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row row-cols-6">
|
<div class="row row-cols-6">
|
||||||
<label class="form-label">Destination isotope:</label>
|
<label class="form-label">Destination isotope:</label>
|
||||||
<div class="col"> <select name="isotope2" class="form-select" size="1">
|
<div class="col"><select name="isotope2" class="form-select" size="1">
|
||||||
{% for i in isotopes %}
|
{% for i in isotopes %}
|
||||||
<option value="{{ i.0 }}">{{ i.1 }}</option>
|
<option value="{{ i.0 }}">{{ i.1 }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select></div>
|
</select></div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button type="submit" name="transform" class="btn btn-primary btn-sm">Search</button>
|
<button type="submit" name="transform" class="btn btn-primary btn-sm">Search</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row row-cols-6">
|
<div class="row row-cols-6">
|
||||||
<label class="form-label">Frequency range in MHz:</label>
|
<label class="form-label">Frequency range in MHz:</label>
|
||||||
<div class="col"><input type="number" name="freq_range" class="form-control" step="any" placeholder="Range in MHz"></div>
|
<div class="col"><input type="number" name="freq_range" class="form-control" step="any"
|
||||||
|
placeholder="Range in MHz"></div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button type="submit" name="search" class="btn btn-primary btn-sm ">Search</button>
|
<button type="submit" name="range_search" class="btn btn-primary btn-sm ">Search</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row row-cols-6">
|
<div class="row row-cols-6">
|
||||||
<label class="form-label">Gradient in T/m:<br>(assuming ⌀5mm)</label>
|
<label class="form-label">Gradient in T/m:<br>(assuming ⌀5mm)</label>
|
||||||
<div class="col"><input type="number" name="gradient" class="form-control" step="any" placeholder="Gradient in T/m"></div>
|
<div class="col"><input type="number" name="gradient" class="form-control" step="any"
|
||||||
|
placeholder="Gradient in T/m"></div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button type="submit" name="calculate" class="btn btn-primary btn-sm">Search</button>
|
<button type="submit" name="gradient_search" class="btn btn-primary btn-sm">Search</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -31,6 +31,10 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<div>
|
||||||
|
<img src="data:image/png;base64, {{ figure }}" alt="somealt" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<a href="{% url 'home' %}">Go Back</a>
|
<a href="{% url 'home' %}">Go Back</a>
|
||||||
|
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
from math import pi
|
from math import pi
|
||||||
|
from io import BytesIO
|
||||||
|
import base64
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
import re
|
import re
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib
|
||||||
|
from setuptools.command.rotate import rotate
|
||||||
|
|
||||||
|
matplotlib.use('Agg')
|
||||||
|
from matplotlib.patches import Wedge, FancyArrowPatch
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
from isotopapp.models import Isotope
|
from isotopapp.models import Isotope
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
@ -42,9 +49,10 @@ def result(request):
|
|||||||
|
|
||||||
field_T = freq / isotope1.gamma
|
field_T = freq / isotope1.gamma
|
||||||
|
|
||||||
close_isotopes = []
|
figure=None
|
||||||
|
print(request.GET)
|
||||||
if request.GET.get('search') == "":
|
if request.GET.get('range_search') == "":
|
||||||
|
close_isotopes = [isotope_info(isotope1, field_T)]
|
||||||
freq_range = float(request.GET.get('freq_range'))
|
freq_range = float(request.GET.get('freq_range'))
|
||||||
Isotope.objects.filter()
|
Isotope.objects.filter()
|
||||||
# calculate the frequency for all isotopes and compile a list of close by isotopes
|
# calculate the frequency for all isotopes and compile a list of close by isotopes
|
||||||
@ -56,21 +64,49 @@ def result(request):
|
|||||||
close_isotopes.append(isotope_info(isotope, field_T))
|
close_isotopes.append(isotope_info(isotope, field_T))
|
||||||
ans = sorted(close_isotopes, key=lambda x: -float(x[3]))
|
ans = sorted(close_isotopes, key=lambda x: -float(x[3]))
|
||||||
|
|
||||||
elif request.GET.get('calculate') == "":
|
elif request.GET.get('gradient_search') == "":
|
||||||
|
fig, ax = plt.subplots(1, 1)
|
||||||
|
theta1, theta2 = 0, 360
|
||||||
|
radius = 2.5
|
||||||
|
center = (0, 0)
|
||||||
|
w = Wedge(center, radius, theta1, theta2, fc='#D5D9FFB2', edgecolor='black')
|
||||||
|
ax.add_patch(w)
|
||||||
|
|
||||||
sample_diameter = 5e-3
|
sample_diameter = 5e-3
|
||||||
gradient = float(request.GET.get('gradient'))
|
gradient = float(request.GET.get('gradient'))
|
||||||
freq_range = sample_diameter/2 * gradient * isotope1.gamma
|
freq_range = sample_diameter/2 * gradient * isotope1.gamma
|
||||||
|
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
|
||||||
f_Larmor = field_T*isotope.gamma
|
f_Larmor = field_T*isotope.gamma
|
||||||
if abs(f_Larmor - freq) <= freq_range:
|
z = (freq/isotope.gamma-field_T)/gradient
|
||||||
close_isotopes.append(isotope_info(isotope, field_T))
|
if abs(z) <= sample_diameter/2:
|
||||||
ans = sorted(close_isotopes, key=lambda x: x[3])
|
i_info = isotope_info(isotope, field_T)
|
||||||
|
#i_info[3] = f"{z*1e3:.1f} mm"
|
||||||
|
close_isotopes.append(i_info)
|
||||||
|
|
||||||
|
arr = FancyArrowPatch((np.sqrt(2.5**2-(z*1e3)**2),z*1e3), (-np.sqrt(2.5**2-(z*1e3)**2), z*1e3),
|
||||||
|
arrowstyle='<->,head_width=.1', mutation_scale=20)
|
||||||
|
ax.add_patch(arr)
|
||||||
|
ax.annotate(f"{isotope.n_nucleons}{isotope.symbol}", (1.05, 0), xycoords=arr, ha='left', va='center',fontsize=7)
|
||||||
|
|
||||||
|
ax.set_aspect('equal')
|
||||||
|
ax.set_xlim([-4, 4])
|
||||||
|
ax.set_ylim([-4, 4])
|
||||||
|
ax.set_ylabel('z (mm)')
|
||||||
|
ax.grid(True)
|
||||||
|
buf = BytesIO()
|
||||||
|
plt.savefig(buf, format='png')
|
||||||
|
figure = base64.b64encode(buf.getvalue()).decode('utf-8').replace('\n', '')
|
||||||
|
buf.close()
|
||||||
|
ans = sorted(close_isotopes, key=lambda x: float(x[3]))
|
||||||
|
|
||||||
elif request.GET.get('transform') == "":
|
elif request.GET.get('transform') == "":
|
||||||
n2, element2 = extract_isotope_parts(request.GET.get('isotope2'))
|
n2, element2 = extract_isotope_parts(request.GET.get('isotope2'))
|
||||||
isotope2 = Isotope.objects.filter(symbol=element2, n_nucleons=n2).get()
|
isotope2 = Isotope.objects.filter(symbol=element2, n_nucleons=n2).get()
|
||||||
#isotope_info(isotope2, field_T)
|
#isotope_info(isotope2, field_T)
|
||||||
ans = [isotope_info(isotope2, field_T)]
|
ans = [isotope_info(isotope2, field_T)]
|
||||||
|
else:
|
||||||
return render(request, 'result.html', {'ans': ans})
|
ans = []
|
||||||
|
return render(request, 'result.html', {'ans': ans, 'figure': figure})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user