Repository: comic/grand-challenge.org

Issue:
Cannot import DICOM with non-integer window levels.
I think you can have non int window and level, please also check for the MHD loader
Dicom image builder: invalid literal for int() with base 10: '1906.5'



Discussion:
@jmsmkn do you think we should cast to int, or just accept floats? I don't think CIRRUS accepts floats, correct? Of course other workstations might.
Yes, in DICOM these values are Decimal Strings, so we must accept them. CIRRUS should use them but that is another issue.
Sorry - to be clear, do not cast to int in the backend, choose what to do with that data in CIRRUS.

Resolving patch:
diff --git a/app/grandchallenge/cases/image_builders/utils.py b/app/grandchallenge/cases/image_builders/utils.py
--- a/app/grandchallenge/cases/image_builders/utils.py
+++ b/app/grandchallenge/cases/image_builders/utils.py
@@ -43,12 +43,12 @@ def convert_itk_to_internal(
         depth = simple_itk_image.GetDepth()
         metadata_keys = simple_itk_image.GetMetaDataKeys()
         window_center = (
-            int(simple_itk_image.GetMetaData("WindowCenter"))
+            float(simple_itk_image.GetMetaData("WindowCenter"))
             if "WindowCenter" in metadata_keys
             else None
         )
         window_width = (
-            int(simple_itk_image.GetMetaData("WindowWidth"))
+            float(simple_itk_image.GetMetaData("WindowWidth"))
             if "WindowWidth" in metadata_keys
             else None
         )
diff --git a/app/grandchallenge/cases/migrations/0024_auto_20200525_0634.py b/app/grandchallenge/cases/migrations/0024_auto_20200525_0634.py
new file mode 100644
--- /dev/null
+++ b/app/grandchallenge/cases/migrations/0024_auto_20200525_0634.py
@@ -0,0 +1,23 @@
+# Generated by Django 3.0.5 on 2020-05-25 06:34
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("cases", "0023_auto_20200521_1052"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="image",
+            name="window_center",
+            field=models.FloatField(null=True),
+        ),
+        migrations.AlterField(
+            model_name="image",
+            name="window_width",
+            field=models.FloatField(null=True),
+        ),
+    ]
diff --git a/app/grandchallenge/cases/models.py b/app/grandchallenge/cases/models.py
--- a/app/grandchallenge/cases/models.py
+++ b/app/grandchallenge/cases/models.py
@@ -296,8 +296,8 @@ class Image(UUIDModel):
     voxel_depth_mm = models.FloatField(null=True)
     timepoints = models.IntegerField(null=True)
     resolution_levels = models.IntegerField(null=True)
-    window_center = models.IntegerField(null=True)
-    window_width = models.IntegerField(null=True)
+    window_center = models.FloatField(null=True)
+    window_width = models.FloatField(null=True)
     color_space = models.CharField(
         max_length=5, blank=False, choices=COLOR_SPACES
     )


Test patch:
diff --git a/app/tests/cases_tests/resources/image3x4-extra-stuff.mhd b/app/tests/cases_tests/resources/image3x4-extra-stuff.mhd
--- a/app/tests/cases_tests/resources/image3x4-extra-stuff.mhd
+++ b/app/tests/cases_tests/resources/image3x4-extra-stuff.mhd
@@ -27,6 +27,6 @@ PatientAge = 001Y
 PatientSex = M
 StudyDescription = super awesome study
 SliceThickness = 2
-WindowCenter = 20
-WindowWidth = 200
+WindowCenter = 20.5
+WindowWidth = 200.5
 ElementDataFile = image3x4.zraw
diff --git a/app/tests/cases_tests/test_dicom.py b/app/tests/cases_tests/test_dicom.py
--- a/app/tests/cases_tests/test_dicom.py
+++ b/app/tests/cases_tests/test_dicom.py
@@ -146,5 +146,5 @@ def test_dicom_window_level():
     assert headers["WindowWidth"] == "200"
 
     image_obj = result.new_images[0]
-    assert image_obj.window_center == 30
-    assert image_obj.window_width == 200
+    assert image_obj.window_center == 30.0
+    assert image_obj.window_width == 200.0