forked from erhanbas/mouse2syglass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syPI.py
138 lines (112 loc) · 6 KB
/
syPI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import requests
import json
import code
###############################################################################
###############################################################################
# Creates a project with an empty tiff file in the center of it
# createEmptyProject('projectName', 'C:/syPI/')
def createEmptyProject(name, pathToSYGFolder):
import tifffile
import numpy as np
import os
cwd = os.getcwd()
empty = np.zeros((1,1,1))
tifffile.imsave('empty.tif', np.uint8(empty))
pathToFile = cwd + '\\empty.tif'
if '/' in pathToSYGFolder:
pathToSYGFolder = pathToSYGFolder.replace('/','\\')
data = {'numChannels': 1, 'name': name, 'convertMax': '255.0', \
'showFrameTemplateString': 0, 'convertMin': '0.0', \
'dataEnum': 'UINT8', 'voxelZ': '1', 'voxelX': '1', \
'voxelY': '1', 'showSliceTemplateString': 0, \
'masterFileList': [[pathToFile]], \
'pathText1': pathToFile, \
'path': pathToSYGFolder, 'extractChannel': 0, 'overwrite': 0, \
'convertType': 'NONE'}
r = requests.post('http://127.0.0.1:8000/syglass/createProject', json.dumps(data))
print(r.status_code, r.reason)
fullPath = pathToSYGFolder + name + '\\' + name + '.syg'
dataForLibrary = {'body': {'path': fullPath, \
'type': 'NONE', 'modality': 'OTHER', 'voxelSize': '(1, 1, 1)',\
'name': name}, 'name': name}
r = requests.post('http://127.0.0.1:8000/syglass/VolumeLibrary/putEntry', json.dumps(dataForLibrary))
print(r.status_code, r.reason)
###############################################################################
###############################################################################
# Create a project with a single tiff stacks
# Example
# createProject('projectName', 'C:/syPI/empty.tif', 'C:/syPI/')
def createProject(name, pathToFile, pathToSYGFolder):
if '/' in pathToFile:
pathToFile = pathToFile.replace('/','\\')
if '/' in pathToSYGFolder:
pathToSYGFolder = pathToSYGFolder.replace('/','\\')
data = {'numChannels': 1, 'name': name, 'convertMax': '255.0', \
'showFrameTemplateString': 0, 'convertMin': '0.0', \
'dataEnum': 'UINT8', 'voxelZ': '1', 'voxelX': '1', \
'voxelY': '1', 'showSliceTemplateString': 0, \
'masterFileList': [[pathToFile]], \
'pathText1': pathToFile, \
'path': pathToSYGFolder, 'extractChannel': 0, 'overwrite': 0, \
'convertType': 'NONE'}
r = requests.post('http://127.0.0.1:8000/syglass/createProject', json.dumps(data))
print(r.status_code, r.reason)
fullPath = pathToSYGFolder + name + '\\' + name + '.syg'
dataForLibrary = {'body': {'path': fullPath, \
'type': 'NONE', 'modality': 'OTHER', 'voxelSize': '(1, 1, 1)',\
'name': name}, 'name': name}
r = requests.post('http://127.0.0.1:8000/syglass/VolumeLibrary/putEntry', json.dumps(dataForLibrary))
print(r.status_code, r.reason)
###############################################################################
###############################################################################
# Add a list of OBJ files to the project
# EXAMPLE:
# import glob
# l = glob.glob('C:/syPI/meshes/*.obj')
# l = [i.replace('/','\\') for i in l]
# print(l)
# addMeshesToProject('C:/syPI/projectName/projectName.syg', 'default', l)
def addMeshesToProject(pathToProject, nameOfExperiment, listOfMeshes):
#{'projectPath': 'C:\\syPI\\name4\\name4.syg', 'dir': 'default', 'path': 'C:\\Users\\mmore\\Downloads\\SevenSisters\\VCN_c09_Axon01.obj\r\nC:\\Users\\mmore\\Downloads\\SevenSisters\\VCN_c09_cellbody.obj\r\nC:\\Users\\mmore\\Downloads\\SevenSisters\\VCN_c09_Dendrite01.obj\r\nC:\\Users\\mmore\\Downloads\\SevenSisters\\VCN_c09_myelin01.obj\r\nC:\\Users\\mmore\\Downloads\\SevenSisters\\VCN_c09_nucleus01.obj\r\n'}
if '/' in pathToProject:
pathToProject = pathToProject.replace('/','\\')
data = {'projectPath': pathToProject, 'dir': nameOfExperiment, 'path': '\r\n'.join(listOfMeshes)}
r = requests.post('http://127.0.0.1:8000/syglass/importMeshOBJs', json.dumps(data))
print(r.status_code, r.reason)
###############################################################################
###############################################################################
# Add DVID data to a project
# Example:
# addDVIDToProject('emdata.janelia.org:80', '90823d3056a044608ebbb5740b6b46c1', 'grayscalejpeg', 'default', 'C:/syPI/projectName/projectName.syg')
def addDVIDToProject(url, uuid, dvidLabelName, nameOfExperiment, pathToProject):
if '/' in pathToProject:
pathToProject = pathToProject.replace('/','\\')
data = {'url': url, 'uuid': uuid, 'dataType': dvidLabelName, 'dir': nameOfExperiment, 'projectPath': pathToProject}
r = requests.post('http://127.0.0.1:8000/syglass/setDVIDFields', json.dumps(data))
print(r.status_code, r.reason)
###############################################################################
###############################################################################
#need to do three things
# 1. read transform data file, convert
# 2. add json file to folder with top level data
# 3. append project path to VolumeLibrary
def buildMouseLightProject(path, name, pathToTransformationFile):
# read transform data file
transformData = dict(line.strip().split(':', 1) for line in open(pathToTransformationFile, 'r'))
level = int(transformData['nl'])
sx = float(transformData['sx']) / 1000.0 / 2**(level-1)
sy = float(transformData['sy']) / 1000.0 / 2**(level-1)
sz = float(transformData['sz']) / 1000.0 / 2**(level-1)
ox = int(transformData['ox']) / 1000.0
oy = int(transformData['oy']) / 1000.0
oz = int(transformData['oz']) / 1000.0
# add json data to folder with top level data
data = {'voxelsize_used_um': [sx, sy, sz], 'origin_um': [ox, oy, oz], 'levels': level-1, 'block_filename': "default.tif"}
with open(path + name + '.json', 'w') as outfile:
json.dump(data, outfile)
dataForLibrary = {'body': {'path': path + name + '.json', \
'type': 'dense', 'modality': 'OTHER', 'voxelSize': '',\
'name': name}, 'name': name}
r = requests.post('http://127.0.0.1:8000/syglass/VolumeLibrary/putEntry', json.dumps(dataForLibrary))
print(r.status_code, r.reason)
buildMouseLightProject('Y:/SAMPLES/2017-09-25/syglass-ch0/', '2017-09-25_ch0.json', 'Y:/SAMPLES/2017-09-25/transform.txt')