SHARE
TWEET

Untitled

a guest Jul 19th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from pprint import pprint as pp
  2. import pickle
  3. import numpy as np
  4. import argparse
  5. import yaml
  6. import time
  7. import sys
  8. import numpy
  9. import matplotlib.pyplot as plt
  10. import os
  11. import matplotlib.animation as animation
  12. from pathlib import Path
  13.  
  14.  
  15. def parse_args(args):
  16.     parsed_args = None
  17.     parser = argparse.ArgumentParser()
  18.     parser.add_argument('scan_data_filename', type=str)
  19.     parser.add_argument('pixel_resolution', type=float)
  20.     parser.add_argument('--canvas_range', nargs="+", type=int)
  21.     parser.add_argument('--animation', action='store_true')
  22.  
  23.     # add canvas_size and pixel_resolution arguments
  24.     try:
  25.         parsed_args = parser.parse_args()
  26.     except Exception as e:
  27.         raise RuntimeError("Could not parse args due to invalid/missing argument: {0}".format(e))
  28.  
  29.     if parsed_args is None:
  30.         raise RuntimeError("")
  31.    
  32.     return parsed_args
  33.  
  34.  
  35. def scan_iterate(xx,yy,platform_pos,range_bins,canvas_size,scan_data):
  36.         mm_x = (xx - platform_pos[0])
  37.         mm_y = (yy - platform_pos[1])
  38.         mm_z = np.full(canvas_size, platform_pos[2], dtype='float16') # create array before?
  39.         o = np.sqrt(np.square(mm_x)+np.square(mm_y)+np.square(mm_z))
  40.         v = np.interp(o, range_bins, scan_data)
  41.         return v
  42.        
  43.  
  44. def main(args): # refactor this file so that it can be animated or not -- make it more vesatile
  45.     # fig = plt.figure()
  46.     # a = time.time()
  47.     parsed_args = parse_args(args)
  48.  
  49.     with open(parsed_args.scan_data_filename,'rb') as f:
  50.         data = pickle.load(f)
  51.    
  52.     # platform_pos = data['platform_pos']
  53.     # with open(parsed_args.mocap_filename,'r') as f:
  54.         # platform_pos =
  55.  
  56.     range_bins = data['range_bins'] # np.reshape() # (1056,)
  57.     scan_data = data['scan_data']                  # (1287,1056)
  58.    
  59.     canvas_range = parsed_args.canvas_range
  60.     pixel_resolution = parsed_args.pixel_resolution
  61.     canvas_size = (int((canvas_range[1]-canvas_range[0])/pixel_resolution),
  62.                    int((canvas_range[3]-canvas_range[2])/pixel_resolution))
  63.  
  64.     total_distance = 12.2
  65.     curated_scan_data = scan_data[400:980]
  66.     distance_interval = total_distance/len(curated_scan_data)
  67.  
  68.     # curated_range = 980-400 # 580
  69.  
  70.     platform_pos = np.zeros((len(curated_scan_data),3))
  71.  
  72.     platform_pos[:,0] = np.arange(-total_distance/2, total_distance/2, distance_interval)
  73.     platform_pos[:,1] = 0
  74.     platform_pos[:,2] = 1
  75.  
  76.     # pp(platform_pos)
  77.  
  78.     curated_platform_pos = platform_pos#[400:980]
  79.  
  80.     # pp(curated_platform_pos)
  81.  
  82.  
  83.     # pp(curated_scan_data.shape)
  84.  
  85.     height = np.arange(canvas_range[0],canvas_range[1],pixel_resolution) # constructor with 120 times 0.12 steps from -3 to 3
  86.     width = np.arange(canvas_range[2],canvas_range[3],pixel_resolution)
  87.  
  88.     xx, yy = np.meshgrid(width,height) # check direction...?
  89.     output = np.zeros(canvas_size,dtype='complex64')
  90.     output_array = []
  91.    
  92.     for i in range(len(curated_scan_data)):
  93.         # pass
  94.         v = scan_iterate(xx,yy,curated_platform_pos[i],range_bins,canvas_size,curated_scan_data[i])
  95.         output += v
  96.         # feed it the pulse each time...
  97.         # if parsed_args.animation == True:
  98.         #     abs_val_img = np.abs(output)
  99.         #     img = plt.imshow(abs_val_img,animated=True)
  100.         #     output_array.append([img])
  101.         #     pp(i)
  102.  
  103.     if parsed_args.animation == True:
  104.         # ani = animation.ArtistAnimation(fig, output_array, interval=25, repeat_delay=300)
  105.         # ani.save('{0}.mp4'.format(Path(parsed_args.scan_data_filename).stem))
  106.         # plt.show()
  107.         pass
  108.     else:
  109.         output = np.flip(output,0)
  110.         abs_val_img = np.abs(output)
  111.         pp(abs_val_img)    
  112.         plt.imshow(abs_val_img)
  113.         # pp(time.time()-a)
  114.         plt.show()
  115.         pp(platform_pos)
  116.  
  117.  
  118. def printing(args):
  119.     parsed_args = parse_args(args)
  120.     with open(parsed_args.scan_data_filename,'rb') as f:
  121.         data = pickle.load(f)
  122.         pp(data)
  123.  
  124.  
  125. if __name__ == "__main__":
  126.     # a = time.time()
  127.     main(sys.argv[1:])
  128.     # printing(sys.argv[1:])
  129.     # pp(time.time()-a)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top