Beispiel #1
0
    devices = {
        d: nwb['general']['devices'][d].value.decode('UTF-8')
        for d in nwb['general']['devices']
    }

    # -- read data - intracellular_ephys
    ie_filtering = nwb['general']['intracellular_ephys']['whole_cell'][
        'filtering'].value

    ie_location = nwb['general']['intracellular_ephys']['whole_cell'][
        'location'].value
    brain_region = re.split(',\s?', ie_location)[-1]
    coord_ap_ml_dv = re.findall('\d+.\d+', ie_location)

    # hemisphere: left-hemisphere is ipsi, so anything contra is right
    brain_region, hemisphere = utilities.get_brain_hemisphere(brain_region)
    brain_location = {
        'brain_region': brain_region,
        'brain_subregion': 'N/A',
        'cortical_layer': 'N/A',
        'hemisphere': hemisphere
    }
    # -- BrainLocation
    if brain_location not in reference.BrainLocation.proj():
        reference.BrainLocation.insert1(brain_location)
    # -- ActionLocation
    action_location = dict(brain_location,
                           coordinate_ref='bregma',
                           coordinate_ap=round(Decimal(coord_ap_ml_dv[0]), 2),
                           coordinate_ml=round(Decimal(coord_ap_ml_dv[1]), 2),
                           coordinate_dv=round(Decimal(coord_ap_ml_dv[2]), 2))
    probe_placement_brain_loc = re.search("(?<=\[\')(.*)(?=\'\])", probe_placement_brain_loc).group()

    # -- Probe
    if {'probe_name': device_names[0], 'channel_counts': len(electrodes)} not in reference.Probe.proj():
        reference.Probe.insert1(
                {'probe_name': device_names[0],
                 'channel_counts': len(electrodes)})
        reference.Probe.Channel.insert((
            {'probe_name': device_names[0], 'channel_counts': len(electrodes), 'channel_id': electrode[0],
             'channel_x_pos': electrode[1], 'channel_y_pos': electrode[2], 'channel_z_pos': electrode[3],
             'shank_id' : int(re.search('\d+', electrode[-2].decode('UTF-8')).group())}
            for electrode in electrodes))

    # -- BrainLocation
    # hemisphere: left-hemisphere is ipsi, so anything contra is right
    brain_region, hemisphere = utilities.get_brain_hemisphere(probe_placement_brain_loc)
    brain_location = {'brain_region': brain_region,
                      'brain_subregion': 'N/A',
                      'cortical_layer': 'N/A',
                      'hemisphere': hemisphere}
    # -- BrainLocation
    if brain_location not in reference.BrainLocation.proj():
        reference.BrainLocation.insert1(brain_location)
    # -- ActionLocation
    ground_coordinates = nwb['general']['extracellular_ephys']['ground_coordinates'].value  # using 'ground_coordinates' here as the x, y, z for where the probe is placed in the brain, TODO double check if this is correct
    action_location = dict(brain_location,
                           coordinate_ref='bregma',
                           coordinate_ap=round(Decimal(str(ground_coordinates[0])), 2),
                           coordinate_ml=round(Decimal(str(ground_coordinates[1])), 2),
                           coordinate_dv=round(Decimal(str(ground_coordinates[2])), 2))
    if action_location not in reference.ActionLocation.proj():