Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krokicki committed Jan 10, 2023
1 parent 4c7b090 commit 54558a2
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 165 deletions.
4 changes: 2 additions & 2 deletions neuronbridge/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ class PPPMatch(Match, extra=Extra.forbid):
A PPPMatch is a match generated by the PPPM algorithm between an EMImage and a LMImage.
"""
type: Literal['PPPMatch'] = 'PPPMatch'
pppRank: float = Field(title="PPPM rank", description="Fractional rank reported by the PPPM algorithm. It's generally better to use the index of the image in the results.")
pppScore: int = Field(title="PPPM score", description="Match score reported by the PPPM algorithm.")
pppmRank: float = Field(title="PPPM rank", description="Fractional rank reported by the PPPM algorithm. It's generally better to use the index of the image in the results.")
pppmScore: int = Field(title="PPPM score", description="Match score reported by the PPPM algorithm.")


class CDSMatch(Match, extra=Extra.forbid):
Expand Down
283 changes: 120 additions & 163 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@
by_body = json.loads(
"""
{
"results": [
{
"id": "2945073143148142603",
"type": "EMImage",
"libraryName": "FlyEM_Hemibrain_v1.2.1",
"publishedName": "1734696429",
"alignmentSpace": "JRC2018_Unisex_20x_HR",
"anatomicalArea": "Brain",
"gender": "f",
"store": "fl:hemibrain:v1.2.1",
"files": {
"CDM": "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/1734696429-JRC2018_Unisex_20x_HR-CDM.png",
"CDMThumbnail": "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/1734696429-JRC2018_Unisex_20x_HR-CDM.jpg",
"AlignedBodySWC": "FlyEM_Hemibrain_v1.2.1/1734696429.swc",
"AlignedBodyOBJ": "FlyEM_Hemibrain_v1.2.1/1734696429.obj",
"CDSResults": "2945073143148142603.json",
"PPPMResults": "1734696429.json"
},
"neuronType": "ORN_DA1",
"neuronInstance": "ORN_DA1_L"
}
]
"results" : [ {
"libraryName" : "FlyEM_Hemibrain_v1.2.1",
"alignmentSpace" : "JRC2018_Unisex_20x_HR",
"anatomicalArea" : "Brain",
"gender" : "f",
"neuronType" : "ORN_DA1",
"neuronInstance" : "ORN_DA1_L",
"id" : "2945073143148142603",
"publishedName" : "hemibrain:v1.2.1:1734696429",
"files" : {
"AlignedBodyOBJ" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/OBJ/1734696429.obj",
"CDM" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/1734696429-JRC2018_Unisex_20x_HR-CDM.png",
"store" : "fl:open_data:brain",
"CDMThumbnail" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/1734696429-JRC2018_Unisex_20x_HR-CDM.jpg",
"CDSResults" : "2945073143148142603.json",
"AlignedBodySWC" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/SWC/1734696429.swc",
"PPPMResults" : "2941779068174991906.json"
},
"type" : "EMImage"
} ]
}
""")

Expand All @@ -39,146 +37,90 @@ def test_EMImageLookup():
assert isinstance(img, EMImage)
assert img.id == "2945073143148142603"
assert img.libraryName == "FlyEM_Hemibrain_v1.2.1"
assert img.publishedName == "1734696429"
assert img.publishedName == "hemibrain:v1.2.1:1734696429"
assert img.alignmentSpace == "JRC2018_Unisex_20x_HR"
assert img.gender == Gender.female
assert img.files.CDM == "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/1734696429-JRC2018_Unisex_20x_HR-CDM.png"
assert img.files.CDMThumbnail == "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/1734696429-JRC2018_Unisex_20x_HR-CDM.jpg"
assert img.files.AlignedBodySWC == "FlyEM_Hemibrain_v1.2.1/1734696429.swc"
assert img.files.AlignedBodyOBJ == "FlyEM_Hemibrain_v1.2.1/1734696429.obj"
assert img.files.AlignedBodySWC == "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/SWC/1734696429.swc"
assert img.files.AlignedBodyOBJ == "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/OBJ/1734696429.obj"
assert img.files.CDSResults == "2945073143148142603.json"
assert img.files.PPPMResults == "1734696429.json"
assert img.files.PPPMResults == "2941779068174991906.json"

assert img.neuronType == "ORN_DA1"
assert img.neuronInstance == "ORN_DA1_L"

ppp_results = json.loads(
"""
{
"inputImage": {
"id": "2945073144457764875",
"type": "EMImage",
"libraryName": "FlyEM_Hemibrain_v1.2.1",
"publishedName": "2384750665",
"anatomicalArea": "Brain",
"alignmentSpace": "JRC2018_Unisex_20x_HR",
"gender": "f",
"store": "fl:hemibrain:v1.2.1",
"files": {
"CDM": "$img/JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/2384750665-JRC2018_Unisex_20x_HR-CDM.png",
"CDMThumbnail": "$thm/JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/2384750665-JRC2018_Unisex_20x_HR-CDM.jpg",
"AlignedBodySWC": "$swc/FlyEM_Hemibrain_v1.2.1/2384750665.swc"
},
"neuronType": null,
"neuronInstance": null
},
"results": [
{
"type": "PPPMatch",
"image": {
"id": "2588090337243168866",
"type": "LMImage",
"libraryName": "FlyLight_Gen1_MCFO",
"publishedName": "R20H11",
"alignmentSpace": "JRC2018_Unisex_20x_HR",
"gender": "f",
"store": "fl:hemibrain:v1.2.1",
"files": {
"VisuallyLosslessStack": "https://s3.amazonaws.com/janelia-flylight-imagery/Gen1+MCFO/R20H11/R20H11-20180918_62_A5-f-40x-central-GAL4-JRC2018_Unisex_20x_HR-aligned_stack.h5j"
},
"slideCode": "20180918_62_A5",
"objective": "40x",
"anatomicalArea": "Brain",
"mountingProtocol": "DPX PBS Mounting"
},
"files": {
"CDM": "23/2384750665/2384750665-R20H11-20180918_62_A5-40x-JRC2018_Unisex_20x_HR-ch.png",
"CDMSkel": "23/2384750665/2384750665-R20H11-20180918_62_A5-40x-JRC2018_Unisex_20x_HR-ch_skel.png",
"SignalMip": "23/2384750665/2384750665-R20H11-20180918_62_A5-40x-JRC2018_Unisex_20x_HR-raw.png",
"SignalMipMasked": "23/2384750665/2384750665-R20H11-20180918_62_A5-40x-JRC2018_Unisex_20x_HR-masked_raw.png",
"SignalMipMaskedSkel": "23/2384750665/2384750665-R20H11-20180918_62_A5-40x-JRC2018_Unisex_20x_HR-skel.png"
},
"mirrored": true,
"pppRank": 0.0,
"pppScore": 144
}
]}
"""
)

def test_PPPMatches():
matches = PrecomputedMatches(**ppp_results)
img = matches.inputImage
assert isinstance(img, EMImage)
assert img.id == "2945073144457764875"
assert len(matches.results) == 1
match = matches.results[0]
assert isinstance(match, PPPMatch)
assert isinstance(match.image, LMImage)
assert match.image.id == "2588090337243168866"
assert match.image.gender == Gender.female
assert match.mirrored == True
assert match.files.CDM == "23/2384750665/2384750665-R20H11-20180918_62_A5-40x-JRC2018_Unisex_20x_HR-ch.png"

new_results = json.loads(
"""{
"inputImage" : {
"id" : "2945073147357655051",
"type": "EMImage",
"libraryName" : "FlyEM_Hemibrain_v1.2.1",
"publishedName" : "1253394541",
"alignmentSpace" : "JRC2018_Unisex_20x_HR",
"anatomicalArea": "Brain",
"gender": "f",
"neuronType" : "MC62",
"neuronInstance" : "MC62(LWF5)_R",
"store": "fl:hemibrain:v1.2.1",
"anatomicalArea" : "Brain",
"gender" : "f",
"neuronType" : "ORN_DA1",
"neuronInstance" : "ORN_DA1_L",
"id" : "2945073143148142603",
"publishedName" : "hemibrain:v1.2.1:1734696429",
"files" : {
"CDMThumbnail" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/1253394541-JRC2018_Unisex_20x_HR-CDM.jpg",
"CDM" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/1253394541-JRC2018_Unisex_20x_HR-CDM.png",
"AlignedBodySWC" : "FlyEM_Hemibrain_v1.2.1/1253394541.swc"
}
"CDM" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/1734696429-JRC2018_Unisex_20x_HR-CDM.png",
"AlignedBodySWC" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/SWC/1734696429.swc",
"store" : "fl:open_data:brain",
"AlignedBodyOBJ" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/OBJ/1734696429.obj",
"CDSResults" : "2945073143148142603.json",
"CDMThumbnail" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/1734696429-JRC2018_Unisex_20x_HR-CDM.jpg",
"PPPMResults" : "2941779068174991906.json"
},
"type" : "EMImage"
},
"results" : [ {
"type": "CDSMatch",
"mirrored" : false,
"normalizedScore" : 34433.96,
"matchingPixels" : 73,
"image" : {
"id" : "2775341446398476299",
"type": "LMImage",
"libraryName" : "FlyLight Gen1 MCFO",
"publishedName" : "VT040712",
"alignmentSpace" : "JRC2018_Unisex_20x_HR",
"anatomicalArea" : "Brain",
"gender" : "m",
"slideCode" : "20200221_64_H4",
"slideCode" : "20200124_63_B4",
"objective" : "40x",
"mountingProtocol" : "DPX PBS Mounting",
"channel" : 2,
"store": "fl:hemibrain:v1.2.1",
"publishedName" : "VT023750",
"files" : {
"CDMThumbnail" : "JRC2018_Unisex_20x_HR/FlyLight_Gen1_MCFO/VT040712-20200221_64_H4-GAL4-m-40x-brain-JRC2018_Unisex_20x_HR-CDM_2.jpg",
"CDM" : "JRC2018_Unisex_20x_HR/FlyLight_Gen1_MCFO/VT040712-20200221_64_H4-GAL4-m-40x-brain-JRC2018_Unisex_20x_HR-CDM_2.png",
"VisuallyLosslessStack" : "Gen1+MCFO/VT040712/VT040712-20200221_64_H4-m-40x-central-GAL4-JRC2018_Unisex_20x_HR-aligned_stack.h5j",
"Gal4Expression" : "Gen1/CDM/VT040712/VT040712-sample_003501-f-20x-brain-JRC2018_Unisex_20x_HR-CDM_1.png"
}
"VisuallyLosslessStack" : "Gen1+MCFO/VT023750/VT023750-20200124_63_B4-m-40x-central-GAL4-JRC2018_Unisex_20x_HR-aligned_stack.h5j",
"store" : "fl:open_data:brain"
},
"id" : "2765069201377853538",
"type" : "LMImage"
},
"files" : {
"CDMMatch" : "VT040712-20200221_64_H4-GAL4-m-40x-brain-JRC2018_Unisex_20x_HR-CDM_2-04.png",
"CDMInput" : "1253394541-JRC2018_Unisex_20x_HR-CDM.png"
}
}]
}
"SignalMip" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/17/1734696429/1734696429-VT023750-20200124_63_B4-40x-JRC2018_Unisex_20x_HR-raw.png",
"store" : "fl:open_data:brain",
"CDMBest" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/17/1734696429/1734696429-VT023750-20200124_63_B4-40x-JRC2018_Unisex_20x_HR-ch.png",
"CDMBestThumbnail" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/17/1734696429/1734696429-VT023750-20200124_63_B4-40x-JRC2018_Unisex_20x_HR-ch.jpg",
"SignalMipMaskedSkel" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/17/1734696429/1734696429-VT023750-20200124_63_B4-40x-JRC2018_Unisex_20x_HR-skel.png",
"SignalMipMasked" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/17/1734696429/1734696429-VT023750-20200124_63_B4-40x-JRC2018_Unisex_20x_HR-masked_raw.png",
"CDMSkel" : "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/17/1734696429/1734696429-VT023750-20200124_63_B4-40x-JRC2018_Unisex_20x_HR-ch_skel.png"
},
"pppmRank" : 0.0,
"pppmScore" : 129,
"type" : "PPPMatch"
}
]}
"""
)

def test_NewMatches():
matches = PrecomputedMatches(**new_results)
assert isinstance(matches.inputImage, EMImage)
def test_PPPMatches():
matches = PrecomputedMatches(**ppp_results)
img = matches.inputImage
assert isinstance(img, EMImage)
assert img.id == "2945073143148142603"
assert len(matches.results) == 1
match = matches.results[0]
assert isinstance(match, CDSMatch)
assert isinstance(match, PPPMatch)
assert isinstance(match.image, LMImage)
assert match.image.id == "2765069201377853538"
assert match.image.gender == Gender.male
assert match.mirrored == False
assert match.files.CDMBest == "JRC2018_Unisex_20x_HR/FlyEM_Hemibrain_v1.2.1/17/1734696429/1734696429-VT023750-20200124_63_B4-40x-JRC2018_Unisex_20x_HR-ch.png"


config = json.loads(
Expand All @@ -195,8 +137,8 @@ def test_NewMatches():
}
},
"stores": {
"fl:hemibrain:v1.2.1": {
"label": "FlyLight vs Hemibrain",
"fl:open_data:brain": {
"label": "FlyLight Brain Open Data Store",
"anatomicalArea": "Brain",
"prefixes": {
"CDM": "https://s3.amazonaws.com/janelia-flylight-color-depth/",
Expand All @@ -210,55 +152,71 @@ def test_NewMatches():
"SignalMipMasked": "https://s3.amazonaws.com/janelia-ppp-match-prod/",
"SignalMipMaskedSkel": "https://s3.amazonaws.com/janelia-ppp-match-prod/",
"SignalMipExpression": "https://s3.amazonaws.com/janelia-ppp-match-prod/",
"AlignedBodySWC": "https://s3.amazonaws.com/janelia-flylight-color-depth/SWC/",
"AlignedBodyOBJ": "https://s3.amazonaws.com/janelia-flylight-color-depth/OBJ/",
"CDSResults": "https://s3.amazonaws.com/janelia-neuronbridge-data-prod/v3.0.0-alpha/metadata/cdsresults/",
"PPPMResults": "https://s3.amazonaws.com/janelia-neuronbridge-data-prod/v3.0.0-alpha/metadata/pppresults/",
"VisuallyLosslessStack": "https://s3.amazonaws.com/janelia-flylight-imagery/"
"AlignedBodySWC": "https://s3.amazonaws.com/janelia-flylight-color-depth/",
"AlignedBodyOBJ": "https://s3.amazonaws.com/janelia-flylight-color-depth/",
"CDSResults": "https://s3.amazonaws.com/janelia-neuronbridge-data-devpre/v3.0.0/metadata/cdsresults/",
"PPPMResults": "https://s3.amazonaws.com/janelia-neuronbridge-data-devpre/v3.0.0/metadata/pppresults/",
"VisuallyLosslessStack": "https://s3.amazonaws.com/janelia-flylight-imagery/",
"Gal4Expression": "https://s3.amazonaws.com/janelia-flylight-imagery/"
},
"customSearch": {
"alignmentSpace": "JRC2018_Unisex_20x_HR",
"searchFolder": "searchable_neurons",
"lmLibraries": [
"FlyLight_Split-GAL4_Drivers",
"FlyLight_Gen1_MCFO",
"FlyLight_Annotator_Gen1_MCFO"
{
"name": "FlyLight_Split-GAL4_Drivers"
},
{
"name": "FlyLight_Gen1_MCFO"
},
{
"name": "FlyLight_Annotator_Gen1_MCFO"
}
],
"emLibraries": [
"FlyEM_Hemibrain_v1.2.1"
{
"name": "FlyEM_Hemibrain_v1.2.1",
"publishedNamePrefix": "hemibrain:v1.2.1"
}
]
}
},
"fl:vnc:latest": {
"label": "FlyLight vs VNC",
"fl:pre_release:vnc": {
"label": "FlyLight VNC Pre-Release Store",
"anatomicalArea": "VNC",
"prefixes": {
"CDM": "https://s3.amazonaws.com/janelia-flylight-color-depth/",
"CDMThumbnail": "https://s3.amazonaws.com/janelia-flylight-color-depth-thumbnails/",
"CDMInput": "https://s3.amazonaws.com/janelia-flylight-color-depth/",
"CDMMatch": "https://s3.amazonaws.com/janelia-flylight-color-depth/",
"CDMBest": "https://s3.amazonaws.com/janelia-ppp-match-prod/",
"CDMBestThumbnail": "https://s3.amazonaws.com/janelia-ppp-match-prod/",
"CDMSkel": "https://s3.amazonaws.com/janelia-ppp-match-prod/",
"SignalMip": "https://s3.amazonaws.com/janelia-ppp-match-prod/",
"SignalMipMasked": "https://s3.amazonaws.com/janelia-ppp-match-prod/",
"SignalMipMaskedSkel": "https://s3.amazonaws.com/janelia-ppp-match-prod/",
"SignalMipExpression": "https://s3.amazonaws.com/janelia-ppp-match-prod/",
"AlignedBodySWC": "https://s3.amazonaws.com/janelia-flylight-color-depth/SWC/",
"AlignedBodyOBJ": "https://s3.amazonaws.com/janelia-flylight-color-depth/OBJ/",
"CDSResults": "https://s3.amazonaws.com/janelia-neuronbridge-data-prod/v3.0.0-alpha/metadata/cdsresults/",
"PPPMResults": "https://s3.amazonaws.com/janelia-neuronbridge-data-prod/v3.0.0-alpha/metadata/pppresults/",
"VisuallyLosslessStack": "https://s3.amazonaws.com/janelia-flylight-imagery/"
"CDM": "https://s3.amazonaws.com/janelia-flylight-color-depth-devpre/",
"CDMThumbnail": "https://s3.amazonaws.com/janelia-flylight-color-depth-thumbnails-devpre/",
"CDMInput": "https://s3.amazonaws.com/janelia-flylight-color-depth-devpre/",
"CDMMatch": "https://s3.amazonaws.com/janelia-flylight-color-depth-devpre/",
"CDMBest": "https://s3.amazonaws.com/janelia-ppp-match-devpre/",
"CDMBestThumbnail": "https://s3.amazonaws.com/janelia-ppp-match-devpre/",
"CDMSkel": "https://s3.amazonaws.com/janelia-ppp-match-devpre/",
"SignalMip": "https://s3.amazonaws.com/janelia-ppp-match-devpre/",
"SignalMipMasked": "https://s3.amazonaws.com/janelia-ppp-match-devpre/",
"SignalMipMaskedSkel": "https://s3.amazonaws.com/janelia-ppp-match-devpre/",
"SignalMipExpression": "https://s3.amazonaws.com/janelia-ppp-match-devpre/",
"AlignedBodySWC": "https://s3.amazonaws.com/janelia-flylight-color-depth-devpre/",
"AlignedBodyOBJ": "https://s3.amazonaws.com/janelia-flylight-color-depth-devpre/",
"CDSResults": "https://s3.amazonaws.com/janelia-neuronbridge-data-devpre/v3.0.0/metadata/cdsresults/",
"PPPMResults": "https://s3.amazonaws.com/janelia-neuronbridge-data-devpre/v3.0.0/metadata/pppresults/",
"VisuallyLosslessStack": "https://s3.amazonaws.com/janelia-flylight-imagery/",
"Gal4Expression": "https://s3.amazonaws.com/janelia-flylight-imagery/"
},
"customSearch": {
"alignmentSpace": "JRC2018_VNC_Unisex_40x_DS",
"searchFolder": "searchable_neurons",
"lmLibraries": [
"FlyLight_Split-GAL4_Drivers",
"FlyLight_Gen1_MCFO"
{
"name": "FlyLight_Split-GAL4_Drivers"
},
{
"name": "FlyLight_Gen1_MCFO"
}
],
"emLibraries": [
"FlyEM_VNC_v0.6"
{
"name": "FlyEM_VNC_v0.6",
"publishedNamePrefix": "vnc:v0.6"
}
]
}
}
Expand All @@ -278,4 +236,3 @@ def test_DataConfig():
for dataSetName in data_config.stores:
store = data_config.stores[dataSetName]
assert store.anatomicalArea in data_config.anatomicalAreas
assert store.customSearch.alignmentSpace in alignmentSpaces

0 comments on commit 54558a2

Please sign in to comment.