oktavpua

Untitled

Sep 8th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import bfj
  3.  
  4. ## SPLIT FILES FOR PARALLEL
  5.  
  6. ## IMPORT LIBRARIES
  7. import numpy as np
  8.  
  9. bfj.load_inputs(globals())
  10.  
  11. ## PUT DATA INTO THE BIG ARRAY
  12.  
  13. ## data 300*18*1681 (time*components*sensors^2)
  14. ## points - array with saved points (coordinates) [0,8,16,24,32,40]
  15. ## length - time length - 300
  16. ## output - fDataX, fDataY - cubs 3*3 points for morfing, original morfing (target)
  17.  
  18. def get_array(data, points,length):
  19. t,l,p2 = data.shape
  20. t = int(t)
  21. l = int(l)
  22. p2 = int(p2)
  23.  
  24. p = int(np.sqrt(p2))
  25. Yset = np.zeros(( l, t, p, p, 1))
  26.  
  27. for elements in range(l):
  28. data_set = data[:,elements,:]
  29. data_set = np.reshape(data_set,(t,p,p))
  30. Yset[elements,:,:,:,0] = data_set
  31.  
  32. sYset = np.reshape(Yset,(l, int(t/length), length, p, p, 1))
  33. sYset = np.reshape(sYset,(int(l*t/length), length, p, p, 1))
  34.  
  35. wd = int(np.size(points)) - 2 # amount of windows in a row
  36. num_of_cubs = wd*wd
  37. wd_size = points[2] + 1 # size of a cell 17*17 or 13*13 or 15*15
  38.  
  39. fDataX = np.zeros((int(l*t/length*wd*wd), length, 3, 3, 1)) # SET INPUT
  40. #fDataY = np.zeros((int(l*t/length*wd*wd), length, wd_size, wd_size, 1)) # SET TARGETS
  41.  
  42. nX = np.zeros(( int(l*t/length), length, 3, 3, 1))
  43. #nY = np.zeros(( int(l*t/length), length, wd_size, wd_size, 1))
  44.  
  45. for n in range(wd):
  46. for nn in range(wd):
  47. nX[:,:,0,0,:] = sYset[:, :, points[n], points[nn],:]
  48. nX[:,:,1,1,:] = sYset[:, :, points[n+1], points[nn+1],:]
  49. nX[:,:,2,2,:] = sYset[:, :, points[n+2], points[nn+2],:]
  50. nX[:,:,0,1,:] = sYset[:, :, points[n], points[nn+1],:]
  51. nX[:,:,0,2,:] = sYset[:, :, points[n], points[nn+2],:]
  52. nX[:,:,1,0,:] = sYset[:, :, points[n+1], points[nn],:]
  53. nX[:,:,1,2,:] = sYset[:, :, points[n+1], points[nn+2],:]
  54. nX[:,:,2,1,:] = sYset[:, :, points[n+2], points[nn+1],:]
  55. nX[:,:,2,0,:] = sYset[:, :, points[n+2], points[nn],:]
  56.  
  57. #nY = sYset[:, :, points[n]:(points[n+2]+1), points[nn]:(points[nn+2]+1), :]
  58.  
  59. fDataX[int((wd*n+nn)*l*t/length):int((wd*n+nn)*l*t/length + l*t/length), :, :, :, :] = nX
  60. #fDataY[int((wd*n+nn)*l*t/length):int((wd*n+nn)*l*t/length + l*t/length), :, :, :, :] = nY
  61. return fDataX, num_of_cubs #fDataY
  62.  
  63.  
  64. # In[3]:
  65.  
  66.  
  67. ## IMPORT DATA
  68.  
  69. #file1 = h5py.File('MphS2445.mat','r') ## BACHATA
  70. #data = file1['MphS']
  71.  
  72. ## TAKE SHIFTS ARRAY
  73.  
  74. #file2 = h5py.File('SH.hdf5','r')
  75. #SH = file2['SH']
  76.  
  77. ## TAKE FIXED SHIFTS ARRAY
  78.  
  79. #if os.path.isfile('FixSH.hdf5'): ## check if we have fixed shifts and download
  80. # file3 = h5py.File('FixSH.hdf5','r')
  81. # SHf = np.asarray(file3['SH'], dtype=int)
  82. # SHf_ind = np.asarray(file3['ind'], dtype=int)
  83.  
  84. #if (Tru == 1) || (Tru ==3): ## check if we have fixed shifts and download
  85. # file3 = h5py.File('FixSH.hdf5','r')
  86. # SHf = np.asarray(file3['SH'], dtype=int)
  87. # SHf_ind = np.asarray(file3['ind'], dtype=int)
  88.  
  89.  
  90. ## EXSTRACT PARAMETERS
  91.  
  92. length_of_sig, componentsXnum_sensors, start_grid2 = data.shape
  93. length_of_sig = int(length_of_sig)
  94. componentsXnum_sensors = int(componentsXnum_sensors)
  95. start_grid2 = int(start_grid2)
  96. components = 18
  97. num_sensors = int(componentsXnum_sensors/components)
  98. start_grid = np.sqrt(start_grid2)
  99.  
  100. ## GET CUBS
  101.  
  102. points = np.arange(0, start_grid,dtype=int)
  103. dataX, num_of_cubs = get_array(data, points, length_of_sig)
  104.  
  105. dataX = np.reshape(dataX,(int(num_of_cubs*components) , num_sensors, length_of_sig, 3, 3))
  106.  
  107. ## split SH and dataX into 886 for parallel
  108. count = 10 # 9!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
  109.  
  110. for i in range(886): #!! num_sensors
  111. exec("bfj.save_package(label = '{}_{}', meta=dict(instance=instance, count = count, number_of_depth = number_of_depth, depth = depth, xpow = xpow, ypow = ypow, zpow = zpow, xcenter = xcenter, ycenter = ycenter, fd = fd, lmod = lmod, fmin = fmin, fmax = fmax, fbeg = fbeg, fend = fend, L = L, number_of_sensor = {}), data = dict(SH{} = SH[{},:,:,:], dataX{} = dataX[:,{},:,:,:], cr = cr, bin1 = bin1, MphS = MphS, domain_X = domain_X, domain_Y = domain_Y, domain_Z = domain_Z, field = field, field_mphs = field_mphs))".format(depth,i+1,i+1,i+1,i, i+1,i))
  112. #bfj.save_package(label = '1', meta=dict(instance=instance, count = count, number_of_depth = number_of_depth, depth = depth, xpow = xpow, ypow = ypow, zpow = zpow, xcenter = xcenter, ycenter = ycenter, fd = fd, lmod = lmod, fmin = fmin, fmax = fmax, fbeg = fbeg, fend = fend, L = L, number_of_sensor = {}), data = dict(SH = SH[i,:,:,:], dataX = dataX[:,i,:,:,:], cr = cr, bin1 = bin1, MphS = MphS, domain_X = domain_X, domain_Y = domain_Y, domain_Z = domain_Z, field = field, field_mphs = field_mphs))
  113.  
  114. #exec("bfj.save_package(meta=dict(instance=instance, number_of_sensor = {}), data = dict(SH{} = SH[{},:,:,:], dataX{} = dataX[:,{},:,:,:]))".format(i+1,i+1,i, i+1,i))
  115.  
  116.  
  117. #for i in range(20): #!! num_sensors
  118. # with h5py.File('SH'+str(i+1)+'.hdf5', 'w') as f:
  119. # f.create_dataset( name = 'SH', data=SH[i,:,:,:])
  120.  
  121. # with h5py.File('dataX'+str(i+1)+'.hdf5', 'w') as f:
  122. # f.create_dataset( name = 'dataX', data=dataX[:,i,:,:,:])
  123.  
  124. #if os.path.isfile('FixSH.hdf5'): ## only if we have fixed sensors
  125. #if Tru:
  126. # n_fix_sen = len(SHf_ind)
  127. # for i in range(n_fix_sen):
  128. # ind = SHf_ind[i]
  129. # with h5py.File('SH'+str(ind+1)+'.hdf5', 'w') as f:
  130. # f.create_dataset( name = 'SH', data=SHf[i,:,:,:])
Advertisement
Add Comment
Please, Sign In to add comment