In [8]:
import json
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import cv2
In [9]:
jf = "m247514_Site3Annotation_MN_global.json"
In [10]:
with open("m247514_Site3Annotation_MN_global.json") as jd:
d = json.load(jd)
In [11]:
al0 = d['area_lists'][0]
In [12]:
for i in range(len(al0['areas'])):
x = al0['areas'][i]['global_path']
In [13]:
x = [i[0] for i in al0['areas'][0]['global_path']]
y = [-i[1] for i in al0['areas'][0]['global_path']]
z = [al0['areas'][0]['z'] for i in al0['areas'][0]['global_path']]
In [14]:
len(d['area_lists'])
Out[14]:
In [15]:
plt.plot(x, y, 'ro')
plt.plot(np.mean(x), np.mean(y), 'ro', color = 'blue')
plt.show()
In [16]:
def colMean(globalPath, z):
x = np.mean([i[0] for i in globalPath])
y = np.mean([i[1] for i in globalPath])
z = np.mean(z)
means = [x,y,z]
return(means)
def colMedian(globalPath, z):
x = np.median([i[0] for i in globalPath])
y = np.median([i[1] for i in globalPath])
z = np.median(z)
medians = [x,y,z]
return(medians)
def colm(globalPath, z):
xmin = np.min([i[0] for i in globalPath])
ymin = np.min([i[1] for i in globalPath])
zmin = np.min(z)
mins = [(xmin, ymin, zmin)]
return(mins)
def colM(globalPath, z):
xmax = np.max([i[0] for i in globalPath])
ymax = np.max([i[1] for i in globalPath])
zmax = np.max(z)
maxs = [(xmax, ymax, zmax)]
return(maxs)
In [17]:
am = []
arm = []
arM = []
ids = []
for ai in d['area_lists']:
anno = { 'id': ai['id'], 'ggp': [], 'z': []}
ids.append(ai['id'])
for gp in ai['areas']:
anno['ggp'].extend(gp['global_path'])
anno['z'].append(gp['z'])
am.append([colMean(anno['ggp'], anno['z']), anno['id']])
arm.append(colm(anno['ggp'], anno['z']))
arM.append(colM(anno['ggp'], anno['z']))
In [18]:
idsp1 = [i + 1 for i in ids]
In [19]:
anno_at = np.asarray(np.round([[(i[0][0]*3)/96, (i[0][1]*3)/96, i[0][2]] for i in am]))
anno_em = np.asarray(np.round([[i[0][0], i[0][1], i[0][2]] for i in am]))
anno_nm = np.asarray(([[i[0][0]/3, i[0][1]/3, i[0][2]] for i in am]))
In [20]:
tmp = anno_at
dfg = np.column_stack([tmp,ids])
In [39]:
#anno_at[0]
tmp = np.delete(np.vstack(np.asarray(arm)), 6,0)
ranges = {
'xmin':(np.min(tmp[:,0])*3/96),
'xmax':(np.max(tmp[:,0])*3/96),
'ymin':(np.min(tmp[:,1])*3/96),
'ymax':(np.max(tmp[:,1])*3/96),
'zmin':(np.min(tmp[:,2])),
'zmax':(np.max(tmp[:,2]))}
#ranges = {
# 'xmin':(np.round(np.min(tmp[:,0]))),
# 'xmax':(np.round(np.max(tmp[:,0]))),
# 'ymin':(np.round(np.min(tmp[:,1]))),
# 'ymax':(np.round(np.max(tmp[:,1]))),
# 'zmin':np.round(np.min(tmp[:,2])),
# 'zmax':np.round(np.max(tmp[:,2]))}
ranges
Out[39]:
In [ ]:
In [32]:
if False:
#a = np.asarray(np.round(am))
np.savetxt("rorb_locations_nm.csv", np.column_stack([anno_nm, ids]), delimiter=",", fmt = "%f")
np.savetxt("rorb_locations_at.csv", np.column_stack([anno_at, ids]), delimiter=",", fmt = "%d")
np.savetxt("rorb_locations_em.csv", np.column_stack([anno_em, ids]), delimiter=",", fmt = "%d")
In [35]:
if False:
#a = np.asarray(np.round(am))
np.savetxt("rorb_locations_nm_idp1.csv", np.column_stack([anno_nm, idsp1]), delimiter=",", fmt = "%f")
np.savetxt("rorb_locations_at_idp1.csv", np.column_stack([anno_at, idsp1]), delimiter=",", fmt = "%d")
np.savetxt("rorb_locations_em_idp1.csv", np.column_stack([anno_em, idsp1]), delimiter=",", fmt = "%d")
In [ ]:
In [ ]: