neuro-ml / amid

Awesome Medical Imaging Datasets
https://neuro-ml.github.io/amid/
MIT License
39 stars 8 forks source link

unpacking metadata fields #52

Open kurmukovai opened 1 year ago

kurmukovai commented 1 year ago

Many medium datasets, especially those published in nii.gz, provide meta information (such as sex, age, manufacturer, etc.) in the form of a CSV spreadsheet or JSON. Currently, in AMID, we have two ways of unpacking these CSVs and creating dataset fields:

  1. Automatically, e.g., AMOS
  2. Manually, e.g., EGD

The first option is cleaner as it does not require writing repetitive code:

def field_name(_meta):
    return _meta[field_name]

However, the second option results in explicitly defined methods, allowing the addition of docstrings, and visibility in documentation. For instance, right now, AMOS has many fields not visible in the documentation:

image image Which of these two options should we prefer?

maxme1 commented 1 year ago

We could write a kind of factory for such methods:

def _field(*keys):
    def wrapper(_metadata):
        for field in fields:
          _metadata = _metadata[field]
        return _metadata
    return wrapper

and use it like so

class ...:
    age = _field('Clinical_data', 'Age')