@@ -315,90 +315,90 @@ def calculate_star_map(req: RunRequest, hash_val: int):
315315
316316 star_map_hash_val = create_hash_starmap (req , dynamic_layer , hash_val )
317317
318- # load the cache info
319- # try:
320- # with open(f"./cache/starmap_{star_map_hash_val}.pickle", 'rb') as f:
321- # print("found cache star map in starmap ")
322- #except FileNotFoundError:
323- # create polar map
318+ # Check if StaRMap available
319+ try :
320+ with open (f"./cache/starmap_{ star_map_hash_val } .pickle" , 'rb' ) as f :
321+ print (f "found cached StaRMap in file starmap_ { star_map_hash_val } .pickle " )
322+ app . star_map = f
323+ except FileNotFoundError :
324324
325- # apply uncertainty to all osm fetched map feature
326- loc_type_table = _get_location_type_table ()
327- loc_to_uncertainty = dict ()
328- for entry in loc_type_table :
329- if entry .std_dev != 0 :
330- loc_to_uncertainty [entry .location_type ] = (entry .std_dev ** 2 ) * eye (2 )
325+ # apply uncertainty to all osm fetched map feature
326+ loc_type_table = _get_location_type_table ()
327+ loc_to_uncertainty = dict ()
328+ for entry in loc_type_table :
329+ if entry .std_dev != 0 :
330+ loc_to_uncertainty [entry .location_type ] = (entry .std_dev ** 2 ) * eye (2 )
331331
332- carte_map = polar_map .to_cartesian ()
333- carte_map .apply_covariance (loc_to_uncertainty )
332+ carte_map = polar_map .to_cartesian ()
333+ carte_map .apply_covariance (loc_to_uncertainty )
334334
335- polar_map = carte_map .to_polar ()
335+ polar_map = carte_map .to_polar ()
336336
337- # create all markers, lines and polygons to uam
338- for marker in markers :
339- if marker .location_type == "" :
340- continue
337+ # create all markers, lines and polygons to uam
338+ for marker in markers :
339+ if marker .location_type == "" :
340+ continue
341341
342- polar_marker = PolarLocation (marker .latlng [1 ],
343- marker .latlng [0 ],
344- location_type = marker .location_type )
345- if marker .std_dev != 0 :
346- cartesian_marker = polar_marker .to_cartesian (origin )
347- cartesian_marker .covariance = (marker .std_dev ** 2 ) * eye (2 )
348- polar_marker = cartesian_marker .to_polar (origin )
342+ polar_marker = PolarLocation (marker .latlng [1 ],
343+ marker .latlng [0 ],
344+ location_type = marker .location_type )
345+ if marker .std_dev != 0 :
346+ cartesian_marker = polar_marker .to_cartesian (origin )
347+ cartesian_marker .covariance = (marker .std_dev ** 2 ) * eye (2 )
348+ polar_marker = cartesian_marker .to_polar (origin )
349349
350- polar_map .features .append (polar_marker )
350+ polar_map .features .append (polar_marker )
351351
352- for polyline in polylines :
353- if polyline .location_type == "" :
354- continue
355- locations = []
356- for location in polyline .latlngs :
357- locations .append (PolarLocation (location [1 ], location [0 ]))
352+ for polyline in polylines :
353+ if polyline .location_type == "" :
354+ continue
355+ locations = []
356+ for location in polyline .latlngs :
357+ locations .append (PolarLocation (location [1 ], location [0 ]))
358358
359- polyline_feature = PolarPolyLine (locations , location_type = polyline .location_type )
359+ polyline_feature = PolarPolyLine (locations , location_type = polyline .location_type )
360360
361- if polyline .std_dev != 0 :
362- cartesian_polyline = polyline_feature .to_cartesian (origin )
363- cartesian_polyline .covariance = (polyline .std_dev ** 2 ) * eye (2 )
364- polyline_feature = cartesian_polyline .to_polar (origin )
361+ if polyline .std_dev != 0 :
362+ cartesian_polyline = polyline_feature .to_cartesian (origin )
363+ cartesian_polyline .covariance = (polyline .std_dev ** 2 ) * eye (2 )
364+ polyline_feature = cartesian_polyline .to_polar (origin )
365365
366- polar_map .features .append (polyline_feature )
366+ polar_map .features .append (polyline_feature )
367367
368- for polygon in polygons :
369- if polygon .location_type == "" :
370- continue
371- locations = []
372- for location in polygon .latlngs :
373- locations .append (PolarLocation (location [1 ], location [0 ]))
368+ for polygon in polygons :
369+ if polygon .location_type == "" :
370+ continue
371+ locations = []
372+ for location in polygon .latlngs :
373+ locations .append (PolarLocation (location [1 ], location [0 ]))
374374
375- polygon_feature = PolarPolygon (locations , location_type = polygon .location_type )
375+ polygon_feature = PolarPolygon (locations , location_type = polygon .location_type )
376376
377- if polygon .std_dev != 0 :
378- cartesian_polygon = polygon_feature .to_cartesian (origin )
379- cartesian_polygon .covariance = (polygon .std_dev ** 2 ) * eye (2 )
380- polygon_feature = cartesian_polygon .to_polar (origin )
377+ if polygon .std_dev != 0 :
378+ cartesian_polygon = polygon_feature .to_cartesian (origin )
379+ cartesian_polygon .covariance = (polygon .std_dev ** 2 ) * eye (2 )
380+ polygon_feature = cartesian_polygon .to_polar (origin )
381381
382- polar_map .features .append (polygon_feature )
382+ polar_map .features .append (polygon_feature )
383383
384384
385- uam = polar_map .to_cartesian ()
385+ uam = polar_map .to_cartesian ()
386386
387- # Setting up the probabilistic spatial relations from the UAM
388- star_map = StaRMap (uam )
387+ # Setting up the probabilistic spatial relations from the UAM
388+ star_map = StaRMap (uam )
389389
390- # Initializing the StaR Map on a raster of points evenly spaced out across the mission area,
391- # sampling 25 random variants of the UAM for estimating the spatial relation parameters
392- support_resolutions = req .support_resolutions
393- evaluation_points = CartesianRasterBand (origin , support_resolutions , width , height )
390+ # Initializing the StaR Map on a raster of points evenly spaced out across the mission area,
391+ # sampling 25 random variants of the UAM for estimating the spatial relation parameters
392+ support_resolutions = req .support_resolutions
393+ evaluation_points = CartesianRasterBand (origin , support_resolutions , width , height )
394394
395- star_map .initialize (evaluation_points , sample_size , logic )
395+ star_map .initialize (evaluation_points , sample_size , logic )
396396
397- # origin, width, height, num_iteration, num_improvement
397+ # origin, width, height, num_iteration, num_improvement
398398
399- # star_map.save(f"./cache/starmap_{star_map_hash_val}.pickle")
399+ star_map .save (f"./cache/starmap_{ star_map_hash_val } .pickle" )
400400
401- app .star_map = star_map
401+ app .star_map = star_map
402402
403403 return star_map_hash_val
404404
0 commit comments