简体   繁体   中英

Setting datajoint key to a different variable in make fxn

Wondering why and when it's needed to set the key to a different variable in a make/maketuples function in an auto-populated table in datajoint, as in the documentation here .

In this example, the part table SegmentationROI is defined as follows:

%{
# Region of interest resulting from segmentation
-> test.Segmentation
roi  : smallint   # roi number
---
roi_pixels  : longblob   #  indices of pixels
roi_weights : longblob   #  weights of pixels
%}

classdef SegmentationROI < dj.Part
    properties(SetAccess=protected)
        master = test.Segmentation
    end
    methods
        function make(self, key)
            image = fetch1(test.Image & key, 'image');
            [roi_pixels, roi_weighs] = mylib.segment(image);
            for roi=1:length(roi_pixels)
                entity = key;
                entity.roi_pixels = roi_pixels{roi};
                entity.roi_weights = roi_weights{roi};
                self.insert(entity)
            end
        end
    end
end

What is the purpose of renaming the key as a separate variable, entity (entity = key), and then inserting that?

In this case, we're adding fields to entity as a struct. I'd consider it best practice to preserve arguments a function as-is. If we added a second for-loop here, we might run into issues when calling key for another purpose.

Caveat: I'm more familiar with DataJoint python and have not used it extensively in MATLAB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM