Skip to content

Commit

Permalink
dose calc init
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-dvorak committed Apr 10, 2024
1 parent 311b1cb commit f301eac
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 49 deletions.
21 changes: 21 additions & 0 deletions DOSPORTAL/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ def __init__(self,*args, user=None, **kwargs):
self.user = user


name = forms.CharField(
required=True,
widget=forms.TextInput(attrs={
'class': 'form-control',

}),
label="Name",
help_text="Enter a name for the measurement.",
)

time_start = forms.DateTimeField(
required=False,
widget=forms.DateTimeInput(attrs={
'class': 'form-control',
'type': 'datetime-local',
'step': '1',
}),
label="Start time",
help_text="Enter the start time of the measurement. When 'time is tracked', you should set start time of the record beginning. ",
)

# log_file = forms.FileField(
# required=False,
# widget=forms.widgets.FileInput(attrs={
Expand Down
3 changes: 3 additions & 0 deletions DOSPORTAL/helper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@



3 changes: 3 additions & 0 deletions DOSPORTAL/helper/dose_calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@



Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Generated by Django 4.2.11 on 2024-04-08 22:16

import DOSPORTAL.models
import datetime
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('DOSPORTAL', '0030_remove_detectorcalib_date_detectorcalib_author'),
]

operations = [
migrations.AddField(
model_name='record',
name='name',
field=models.CharField(default='Record', help_text='Name of this record. Short and simple description of record.', max_length=80, null=True, verbose_name='Record name'),
),
migrations.AlterField(
model_name='detector',
name='calib',
field=models.ManyToManyField(blank=True, help_text='Detector calibration', related_name='detectors', to='DOSPORTAL.detectorcalib'),
),
migrations.AlterField(
model_name='record',
name='belongs',
field=models.ForeignKey(help_text='Organization, which owns this record. If you are the only owner, please leave this field empty.', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='records_owning', to='DOSPORTAL.organization'),
),
migrations.AlterField(
model_name='record',
name='data_policy',
field=models.CharField(choices=[('PR', 'Private'), ('PU', 'Public'), ('NV', 'Non-public')], default='PU', help_text='Data policy of this record. Field can be overridden depending by setting of the organisation, that owns this record.', max_length=2),
),
migrations.AlterField(
model_name='record',
name='log_file',
field=models.FileField(blank=True, help_text='Upload recorded data file form your detector', upload_to=DOSPORTAL.models.Record.user_directory_path, verbose_name='File log'),
),
migrations.AlterField(
model_name='record',
name='time_start',
field=models.DateTimeField(blank=True, default=datetime.datetime(2000, 1, 1, 0, 0), help_text="When 'time is tracked', you can set start time of the record beginning. ", null=True, verbose_name='Measurement beginning time'),
),
migrations.AlterField(
model_name='record',
name='time_tracked',
field=models.BooleanField(default=False, help_text='Tick this box if the record is dependent on absolute time. When you need align record to real time.', verbose_name='Is time tracked?'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.11 on 2024-04-09 08:26

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('DOSPORTAL', '0031_record_name_alter_detector_calib_and_more'),
]

operations = [
migrations.RemoveField(
model_name='record',
name='time_of_interest_end',
),
migrations.RemoveField(
model_name='record',
name='time_of_interest_start',
),
]
23 changes: 23 additions & 0 deletions DOSPORTAL/migrations/0033_record_time_of_interest_end_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.11 on 2024-04-09 08:26

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('DOSPORTAL', '0032_remove_record_time_of_interest_end_and_more'),
]

operations = [
migrations.AddField(
model_name='record',
name='time_of_interest_end',
field=models.FloatField(blank=True, default=None, null=True, verbose_name='Time of interest end'),
),
migrations.AddField(
model_name='record',
name='time_of_interest_start',
field=models.FloatField(blank=True, default=None, null=True, verbose_name='Time of interest start'),
),
]
13 changes: 11 additions & 2 deletions DOSPORTAL/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,15 @@ def __str__(self):

class Record(UUIDMixin):

name = models.CharField(
max_length = 80,
verbose_name=_("Record name"),
help_text=_("Name of this record. Short and simple description of record."),
null=True,
blank=False,
default="Record"
)

detector = models.ForeignKey(
Detector,
on_delete=models.CASCADE,
Expand Down Expand Up @@ -573,14 +582,14 @@ def user_directory_path_data(instance, extension='pk'):
default=datetime.datetime(2000, 1, 1, 0, 0, 0)
)

time_of_interest_start = models.DurationField(
time_of_interest_start = models.FloatField(
verbose_name = _("Time of interest start"),
null=True,
blank=True,
default=None
)

time_of_interest_end = models.DurationField(
time_of_interest_end = models.FloatField(
verbose_name = _("Time of interest end"),
null=True,
blank=True,
Expand Down
1 change: 0 additions & 1 deletion DOSPORTAL/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def save_record(sender, instance, created = None, **kwargs):
print(instance.metadata_file)
df_metadata.to_pickle('data/media/'+new_name)


except Exception as e:
print(e)

Expand Down
7 changes: 1 addition & 6 deletions DOSPORTAL/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@
</head>
<body>

<div style="position: fixed; bottom: 20px; right: 20px; background-color: #ffa6a6; padding: 10px; border-radius: 5px; box-shadow: 0px 0px 10px rgba(0,0,0,0.5); z-index: 9999; text-align: center;">
Demo-version of DOSPORTAL tool for EURADOS 2024 <br>
DOSPORTAL is developed by <a href="https://www.ust.cz">www.ust.cz</a>
</div>

<nav id="overlay" class="navbar navbar-expand-lg bg-body-tertiary border-bottom ">
<div class="container">
<a class="navbar-brand" href="#">
Expand Down Expand Up @@ -117,7 +112,7 @@
</div>
</nav>

<main class="container" style="margin-top:80pt; margin-bottom: 100pt">
<main class="container" style="margin-top:80pt; margin-bottom: 50pt;">
{% block content %}
{% endblock %}
</main>
Expand Down
37 changes: 3 additions & 34 deletions DOSPORTAL/templates/records/record_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

<table class="table table-borderless">
<tbody>
<tr>
<td class="w-auto">Record name:</td>
<td class=""><code>{{ record.name }}</code></td>
<tr>
<td class="w-auto">Detector:</td>
<td class="">{{ record.detector.formatted_label | safe }}
Expand Down Expand Up @@ -271,40 +274,6 @@ <h3>Energetic spectrogram:</h3>
function update_chart() {
/* if($("#logarithm").is(":checked")) {
myChart.setOption({
yAxis: [{
min: 'dataMin',
max: 'dataMax',
type: 'log',
logBase: 10,
}, {
gridIndex: 1,
min: 'dataMin',
max: 'dataMax',
type: 'log',
logBase: 10,
}]}
);
} else {
myChart.setOption({
yAxis: [{
min: 'dataMin',
max: 'dataMax',
//type: 'log',
//logBase: 10,
}, {
gridIndex: 1,
min: 'dataMin',
max: 'dataMax',
//type: 'log',
//logBase: 100000,
}]
});
} */
var dataZoomRanges = myChart.getOption().dataZoom;
console.log("A...");
Expand Down
3 changes: 2 additions & 1 deletion DOSPORTAL/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from .views import MeasurementsListView, MeasurementDetailView, MeasurementNewView, MeasurementNewView, MeasurementDataView, measuredDataGet, measuredSpectraGet, MeasurementRecordNewView
from .views_detectors import DetectorView, DetectorEditView,DetectorOverview, DetectorNewLogbookRecord, DetectorTypeView, DetectorCalibDetailView
from .views_flights import FlightView
from .views_record import RecordsListView, RecordView, RecordNewView, GetSpectrum, GetEvolution, GetHistogram, GetTelemetry
from .views_record import RecordsListView, RecordView, RecordNewView, GetSpectrum, GetEvolution, GetHistogram, GetTelemetry, CalcDSI

#from organizations.backends import invitation_backend

Expand Down Expand Up @@ -70,6 +70,7 @@
path('record/<uuid:pk>/get_evolution/', GetEvolution, name='record-GetEvolution'),
path('record/<uuid:pk>/get_histogram/', GetHistogram, name='record-GetHistogram'),
path('record/<uuid:pk>/get_telemetry/', GetTelemetry, name='record-GetTelemetry'),
path('record/<uuid:pk>/calc_dsi/', CalcDSI, name='record-CalcDSI'),


path('flight/<uuid:pk>/', FlightView, name='flight-detail'),
Expand Down
54 changes: 49 additions & 5 deletions DOSPORTAL/views_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import django_tables2 as tables
from django_tables2.utils import Accessor
from django_tables2 import RequestConfig
from django_tables2.utils import A # alias for Accessor
from django.utils.html import format_html
from django.urls import reverse

Expand Down Expand Up @@ -47,11 +48,18 @@

class RecordTable(tables.Table):
row_number = tables.Column(empty_values=(), verbose_name='#')
link = tables.LinkColumn('record-view', args=[tables.A('pk')], verbose_name='Link', accessor='pk', attrs={'a': {'target': '_blank'}})

link = tables.LinkColumn(
'record-view',
args=[tables.A('pk')],
verbose_name='Name',
attrs={ 'aria-label': 'Link'},
text = lambda record: record.name,
)

class Meta:
model = Record
fields = ("row_number", "belongs", "author", "data_policy", "log_original_filename") # replace with your field names
fields = ("row_number", "link", "belongs", "author", "data_policy", "log_original_filename") # replace with your field names

def render_row_number(self, record):
self.row_number = getattr(self, 'row_number', itertools.count(self.page.start_index()))
Expand Down Expand Up @@ -263,8 +271,8 @@ def GetEvolution(request, pk):
time_of_interest = None
if record[0].time_of_interest_start and record[0].time_of_interest_end:
time_of_interest = []
time_of_interest.append(record[0].time_of_interest_start.seconds*1000 + start_time)
time_of_interest.append(record[0].time_of_interest_end.seconds*1000 + start_time)
time_of_interest.append(record[0].time_of_interest_start*1000 + start_time)
time_of_interest.append(record[0].time_of_interest_end*1000 + start_time)

return JsonResponse({'evolution_values': data_list, 'time_tracked': record[0].time_tracked, 'time_of_interest': time_of_interest})

Expand All @@ -290,4 +298,40 @@ def GetTelemetry(request, pk):
df = df.astype(float)


return JsonResponse({'telemetry_values': df.to_dict() })
return JsonResponse({'telemetry_values': df.to_dict() })



def CalcDSI(request, pk):

record = Record.objects.filter(pk=pk)
df = pd.read_pickle(record[0].data_file.path).drop('time', axis=1).sum(axis=0)

calib = record[0].calib

df = df.reset_index()

df.columns = ['index', 'counts']
df = df.drop('index', axis=1)
df['channel_energy'] = calib.coef0 + df.index * calib.coef1
df['energy_sum'] = df['counts'] * df['channel_energy']

print(df)

e_corr = df['energy_sum'].mean() # eV
si_mass = 0.1165e-3 # kg
integration = 10 # s

print("Energy correction", e_corr)

dsi = ( (e_corr * 1.602 * 1e-19) / si_mass ) # Gy
dsi *= 1e6 # uGy

print("DSI", dsi)

dsi *= (3600/10) # uGy / h

print("DSI", dsi)


return HttpResponse(f"Total energie: {e_corr} \n DSI: {dsi} \n" + df.to_csv(), content_type="text/csv")

0 comments on commit f301eac

Please sign in to comment.