diff --git a/scripts/waln_to_json.py b/scripts/waln_to_json.py new file mode 100644 index 0000000000000000000000000000000000000000..f44cba5c843e35c862f967e15cf52faec996e4f5 --- /dev/null +++ b/scripts/waln_to_json.py @@ -0,0 +1,61 @@ +import json +import re +import os + +''' +Sharon Yates, 04.04.24. +This is a script for converting WALN and WWRP files from WebAlign and WebWarp to VisuAlign compatible JSON files. +To be used for testing purposes. +''' + +def waln_to_json(filename): + with open(filename) as f: + vafile = json.load(f) + if filename.endswith(".waln") or filename.endswith("wwrp"): + slices = vafile["sections"] # define slices as "section" in waln + vafile["slices"] = slices + + for slice in slices: + print(slice) # this prints info from waln to screen. + if "filename" in slice: + base_name = os.path.basename(slice["filename"]).split('.')[0] + new_filename = base_name + '.png' + slice["filename"] = new_filename + slice["nr"] = int(re.search(r"_s(\d+)", slice["filename"]).group(1)) + if "ouv" in slice: + slice["anchoring"] = slice["ouv"] + + ''' + for slice in slices: + print(slice) # this prints info from waln to screen. + if "filename" in slice: + name, old_extension = slice["filename"].rsplit('.',1) + new_filename = name + '.png' + slice["filename"] = new_filename + slice["nr"] = int(re.search(r"_s(\d+)", slice["filename"]).group(1)) + if "ouv" in slice: + slice["anchoring"] = slice["ouv"] + ''' + + name = os.path.basename(filename) + va_compat_file = { + "name": name.replace(".waln",".json"), + "target": vafile["atlas"] + '.cutlas', + "target-resolution": [456, 528, 320], + "slices": slices + } + # save with .json extension need to see if i can remove this + with open( + filename.replace(".waln", ".json").replace(".wwrp", ".json"), "w" + ) as f: + #json.dump(va_compat_file, f, indent=4) + json.dump(va_compat_file, f, indent=4) + + print("Waln or Wwrp converted successfully to JSON") + + else: + pass + +waln_to_json("PyNutil_test_2.waln") + + diff --git a/testOOP.py b/testOOP.py index 0cab45c0927c8f278787fa111f8b8609640574c9..3109bb82b350068bd4c4d1741a54cfe3ca82438e 100644 --- a/testOOP.py +++ b/testOOP.py @@ -6,9 +6,9 @@ os.chdir("..") pnt = PyNutil(settings_file=r"PyNutil/test/test10_PyNutil_web.json") -##Use flat can be set to True if you want to use the flat file -# instead of the visualign json (this is only useful for testing and will be removed) -pnt.get_coordinates(object_cutoff=0, method="per_pixel") +##use_flat can be set to True if you want to use the flat file +## for method select between "all", "per_pixel" and "per_object" +pnt.get_coordinates(object_cutoff=0, method="per_pixel", use_flat=False) pnt.quantify_coordinates() diff --git a/test_data/PyNutil_test_2.waln b/test_data/PyNutil_test_2.waln new file mode 100644 index 0000000000000000000000000000000000000000..a14a8306d5014c41f469a3fc079d636914761454 --- /dev/null +++ b/test_data/PyNutil_test_2.waln @@ -0,0 +1 @@ +{"atlas":"ABA_Mouse_CCFv3_2017_25um","sections":[{"filename":"PyNutil_test/test_s001.dzip","width":1500,"height":1000,"snr":1,"format":"png","current":0,"tilesize":254,"overlap":1,"mode":0,"ouv":[-5.145275115966797,361.8014440433213,331.1490739071843,456,0,0,0,0,-320],"markers":[[440.0000000000001,289,450,323]]},{"filename":"PyNutil_test/test_s002.dzip","width":1500,"height":1000,"snr":2,"format":"png","current":0,"tilesize":254,"overlap":1,"mode":0,"ouv":[-3.8589563369750977,318.7157039711191,340.24552914037605,456,0,0,0,0,-320],"markers":[[636.8098159509204,603.4958601655935,672.6993865030674,593.3762649494021],[902.9868982011025,615.5567336628567,843.8650306748466,610.8555657773691],[561.2609204260139,750.3661510917975,558.5889570552147,775.5289788408462]]},{"filename":"PyNutil_test/test_s003.dzip","width":1500,"height":1000,"snr":3,"format":"png","current":0,"tilesize":254,"overlap":1,"mode":0,"ouv":[-2.8942172527313232,275.6299638989171,350.0189942541106,456,0,0,0,0,-320],"markers":[[761.0429447852762,629.2548298068077,741,500],[204.29447852760745,613.6154553817848,365.3374233128834,612.695492180313],[482.6376861494953,714.9876920193675,623.0061349693251,747.0101195952162],[434.00208292806684,606.7676930120547,578.8343558282207,601.6559337626494],[959.8159509202455,636.6145354185834,980.0613496932516,628.3348666053357],[957.8161415293836,523.3987679117937,953.3742331288344,547.3781048758049]]},{"filename":"PyNutil_test/test_s004.dzip","width":1500,"height":1000,"snr":4,"format":"png","current":0,"tilesize":254,"overlap":1,"mode":0,"ouv":[-3.0282087922096252,232.54422382671487,364.1366059225139,456,0,0,0,0,-320],"markers":[[522.6993865030674,712.9714811407543,530.6338374725239,715.7313707451705],[630.6438500513034,523.1833943062713,550.3067484662577,519.7792088316469],[916.4047791164191,534.1886045162021,962.5766871165645,523.4590616375344],[950.8076359295408,705.46368100121,925,668],[1096.1208774051677,649.3153717520049,1115,675],[1030.2378410339393,594.2011916220456,1065.644171779141,604.4158233670653]]},{"filename":"PyNutil_test/test_s005.dzip","width":1500,"height":1000,"snr":5,"format":"png","current":0,"tilesize":254,"overlap":1,"mode":0,"ouv":[-0.6163610816001892,189.45848375451277,374.2485759765199,456,0,0,0,0,-320]}],"bucket":"ewb-3d1dc41f-4256-4db5-bc75-0642369e1354"} \ No newline at end of file