Metadata-Version: 2.4
Name: magdi-data
Version: 0.4.6b397
Summary: MAGDI data
Author-email: Christian Hänig <christian.haenig@hs-anhalt.de>, Christian Gurski <christian.gurski@hs-anhalt.de>
License-Expression: MIT
Project-URL: Gitlab, https://gitlab.hs-anhalt.de/ki/projekte/magdi/magdi-data
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8
License-File: LICENSE
Requires-Dist: torch>=2.2.2
Requires-Dist: lightning>=2.6.6
Requires-Dist: numpy>=2.5.1
Requires-Dist: monai>=1.4.0
Requires-Dist: einops>=0.8.1
Requires-Dist: typing_extensions>=4.13.0
Requires-Dist: anhaltai-commons-minio>=0.2.2
Requires-Dist: python-dotenv>=1.2.2
Requires-Dist: nibabel>=5.2.1
Requires-Dist: scikit-learn>=1.5.1
Requires-Dist: minio>=7.2.20
Requires-Dist: pydantic>=2.11.4
Requires-Dist: typing_extensions>=4.13.2
Requires-Dist: pydantic_core>=2.33.2
Requires-Dist: transformers>=4.55.2
Requires-Dist: pillow>=11.2.1
Dynamic: license-file

# MAGDI Data

This python package named ``magdi_data is`` responsible for data loading to be used for
AI training.
It also contains the definition of a specific dataset structure.

## Setup

- `pip install -r requirements.txt` to run AI experiments
- `pip install -r requirements-tests.txt` to run pytest
- Copy `.env-example` as `.env` file and set your credentials and other env variables
  there

## dataset_meta.json

The dataset_meta.json describes a dataset in the Occurrence Instance Format.
Its properties have to follow a strict format to be readable by humans and machines.

## How to create a dataset

Read [README_create_occ_inst_dataset.md](./README_create_occ_inst_dataset.md)

### Terms

#### Occurrence

- An occurrence is a real scanned object. It can have one or more instances (replicates
  or measurements).

#### Instance

- An instance is a digitalized object.

### Contents

| property                   | description                                                                                                                                                       | input  | json type        | example                                                                                                                        |
|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|------------------|--------------------------------------------------------------------------------------------------------------------------------|
| status                     | Current status of the dataset. Default: "not_verified". Possible values: "not_verified", "verified", "deleted", "locked".                                         | auto   | string           | "not_verified"                                                                                                                 |
| id                         | Identifier of the dataset. Used as the folder name. Automatically generated from `name`, `release`, and `uuid`. Immutable after creation.  Immutable.             | auto   | string           | "Maize_2025.07.02_abc123..."                                                                                                   |
| uuid                       | Universally unique identifier assigned to this dataset. Immutable.                                                                                                | auto   | string           | "abc123..."                                                                                                                    |
| measurement_channel        | Measurement channel, how the real object was scanned                                                                                                              | manual | string           | "lipid"                                                                                                                        |
| species_en                 | English name of the species. Replaces old field `entity`.                                                                                                         | manual | string           | "Zea mays"                                                                                                                     |
| species_de                 | German name of the species.                                                                                                                                       | manual | string           | "Mais"                                                                                                                         |
| species_la                 | Latin name of the species.                                                                                                                                        | manual | string           | "Zea mays"                                                                                                                     |
| organ_en                   | English name of the biological organ or structure. Replaces old field `structure`.                                                                                | manual | string           | "maize"                                                                                                                        |
| organ_de                   | German translation of the organ name.                                                                                                                             | manual | string           | "Mais"                                                                                                                         |
| development_stage_en       | Development stage of the biological sample (e.g., "seedling", "mature").                                                                                          | manual | string           | "seedling"                                                                                                                     |
| development_stage_de       | German translation of development stage.                                                                                                                          | manual | string           | "Keimling"                                                                                                                     |
| name                       | English name of the dataset.                                                                                                                                      | manual | string           | "Maize"                                                                                                                        |
| name_de                    | German translation of the dataset name.                                                                                                                           | manual | string           | "Mais"                                                                                                                         |
| original_name              | Optional. Previously used name                                                                                                                                    | manual | string           | "technical_name_1234"                                                                                                          |
| release                    | Version release string (e.g., YYYY.MM.DD). Immutable.                                                                                                             | auto   | string           | "2025.07.02"                                                                                                                   |
| line_name                  | Name of the plant line                                                                                                                                            | manual | string           | "B73"                                                                                                                          |
| device                     | The device used to scan the real objects                                                                                                                          | manual | string           | "Manufacturer NMR Device XYZ "                                                                                                 |
| coil                       | Coil of the device                                                                                                                                                | manual | string           | "MICWB40 RES 400 1H 040/010 LTR"                                                                                               |
| description                | Short description of the dataset.                                                                                                                                 | manual | string           | "NMR dataset with all maize samples..."                                                                                        |
| reference                  | Source or publication where data was derived from. Can be URL or citation.                                                                                        | manual | string           | "Leibniz Institute of Plant Genetics and Crop Plant Research (IPK)"                                                            |
| license                    | License under which the dataset is published.                                                                                                                     | manual | string           | "IPK proprietary"                                                                                                              |
| publishing_venue           | Optional list of venues where the dataset or related work was published.                                                                                          | manual | array of string  | ["Zenodo", "Hugging Face", "MRI Hub"]                                                                                          |
| tags                       | Modalities describing the dataset (e.g., imaging modality, domain). See Hugging Face modality list.                                                               | manual | array of string  | ["MRI", "3D", "Image"]                                                                                                         |
| task_categories            | ML tasks the dataset is intended for. See Hugging Face task list.                                                                                                 | manual | array of string  | ["image-segmentation"]                                                                                                         |
| labels                     | Optional class label mapping. Keys must be ascending integers starting at 0, formatted as strings. No gaps allowed. Missing keys must have empty string as value. | manual | object           | { "0": "background", "1": "embryo", "2": "endosperm" }                                                                         |
| image_format               | File extension of the image files (e.g., .nii.gz, .png).                                                                                                          | auto   | string           | ".nii.gz"                                                                                                                      |
| annotation_format          | Optional. File extension of annotation files (e.g., masks).                                                                                                       | auto   | string           | ".nii.gz"                                                                                                                      |
| num_instances_total        | Total number of instances across all splits. Immutable.                                                                                                           | auto   | integer          | 4                                                                                                                              |
| num_instances_training     | Number of instances in training split. Immutable.                                                                                                                 | auto   | integer          | 2                                                                                                                              |
| num_instances_test         | Optional. Number of instances in test split. Immutable.                                                                                                           | auto   | integer          | 2                                                                                                                              |
| num_instances_validation   | Optional. Number of instances in validation split. Immutable.                                                                                                     | auto   | integer          | 2                                                                                                                              |
| num_occurrences_total      | Total number of occurrences (biological samples). Immutable.                                                                                                      | auto   | integer          | 4                                                                                                                              |
| num_occurrences_training   | Number of occurrences in training split. Immutable.                                                                                                               | auto   | integer          | 2                                                                                                                              |
| num_occurrences_test       | Optional. Number of occurrences in test split. Immutable.                                                                                                         | auto   | integer          | 2                                                                                                                              |
| num_occurrences_validation | Optional. Number of occurrences in validation split. Immutable.                                                                                                   | auto   | integer          | 2                                                                                                                              |
| image_data_type            | Data type of image values compatible with NumPy (np.dtype).                                                                                                       | auto   | string           | "int16"                                                                                                                        |
| annotation_data_type       | Optional. Data type of annotation values.                                                                                                                         | auto   | string           | "uint8"                                                                                                                        |
| value_channels             | Number of channels per image (e.g., 1 for grayscale, 3 for RGB).                                                                                                  | auto   | integer          | 1                                                                                                                              |
| range                      | auto specification of possible voxel value range across all instances.                                                                                            | auto   | array of number  | [0, 1000]                                                                                                                      |
| range_max                  | Maximum value across all instances. Automatically calculated during validation.                                                                                   | auto   | number           | 1000                                                                                                                           |
| range_min                  | Minimum value across all instances. Automatically calculated during validation.                                                                                   | auto   | number           | 0                                                                                                                              |
| range_avg                  | Average value across all instances. Automatically calculated during validation.                                                                                   | auto   | number           | 500.0                                                                                                                          |
| dimensions_max             | Dimensions of the largest image. Automatically calculated.                                                                                                        | auto   | array of integer | [96, 128, 150]                                                                                                                 |
| dimensions_min             | Dimensions of the smallest image. Same shape as dimensions_max. Automatically calculated.                                                                         | auto   | array of integer | [41, 64, 78]                                                                                                                   |
| dimensions_avg             | Average dimensions across all images. Same shape as dimensions_max. Automatically calculated.                                                                     | auto   | array of number  | [57.496, 92.015, 115.603]                                                                                                      |
| resolution_unit            | Unit used for voxel size (e.g., mm, µm).                                                                                                                          | auto   | string           | "mm"                                                                                                                           |
| resolution_voxel_size      | auto specification of voxel size per dimension.                                                                                                                   | auto   | array of number  | [0.1, 0.1, 0.1]                                                                                                                |
| resolution_voxel_size_max  | Maximum voxel size across all instances. Automatically calculated.                                                                                                | auto   | array of number  | [0.1, 0.1, 0.1]                                                                                                                |
| resolution_voxel_size_min  | Minimum voxel size across all instances. Automatically calculated.                                                                                                | auto   | array of number  | [0.1, 0.1, 0.1]                                                                                                                |
| resolution_voxel_size_avg  | Average voxel size across all instances. Automatically calculated.                                                                                                | auto   | array of number  | [0.1, 0.1, 0.1]                                                                                                                |
| training                   | List of image and annotation paths for training instances. "image" is required; "annotations" is required only for labeled data. Immutable.                       | auto   | array of object  | `[{"image": "occurrence-0001/instance-0000/image.nii.gz", "annotations": "occurrence-0001/instance-0000/annotations.nii.gz"}]` |
| test                       | Optional. Same structure as training for test split.                                                                                                              | auto   | array of object  | `[{"image": "occurrence-0004/instance-0000/image.nii.gz", "annotations": "occurrence-0004/instance-0000/annotations.nii.gz"}]` |
| validation                 | Optional. Same structure as training for validation split.                                                                                                        | auto   | array of object  | `[{"image": "occurrence-0002/instance-0000/image.nii.gz", "annotations": "occurrence-0002/instance-0000/annotations.nii.gz"}]` |
| showcase_images            | Optional subset of instances for presentation (e.g., in websites).                                                                                                | manual | array of object  | `[{"image": "occurrence-0001/instance-0000/image.nii.gz", "annotations": "occurrence-0001/instance-0000/annotations.nii.gz"}]` |
| data_references            | Maps file paths to real-world identifiers (e.g., sample IDs). Used for traceability. Immutable.                                                                   | auto   | object           | `{"occurrence-0000/instance-0000/image.nii.gz": "sample_001"}`                                                                 |

### Example:

````json

{
  "id": "mais_seed_matured_2025-7-5_806fd055-b90d-46d5-a1ce-dd7e61b286ee",
  "uuid": "806fd055-b90d-46d5-a1ce-dd7e61b286ee",
  "species_en": "maize",
  "species_de": "Mais",
  "species_la": "frumentum",
  "organ_en": "seed",
  "organ_de": "Samen",
  "development_stage_en": "matured",
  "development_stage_de": "gereift",
  "name": "Maize Seed Matured",
  "name_de": "Mais Samen Gereift",
  "original_name": "Maize_mix_Classic_mix_M1_res_multi_inst",
  "release": "2025.7.5",
  "line name": "Mais",
  "development_state": "10 DAP",
  "device": "NMR Device",
  "coil": "CRP 13C/1H 5mm 400MHz",
  "measurement channel": "structure",
  "description": "NMR dataset with all maize samples. Test set dispersed among sets 7,8, 10, 11, tree set7 samples discarded.",
  "reference": "Leibniz Institute of Plant Genetics and Crop Plant Research (IPK) ",
  "license": "IPK proprietary",
  "publishing_venue": [],
  "tags": [
    "MRI",
    "3D",
    "Image"
  ],
  "task_categories": [
    "image-segmentation"
  ],
  "labels": {
    "0": "background",
    "1": "embryo",
    "2": "endosperm",
    "3": "aleuron"
  },
  "image_format": ".nii.gz",
  "annotation_format": ".nii.gz",
  "num_instances_total": 6,
  "num_instances_training": 2,
  "num_instances_test": 2,
  "num_instances_validation": 2,
  "num_occurrences_total": 6,
  "num_occurrences_training": 2,
  "num_occurrences_test": 2,
  "num_occurrences_validation": 2,
  "image_data_type": "int16",
  "annotation_data_type": "uint8",
  "value_channels": 1,
  "range": [
    0,
    16000
  ],
  "range_max": 1002,
  "range_min": 0,
  "range_avg": 167.57250248655913,
  "dimensions_max": [
    96,
    128,
    150
  ],
  "dimensions_min": [
    41,
    64,
    78
  ],
  "dimensions_avg": [
    57.49618320610687,
    92.01526717557252,
    115.6030534351145
  ],
  "resolution_unit": "mm",
  "resolution_voxel_size": [
    0.1,
    0.1,
    0.1
  ],
  "resolution_voxel_size_max": [
    0.1,
    0.1,
    0.1
  ],
  "resolution_voxel_size_min": [
    0.1,
    0.1,
    0.1
  ],
  "resolution_voxel_size_avg": [
    0.1,
    0.1,
    0.1
  ],
  "training": [
    {
      "annotations": "occurrence-0000/instance-0000/annotations.nii.gz",
      "image": "occurrence-0000/instance-0000/image.nii.gz"
    },
    {
      "annotations": "occurrence-0001/instance-0000/annotations.nii.gz",
      "image": "occurrence-0001/instance-0000/image.nii.gz"
    }
  ],
  "validation": [
    {
      "annotations": "occurrence-0002/instance-0000/annotations.nii.gz",
      "image": "occurrence-0002/instance-0000/image.nii.gz"
    },
    {
      "annotations": "occurrence-0003/instance-0000/annotations.nii.gz",
      "image": "occurrence-0003/instance-0000/image.nii.gz"
    }
  ],
  "test": [
    {
      "annotations": "occurrence-0004/instance-0000/annotations.nii.gz",
      "image": "occurrence-0004/instance-0000/image.nii.gz"
    },
    {
      "annotations": "occurrence-0005/instance-0000/annotations.nii.gz",
      "image": "occurrence-0005/instance-0000/image.nii.gz"
    }
  ],
  "showcase_images": [
    {
      "annotations": "occurrence-0000/instance-0000/annotations.nii.gz",
      "image": "occurrence-0000/instance-0000/image.nii.gz"
    }
  ],
  "data_references": {
    "occurrence-0000/instance-0000/image.nii.gz": "example1",
    "occurrence-0001/instance-0000/image.nii.gz": "example2",
    "occurrence-0002/instance-0000/image.nii.gz": "example3",
    "occurrence-0003/instance-0000/image.nii.gz": "folder_xyz/exampleA",
    "occurrence-0004/instance-0000/image.nii.gz": "folder_xyz/exampleB",
    "occurrence-0005/instance-0000/image.nii.gz": "folder_xyz/exampleC"
  }
}
````

### Data migration scripts:

There was a migration at Nov 2026.

Change TARGET_FOLDER to the folder of your local datasets and inside the file and then
run it to migrate older files than Nov 2026.

migration_script_datasetmeta_json_11_2026.py
