5050import datetime
5151import cProfile
5252
53- import matplotlib .pyplot as plt
54-
5553
5654class Tpu :
5755 """
@@ -121,191 +119,11 @@ def update_fl_stats(self, fl, num_fl_points, fl_tpu_data):
121119 fl_tpu_stddev [ind ])
122120
123121 fl_stats_str = '{}: {:6.3f}{:6.3f}{:6.3f}{:6.3f}' .format (* fl_stats_vals )
124- #fl_stats_str = '{}: {:6d}{:6d}{:6.0f}{:6.0f}'.format(*fl_stats_vals)
125122 fl_stats_strs .append (fl_stats_str )
126123
127124 fl_header_str = f'{ fl } ({ fl_tpu_count } /{ num_fl_points } points with TPU)'
128125 self .flight_line_stats .update ({fl_header_str : fl_stats_strs })
129126
130- def export_diag_data (self , las_base_name , diag_dfs ):
131- diag_data_fields = {
132- 'las_data' : [
133- 'las_name' ,
134- 'flight_line' ,
135- 'raw_class' ,
136- 'las_t' ,
137- 'las_x' ,
138- 'las_y' ,
139- 'las_z' ],
140- 'sbet_data' : [
141- 'sbet_t' ,
142- 'sbet_x' ,
143- 'sbet_y' ,
144- 'sbet_z' ,
145- 'r' ,
146- 'p' ,
147- 'h' ,
148- 'std_r' ,
149- 'std_p' ,
150- 'std_h' ,
151- 'stdx_sbet' ,
152- 'stdy_sbet' ,
153- 'stdz_sbet' ],
154- 'subaerial_data' : [
155- 'rho_est' ,
156- 'a_est' ,
157- 'b_est' ,
158- 'std_a' ,
159- 'std_b' ,
160- 'std_rho' ,
161- 'aer_x_pre_poly' ,
162- 'aer_y_pre_poly' ,
163- 'aer_z_pre_poly' ,
164- 'dx' ,
165- 'dy' ,
166- 'dz' ],
167- 'cblue_position' : [
168- 'cblue_aer_x' ,
169- 'cblue_aer_y' ,
170- 'cblue_aer_z' ,
171- 'cblue_aer_err_x' ,
172- 'cblue_aer_err_y' ,
173- 'cblue_aer_err_z' ],
174- 'subaer_comp_uncertainties' : [
175- 'x_subaer_a' ,
176- 'x_subaer_b' ,
177- 'x_subaer_r' ,
178- 'x_subaer_p' ,
179- 'x_subaer_h' ,
180- 'x_subaer_x' ,
181- 'x_subaer_y' ,
182- 'x_subaer_z' ,
183- 'x_subaer_rho' ,
184- 'y_subaer_a' ,
185- 'y_subaer_b' ,
186- 'y_subaer_r' ,
187- 'y_subaer_p' ,
188- 'y_subaer_h' ,
189- 'y_subaer_x' ,
190- 'y_subaer_y' ,
191- 'y_subaer_z' ,
192- 'y_subaer_rho' ,
193- 'z_subaer_a' ,
194- 'z_subaer_b' ,
195- 'z_subaer_r' ,
196- 'z_subaer_p' ,
197- 'z_subaer_h' ,
198- 'z_subaer_x' ,
199- 'z_subaer_y' ,
200- 'z_subaer_z' ,
201- 'z_subaer_rho' ],
202- 'tpu_data' : [
203- 'subaerial_thu' ,
204- 'subaerial_tvu' ,
205- 'subaqueous_thu' ,
206- 'subaqueous_tvu' ,
207- 'total_thu' ,
208- 'total_tvu' ]
209- }
210-
211- for k , v in diag_data_fields .items ():
212- data = {}
213- for field in v :
214- print (f'adding { field } data to array...' )
215- data [field ] = []
216- for fl_df in diag_dfs :
217- data [field ].extend (fl_df [field ].to_list ())
218-
219- df = pd .DataFrame (data )
220- out_path = Path (self .tpu_output ) / f'{ las_base_name } _{ k } .pkl'
221- print (f'pickling { out_path } ...' )
222- df .to_pickle (str (out_path ))
223-
224- def output_diagnostic_data (self , las_short_name , fl , merged_data ,
225- stddev , subaer_obj , subaqu_obj ,
226- total_thu , total_tvu , raw_class ):
227-
228- print (f'outputting diagnostic data - { las_short_name } , flight line { fl } ...' )
229-
230- las_pos_xyz = (merged_data [2 ], merged_data [3 ], merged_data [4 ], )
231- sensor_model_diag_data = subaer_obj .jacobian .sensor_model .get_sensor_model_diagnostic_data (las_pos_xyz )
232-
233- diag_data = {
234- 'las_name' : las_short_name ,
235- 'flight_line' : fl ,
236- 'raw_class' : raw_class ,
237- 'las_t' : merged_data [1 ],
238- 'las_x' : merged_data [2 ],
239- 'las_y' : merged_data [3 ],
240- 'las_z' : merged_data [4 ],
241- 'sbet_t' : merged_data [0 ],
242- 'sbet_x' : merged_data [5 ],
243- 'sbet_y' : merged_data [6 ],
244- 'sbet_z' : merged_data [7 ],
245- 'r' : merged_data [8 ],
246- 'p' : merged_data [9 ],
247- 'h' : merged_data [10 ],
248- 'std_a' : stddev [0 ],
249- 'std_b' : stddev [1 ],
250- 'std_r' : stddev [2 ],
251- 'std_p' : stddev [3 ],
252- 'std_h' : stddev [4 ],
253- 'stdx_sbet' : stddev [5 ],
254- 'stdy_sbet' : stddev [6 ],
255- 'stdz_sbet' : stddev [7 ],
256- 'std_rho' : stddev [8 ],
257- 'rho_est' : sensor_model_diag_data [0 ],
258- 'a_est' : sensor_model_diag_data [1 ],
259- 'b_est' : sensor_model_diag_data [2 ],
260- 'aer_x_pre_poly' : sensor_model_diag_data [3 ],
261- 'aer_y_pre_poly' : sensor_model_diag_data [4 ],
262- 'aer_z_pre_poly' : sensor_model_diag_data [5 ],
263- 'dx' : sensor_model_diag_data [6 ],
264- 'dy' : sensor_model_diag_data [7 ],
265- 'dz' : sensor_model_diag_data [8 ],
266- 'cblue_aer_x' : sensor_model_diag_data [9 ], # np.round_(total_thu * 100).astype('int')
267- 'cblue_aer_y' : sensor_model_diag_data [10 ],
268- 'cblue_aer_z' : sensor_model_diag_data [11 ],
269- 'cblue_aer_err_x' : sensor_model_diag_data [12 ],
270- 'cblue_aer_err_y' : sensor_model_diag_data [13 ],
271- 'cblue_aer_err_z' : sensor_model_diag_data [14 ],
272- 'x_subaer_a' : np .round_ (subaer_obj .x_comp_uncertainties [0 ] * 1000 ).astype ('uint16' ),
273- 'x_subaer_b' : np .round_ (subaer_obj .x_comp_uncertainties [1 ] * 1000 ).astype ('uint16' ),
274- 'x_subaer_r' : np .round_ (subaer_obj .x_comp_uncertainties [2 ] * 1000 ).astype ('uint16' ),
275- 'x_subaer_p' : np .round_ (subaer_obj .x_comp_uncertainties [3 ] * 1000 ).astype ('uint16' ),
276- 'x_subaer_h' : np .round_ (subaer_obj .x_comp_uncertainties [4 ] * 1000 ).astype ('uint16' ),
277- 'x_subaer_x' : np .round_ (subaer_obj .x_comp_uncertainties [5 ] * 1000 ).astype ('uint16' ),
278- 'x_subaer_y' : None ,
279- 'x_subaer_z' : None ,
280- 'x_subaer_rho' : np .round_ (subaer_obj .x_comp_uncertainties [6 ] * 1000 ).astype ('uint16' ),
281- 'y_subaer_a' : np .round_ (subaer_obj .y_comp_uncertainties [0 ] * 1000 ).astype ('uint16' ),
282- 'y_subaer_b' : np .round_ (subaer_obj .y_comp_uncertainties [1 ] * 1000 ).astype ('uint16' ),
283- 'y_subaer_r' : np .round_ (subaer_obj .y_comp_uncertainties [2 ] * 1000 ).astype ('uint16' ),
284- 'y_subaer_p' : np .round_ (subaer_obj .y_comp_uncertainties [3 ] * 1000 ).astype ('uint16' ),
285- 'y_subaer_h' : np .round_ (subaer_obj .y_comp_uncertainties [4 ] * 1000 ).astype ('uint16' ),
286- 'y_subaer_x' : None ,
287- 'y_subaer_y' : np .round_ (subaer_obj .y_comp_uncertainties [5 ] * 1000 ).astype ('uint16' ),
288- 'y_subaer_z' : None ,
289- 'y_subaer_rho' : np .round_ (subaer_obj .y_comp_uncertainties [6 ] * 1000 ).astype ('uint16' ),
290- 'z_subaer_a' : np .round_ (subaer_obj .z_comp_uncertainties [0 ] * 1000 ).astype ('uint16' ),
291- 'z_subaer_b' : np .round_ (subaer_obj .z_comp_uncertainties [1 ] * 1000 ).astype ('uint16' ),
292- 'z_subaer_r' : np .round_ (subaer_obj .z_comp_uncertainties [2 ] * 1000 ).astype ('uint16' ),
293- 'z_subaer_p' : np .round_ (subaer_obj .z_comp_uncertainties [3 ] * 1000 ).astype ('uint16' ),
294- 'z_subaer_h' : None ,
295- 'z_subaer_x' : None ,
296- 'z_subaer_y' : None ,
297- 'z_subaer_z' : np .round_ (subaer_obj .z_comp_uncertainties [4 ] * 1000 ).astype ('uint16' ),
298- 'z_subaer_rho' : np .round_ (subaer_obj .z_comp_uncertainties [5 ] * 1000 ).astype ('uint16' ),
299- 'subaerial_thu' : subaer_obj .thu ,
300- 'subaerial_tvu' : subaer_obj .tvu ,
301- 'subaqueous_thu' : subaqu_obj .thu ,
302- 'subaqueous_tvu' : subaqu_obj .tvu ,
303- 'total_thu' : total_thu ,
304- 'total_tvu' : total_tvu ,
305- }
306-
307- return pd .DataFrame (diag_data )
308-
309127 def calc_tpu (self , sbet_las_files ):
310128 """
311129
@@ -367,28 +185,15 @@ def calc_tpu(self, sbet_las_files):
367185 total_tvu = ne .evaluate ('sqrt(subaer_tvu**2 + subaqu_tvu**2 + vdatum_mcu**2)' )
368186
369187 fl_tpu_data = np .vstack ((
370- #np.round_(total_thu * 1000).astype('uint16'),
371- #np.round_(total_tvu * 1000).astype('uint16'),
372188 total_thu ,
373189 total_tvu ,
374- merged_data [1 ],
375- merged_data [2 ],
376- merged_data [3 ],
377- merged_data [4 ],
378- raw_class ,
379190 unsort_idx
380191 )).T
381192
382- print (fl_tpu_data )
383193 data_to_output .append (fl_tpu_data )
384194
385195 self .update_fl_stats (fl , num_fl_points , fl_tpu_data )
386196
387- #diag_dfs.append(self.output_diagnostic_data(las.las_short_name, fl,
388- # merged_data, stddev,
389- # subaer_obj, subaqu_obj,
390- # total_thu, total_tvu, raw_class))
391-
392197 else :
393198 logging .warning ('SBET and LAS not merged because max delta '
394199 'time exceeded acceptable threshold of {} '
@@ -400,9 +205,6 @@ def calc_tpu(self, sbet_las_files):
400205 self .write_metadata (las ) # TODO: include as VLR?
401206 self .output_tpu_to_las_extra_bytes (las , data_to_output )
402207
403- ## merge fl diagnostic dataframes
404- #self.export_diag_data(las.las_base_name, diag_dfs)
405-
406208 else :
407209 logging .warning ('WARNING: {} has no data points' .format (las .las_short_name ))
408210
@@ -446,17 +248,11 @@ def output_tpu_to_las_extra_bytes(self, las, data_to_output):
446248 in_las = laspy .file .File (las .las , mode = "r" ) # las is Las object
447249 out_las = laspy .file .File (out_las_name , mode = "w" , header = in_las .header )
448250
449- tpu_data_type = 9 # 3 = laspy unsigned short (2 bytes)
251+ tpu_data_type = 9 # float
450252
451253 extra_byte_dimensions = OrderedDict ([
452254 ('total_thu' , tpu_data_type ),
453- ('total_tvu' , tpu_data_type ),
454- ('t' , tpu_data_type ),
455- ('x' , tpu_data_type ),
456- ('y' , tpu_data_type ),
457- ('z' , tpu_data_type ),
458- ('raw_class' , tpu_data_type ),
459- ('unsort_idx' , tpu_data_type )
255+ ('total_tvu' , tpu_data_type )
460256 ])
461257
462258 num_extra_bytes = len (extra_byte_dimensions .keys ())
@@ -470,12 +266,10 @@ def output_tpu_to_las_extra_bytes(self, las, data_to_output):
470266
471267 if len (data_to_output ) != 0 :
472268 tpu_data = np .vstack (data_to_output )
473- print (tpu_data )
474- extra_byte_df = pd .DataFrame (tpu_data ,
475- index = tpu_data [:, - 1 ],
269+ extra_byte_df = pd .DataFrame (tpu_data [:, 0 :num_extra_bytes ],
270+ index = tpu_data [:, num_extra_bytes ],
476271 columns = extra_byte_dimensions .keys ())
477- print (extra_byte_df )
478-
272+
479273 if extra_byte_df .shape [0 ] == las .num_file_points :
480274 extra_byte_df = extra_byte_df .sort_index ()
481275 else :
@@ -490,27 +284,7 @@ def output_tpu_to_las_extra_bytes(self, las, data_to_output):
490284
491285 logging .debug ('populating extra byte data for total_tvu...' )
492286 out_las .total_tvu = extra_byte_df ['total_tvu' ]
493-
494- logging .debug ('populating extra byte data for t...' )
495- out_las .t = extra_byte_df ['t' ]
496-
497- logging .debug ('populating extra byte data for x...' )
498- out_las .x = extra_byte_df ['x' ]
499-
500- logging .debug ('populating extra byte data for y...' )
501- out_las .y = extra_byte_df ['y' ]
502287
503- logging .debug ('populating extra byte data for z...' )
504- out_las .z = extra_byte_df ['z' ]
505-
506- logging .debug ('populating extra byte data for raw_class...' )
507- out_las .raw_class = extra_byte_df ['raw_class' ]
508-
509- logging .debug ('populating extra byte data for unsort_idx...' )
510- out_las .unsort_idx = extra_byte_df ['unsort_idx' ]
511-
512- #logging.debug('populating extra byte data for masked_fl_t_idx...')
513- #out_las.masked_fl_t_idx = extra_byte_df['masked_fl_t_idx']
514288 else :
515289 logging .debug ('populating extra byte data for total_thu...' )
516290 out_las .total_thu = np .zeros (las .num_file_points )
@@ -575,7 +349,7 @@ def run_tpu_multiprocess(self, num_las, sbet_las_generator):
575349 """
576350
577351 print ('Calculating TPU (multi-processing)...' )
578- p = pp .ProcessPool (4 )
352+ p = pp .ProcessPool (2 )
579353
580354 for _ in tqdm (p .imap (self .calc_tpu , sbet_las_generator ), total = num_las , ascii = True ):
581355 pass
0 commit comments