From 722edb6d4ba48ef7152c61c702f63c0d91ce65d8 Mon Sep 17 00:00:00 2001 From: Roman Dvorak Date: Fri, 12 Apr 2024 17:27:14 +0200 Subject: [PATCH] Update record view, dose calculation --- .../0035_record_time_internal_start.py | 18 ++++++++ DOSPORTAL/models.py | 9 +++- DOSPORTAL/serializers.py | 7 --- DOSPORTAL/signals.py | 6 ++- DOSPORTAL/tasks.py | 23 +++++++--- .../templates/records/record_detail.html | 31 ++++++------- DOSPORTAL/views_record.py | 44 +++++++------------ api/serializers.py | 2 +- api/urls.py | 3 +- api/views.py | 13 ++++-- 10 files changed, 90 insertions(+), 66 deletions(-) create mode 100644 DOSPORTAL/migrations/0035_record_time_internal_start.py delete mode 100644 DOSPORTAL/serializers.py diff --git a/DOSPORTAL/migrations/0035_record_time_internal_start.py b/DOSPORTAL/migrations/0035_record_time_internal_start.py new file mode 100644 index 0000000..de42616 --- /dev/null +++ b/DOSPORTAL/migrations/0035_record_time_internal_start.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-04-12 14:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('DOSPORTAL', '0034_alter_detector_data_alter_record_metadata'), + ] + + operations = [ + migrations.AddField( + model_name='record', + name='time_internal_start', + field=models.FloatField(blank=True, default=0, help_text='System time of record start', null=True, verbose_name='Internal time start'), + ), + ] diff --git a/DOSPORTAL/models.py b/DOSPORTAL/models.py index 08a4fcc..f3b89f2 100644 --- a/DOSPORTAL/models.py +++ b/DOSPORTAL/models.py @@ -559,7 +559,6 @@ def user_directory_path_data(instance, extension='pk'): blank=True ) - metadata_file = models.FileField( verbose_name=_("Metadata file"), help_text=_("Processed metadata file"), @@ -574,6 +573,14 @@ def user_directory_path_data(instance, extension='pk'): help_text=_("Tick this box if the record is dependent on absolute time. When you need align record to real time.") ) + time_internal_start = models.FloatField( + verbose_name = _("Internal time start"), + help_text=_("System time of record start"), + null=True, + blank=True, + default=0 + ) + time_start = models.DateTimeField( verbose_name = _("Measurement beginning time"), help_text=("When 'time is tracked', you can set start time of the record beginning. "), diff --git a/DOSPORTAL/serializers.py b/DOSPORTAL/serializers.py deleted file mode 100644 index cc26701..0000000 --- a/DOSPORTAL/serializers.py +++ /dev/null @@ -1,7 +0,0 @@ -from rest_framework import serializers -from .models import measurement - -class MeasurementSerializer(serializers.ModelSerializer): - class Meta: - model = measurement - fields = ["id", "time_start", "author", "name", "description"] \ No newline at end of file diff --git a/DOSPORTAL/signals.py b/DOSPORTAL/signals.py index 6163ba7..618386d 100644 --- a/DOSPORTAL/signals.py +++ b/DOSPORTAL/signals.py @@ -101,8 +101,8 @@ def save_record(sender, instance, created = None, **kwargs): metadata['log_info'] = {} - metadata['log_info']['internat_time_min'] = df_spectrum['time'].min() - metadata['log_info']['internat_time_max'] = df_spectrum['time'].max() + metadata['log_info']['internal_time_min'] = df_spectrum['time'].min() + metadata['log_info']['internal_time_max'] = df_spectrum['time'].max() metadata['log_info']['log_duration'] = float(duration) metadata['log_info']['spectral_count'] = df_spectrum.shape[0] metadata['log_info']['channels'] = df_spectrum.shape[1] - 1 # remove time column @@ -110,6 +110,8 @@ def save_record(sender, instance, created = None, **kwargs): df_spectrum['time'] = df_spectrum['time'] - df_spectrum['time'].min() instance.record_duration = datetime.timedelta(seconds=float(duration)) + + instance.time_internat_start = df_spectrum['time'].min() instance.time_of_interest_start = 0 instance.time_of_interest_end = float(duration) diff --git a/DOSPORTAL/tasks.py b/DOSPORTAL/tasks.py index ac9c1b2..64df343 100644 --- a/DOSPORTAL/tasks.py +++ b/DOSPORTAL/tasks.py @@ -63,16 +63,23 @@ def process_record_entry(pk): record = Record.objects.filter(pk=pk)[0] print(record) - df = pd.read_pickle(record.data_file.path).drop('time', axis=1).astype(float).to_numpy() + + start_time = record.time_of_interest_start + end_time = record.time_of_interest_end + duration_hours = (end_time - start_time) / 3600 + + + df = pd.read_pickle(record.data_file.path) + print(df) + df = df[(df['time'] >= start_time) & (df['time'] <= end_time)] + df = df.drop('time', axis=1).astype(float).to_numpy() calib = record.calib s = np.linspace(0, df.shape[1]-1, df.shape[1]) s = calib.coef0 + s * calib.coef1 - energies_per_exposition = np.matmul(df, s) - - dose_rate_per_exposition = ((1e6 * (1.602e-19 * energies_per_exposition)/0.1165e-3)/10) * 3600 # in uGy/h + dose_rate_per_exposition = (((1e6 * (1.602e-19 * np.matmul(df, s))/0.1165e-3)/10) * 3600) # in uGy/h dose_rate = dose_rate_per_exposition.mean() @@ -81,18 +88,20 @@ def process_record_entry(pk): # si_mass = 0.1165e-3 # kg # integration = 10 # s - #metadata = json.loads(record.metadata) metadata = record.metadata print('METADATA FILE', metadata) print(type(metadata)) - metadata = json.loads(metadata) + if type(metadata) == str: + metadata = json.loads(metadata) if not 'outputs' in metadata: metadata["outputs"] = {} - metadata["outputs"]["dose_rate_mean"] = dose_rate + metadata["outputs"]["dose_rate_mean"] = dose_rate_per_exposition.mean() + metadata["outputs"]["dose_rate_std"] = dose_rate_per_exposition.std() + metadata["outputs"]["dose_obtained"] = dose_rate_per_exposition.mean() * duration_hours #record.metadata = json.dumps(metadata, indent=4) record.metadata = metadata diff --git a/DOSPORTAL/templates/records/record_detail.html b/DOSPORTAL/templates/records/record_detail.html index 7237d28..d5baa5c 100644 --- a/DOSPORTAL/templates/records/record_detail.html +++ b/DOSPORTAL/templates/records/record_detail.html @@ -2,6 +2,7 @@ {% load filters %} {% block content %} + @@ -63,9 +64,9 @@ Log file: {{record.log_original_filename}} ({{ record.log_file | filesize_mb }}) - {% if record.metadata|length > 1 %} + {% if record.description|length > 1 %} Description: -
{{record.metadata | safe }}
+
{{record.description_formatted | safe }}
{% endif %} @@ -87,13 +88,20 @@
Outputs:
-
-
+
+
{% if "dose_rate_mean" in outputs %} -
+
Dose rate
{{outputs.dose_rate_mean|floatformat:2 }}
-
uS/h
+
μS/h
+
+ {% endif %} + {% if "dose_obtained" in outputs %} +
+
Dose absorbed
+
{{outputs.dose_obtained|floatformat:2 }}
+
μS
{% endif %}
@@ -134,17 +142,6 @@

Telemetry data:

- - -