added upload and better gradient view

This commit is contained in:
Markus Rosenstihl 2025-04-04 15:50:52 +02:00
parent 11729f67e5
commit d48e0e07df
5 changed files with 40 additions and 11 deletions

Binary file not shown.

View File

@ -1,3 +1,5 @@
from django.contrib import admin from django.contrib import admin
from isotopapp import models
# Register your models here. # Register your models here.
admin.site.register(models.FieldProfile)

View File

@ -11,3 +11,7 @@ class Isotope(models.Model):
gamma = models.FloatField(help_text="Gyromagnetic ratio in MHz/T") # MHz/T gamma = models.FloatField(help_text="Gyromagnetic ratio in MHz/T") # MHz/T
natural_abundance = models.FloatField(help_text="Natural abundance") natural_abundance = models.FloatField(help_text="Natural abundance")
quadrupole_moment = models.FloatField(null=True, help_text="Quadrupole moment") quadrupole_moment = models.FloatField(null=True, help_text="Quadrupole moment")
class FieldProfile(models.Model):
field_profile = models.FileField(upload_to='field_profile')

View File

@ -2,6 +2,23 @@
<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">
</head> </head>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{% url 'home' %}">Isotopes</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'sfg' %}">Position</a>
</li>
<li class="nav-item">
{% load admin_urls %}
<a class="nav-link" href="{% url 'admin:index' %}">Admin</a>
</li>
</ul>
</div>
</nav>
<style> <style>
.center { .center {
margin: auto; margin: auto;
@ -66,4 +83,3 @@
<div> <div>
{{ ans }} {{ ans }}
</div> </div>

View File

@ -164,8 +164,9 @@ def position(request):
] ]
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)
frame_bottom = Node(target="frame", symbol="bottom", offset=0) frame_bottom = Node(target="frame", symbol="bottom", offset=5)
frame_top = Node(target="frame", symbol="top", offset=0) frame_top = Node(target="frame", symbol="top", offset=5)
frame_right = Node(target="frame", symbol="right", offset=5)
#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")
@ -189,16 +190,22 @@ 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])
label = Label(x=_z_coords[p]*1e3, y=_fields[p]+1, text=f"{_z_coords[p]*1e3:.2f},{_gradients[p]:.1f}T/m", text_baseline="middle", label = Label(x=_z_coords[p]*1e3+25,
text_align="center", text_font_size="11pt") y=-(np.sign(_z_coords[p]) *10) +(_gradients[p]), text=f"{_z_coords[p]*1e3:.2f},{_gradients[p]:.1f}T/m", text_baseline="middle",
text_align="center", text_font_size="11pt",
border_line_color="#D5D9FF", background_fill_color="white",
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]*1e3, y=_gradients[indices], radius=2, color="gray",y_range_name="gradient" )
hline1 = Span(location=field_T, dimension='width', line_color='gray', line_width=1) # plot the B0 field hlines
hline2 = Span(location=-field_T, dimension='width', line_color='gray', line_width=1) hline1 = Span(location=field_T, dimension='width', line_color='gray', line_width=2)
plot.renderers.extend([hline1, hline2]) label1 = Label(x=frame_right, y=field_T, text=f"{field_T:.1f}T/m",
text_baseline="middle")
hline2 = Span(location=-field_T, dimension='width', line_color='gray', line_width=2)
plot.renderers.extend([hline1, hline2, label1])
close_isotopes = [] close_isotopes = []
for isotope in Isotope.objects.all(): for isotope in Isotope.objects.all():