Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CaimanSegmentationInterface #406

Merged
merged 18 commits into from
Oct 2, 2023
Merged

Conversation

garrettmflynn
Copy link
Member

This PR adds the CaimanSegmentationInterface. An error was thrown on the testing data because there isn't sufficient default metadata to run the conversion and we've ignored the Ophys metadata entry sections.

Error



[2023-09-28 14:06:00,593] ERROR in app: Exception on /neuroconv/convert [POST]
Traceback (most recent call last):
  File "/Users/garrettflynn/Documents/Github/nwb-guide/pyflask/apis/neuroconv.py", line 82, in post
    return convert_to_nwb(neuroconv_api.payload)
  File "/Users/garrettflynn/Documents/Github/nwb-guide/pyflask/manageNeuroconv/manage_neuroconv.py", line 383, in convert_to_nwb
    converter.run_conversion(
  File "/opt/anaconda3/envs/nwb-guide/lib/python3.9/site-packages/neuroconv/nwbconverter.py", line 147, in run_conversion
    self.validate_metadata(metadata=metadata)
  File "/opt/anaconda3/envs/nwb-guide/lib/python3.9/site-packages/neuroconv/nwbconverter.py", line 96, in validate_metadata
    validate(instance=decoded_metadata, schema=self.get_metadata_schema())
  File "/opt/anaconda3/envs/nwb-guide/lib/python3.9/site-packages/jsonschema/validators.py", line 1292, in validate
    raise error
jsonschema.exceptions.ValidationError: 'name' is a required property

Failed validating 'required' in schema['properties']['Ophys']['properties']['TwoPhotonSeries']:
    {'additionalProperties': False,
     'properties': {'bits_per_pixel': {'description': 'DEPRECATED: Number '
                                                      'of bits per image '
                                                      'pixel',
                                       'type': 'number'},
                    'comments': {'default': 'no comments',
                                 'description': 'Human-readable comments '
                                                'about this TimeSeries '
                                                'dataset',
                                 'type': 'string'},
                    'control': {'description': 'Numerical labels that '
                                               'apply to each element in '
                                               'data',
                                'type': 'array'},
                    'control_description': {'description': 'Description of '
                                                           'each control '
                                                           'value',
                                            'type': 'array'},
                    'conversion': {'default': 1.0,
                                   'description': 'Scalar to multiply each '
                                                  'element in data to '
                                                  'convert it to the '
                                                  'specified unit',
                                   'type': 'number'},
                    'description': {'default': 'no description',
                                    'description': 'Description of this '
                                                   'TimeSeries dataset',
                                    'type': 'string'},
                    'device': {'description': 'Device used to capture the '
                                              'images/video.',
                               'target': 'pynwb.device.Device',
                               'type': 'string'},
                    'dimension': {'description': 'Number of pixels on x, '
                                                 'y, (and z) axes.',
                                  'type': 'array'},
                    'field_of_view': {'description': 'Width, height and '
                                                     'depth of image, or '
                                                     'imaged area '
                                                     '(meters).',
                                      'type': 'array'},
                    'format': {'description': 'Format of image. Three '
                                              'types: 1) Image format; '
                                              'tiff, png, jpg, etc. 2) '
                                              'external 3) raw.',
                               'type': 'string'},
                    'imaging_plane': {'description': 'Imaging plane '
                                                     'class/pointer.',
                                      'target': 'pynwb.ophys.ImagingPlane',
                                      'type': 'string'},
                    'name': {'description': 'The name of this TimeSeries '
                                            'dataset',
                             'type': 'string'},
                    'offset': {'default': 0.0,
                               'description': 'Scalar to add to each '
                                              'element in the data scaled '
                                              "by 'conversion' to finish "
                                              'converting it to the '
                                              'specified unit.',
                               'type': 'number'},
                    'pmt_gain': {'description': 'Photomultiplier gain.',
                                 'type': 'number'},
                    'rate': {'description': 'Sampling rate in Hz',
                             'type': 'number'},
                    'resolution': {'default': -1.0,
                                   'description': 'The smallest meaningful '
                                                  'difference (in '
                                                  'specified unit) between '
                                                  'values in data',
                                   'type': 'number'},
                    'scan_line_rate': {'description': 'Lines imaged per '
                                                      'second. This is '
                                                      'also stored in '
                                                      '/general/optophysiology '
                                                      'but is kept here as '
                                                      'it is useful '
                                                      'information for '
                                                      'analysis, and so '
                                                      'good to be stored '
                                                      'w/ the actual data.',
                                       'type': 'number'},
                    'starting_frame': {'description': 'Each entry is a '
                                                      'frame number that '
                                                      'corresponds to the '
                                                      'first frame of each '
                                                      'file listed in '
                                                      'external_file '
                                                      'within the full '
                                                      'ImageSeries.',
                                       'type': 'array'},
                    'starting_time': {'description': 'The timestamp of the '
                                                     'first sample',
                                      'type': 'number'},
                    'unit': {'description': 'The unit of measurement of '
                                            'the image data, e.g., values '
                                            'between 0 and 255. Required '
                                            'when data is specified. If '
                                            'unit (and data) are not '
                                            'specified, then unit will be '
                                            'set to "unknown".',
                             'type': 'string'}},
     'required': ['name', 'imaging_plane'],
     'tag': 'pynwb.ophys.TwoPhotonSeries',
     'type': 'array'}

On instance['Ophys']['TwoPhotonSeries']:
    {'comments': 'no comments',
     'conversion': 1,
     'description': 'no description',
     'resolution': -1}

@garrettmflynn garrettmflynn self-assigned this Sep 28, 2023
@garrettmflynn garrettmflynn added the interface Add support for a specific NeuroConv interface / converter label Sep 28, 2023
@garrettmflynn
Copy link
Member Author

This appears to be a blocker for all Segmentation interfaces. Though, now that I've enabled Ophys in the Metadata form and looked closer at the data structure returned from NeuroConv, it looks like I might be parsing things incorrectly too

However, if I'm not mistaken, we should ideally be able to pass back what was provided from NeuroConv back to Neuroconv—in which case, that is the deeper issue.

@garrettmflynn
Copy link
Member Author

So one point of confusion for me is that ImagingPlane appears to be of type array, but there is no items property. Instead, there is a properties property and the returned array has these properties on both internal elements of the array and on the array itself (looking as if they're intended to apply across entries).

Can you direct me as to how to interpret this?

Screenshot 2023-09-28 at 2 34 18 PM Screenshot 2023-09-28 at 2 36 46 PM

@garrettmflynn
Copy link
Member Author

Ah it looks like you were right. The returned metadata values do not have the extra properties on the array—these are added on the GUIDE side while filling in default values.

@garrettmflynn
Copy link
Member Author

@CodyCBakerPhD Either way, it looks like the fact that the array properties have a properties field rather than an items field is the core problem. Monkey-patching over existing code that assumes the correct structure results in a successful conversion.

@CodyCBakerPhD
Copy link
Collaborator

Monkey-patching over existing code that assumes the correct structure results in a successful conversion.

I tried on this current branch but was unable to get past the metadata page (errored out regarding missing items, I assume from the ophys side)

Are you saying the thing that was successful was #410?

@garrettmflynn
Copy link
Member Author

Yeah. Sorry if that was unclear

@CodyCBakerPhD CodyCBakerPhD marked this pull request as ready for review October 2, 2023 13:42
@CodyCBakerPhD
Copy link
Collaborator

Looks great!

@CodyCBakerPhD CodyCBakerPhD merged commit 8bf96e5 into main Oct 2, 2023
7 checks passed
@CodyCBakerPhD CodyCBakerPhD deleted the CaimanSegmentationInterface branch October 2, 2023 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interface Add support for a specific NeuroConv interface / converter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants