Commit 32abb9df authored by Bryson Howell's avatar Bryson Howell

Ready to collect all terrains

parent 743c17e8
......@@ -139,8 +139,8 @@ def get_terrain_map(lat_lon = [0,0], sample_dist = 10, extent = 100, heading = 0
if verbosity:
print("total calls: {}".format(np.square(cc)))
print("For extent of %d, we're making %d calls with window %d" % (extent,cc,sample_extents))
print(" For extent of %d, we're making %d calls with window %d" % (extent,cc,sample_extents))
# set max values
elv_layer.extent['xmin'] = lhc_pt[0]
elv_layer.extent['xmax'] = lhc_pt[0] + extent
......@@ -154,7 +154,7 @@ def get_terrain_map(lat_lon = [0,0], sample_dist = 10, extent = 100, heading = 0
e = np.empty([0,sc*cc])
data = []
for j in range(cc): # outter loop for y values
print('Iteration %d/%d' % (j,cc))
print(' Iteration %d/%d' % (j,cc))
# lists of values for a single row, reset at every y iteration
x_row = np.empty([sc,0])
y_row = np.empty([sc,0])
......
......@@ -56,14 +56,14 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he
#print("Making grid of size %d" % scaled_extent)
viz_cnt = 0
viz_cnt_inac = 0
viz_map = np.zeros([scaled_extent,scaled_extent,len(name_list)])
viz_map_inac = np.zeros([scaled_extent,scaled_extent,len(inac_layers)])
viz_map = np.zeros([scaled_extent,scaled_extent,len(name_list)],dtype=np.uint8)
viz_map_inac = np.zeros([scaled_extent,scaled_extent,len(inac_layers)],dtype=np.uint8)
for i,url in enumerate(url_list):
# binary map, will use feature coords to populate (one per layer)
bin_map = np.zeros([scaled_extent,scaled_extent])
inac_bin_map = np.zeros([scaled_extent,scaled_extent])
bin_map = np.zeros([scaled_extent,scaled_extent],dtype=np.uint8)
inac_bin_map = np.zeros([scaled_extent,scaled_extent],dtype=np.uint8)
#Array of rings and a spatial reference
#Docs - https://developers.arcgis.com/python/api-reference/arcgis.geometry.html
......@@ -295,10 +295,10 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he
plot_name = ''
if plot_data:
if(get_elev):
t = 'Elevation ' + case_name
t = 'Area ' + file_id + ' - Elevation'
plt.title(t)
plt.imshow(e_interp)
plot_name = plot_dir + 'elevation_' + case_name
plot_name = plot_dir + file_id + '_elevation'
plt.savefig(plot_name)
plt.close()
#plt.show()
......@@ -313,18 +313,18 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he
# flip y values
# col_idx = viz_map.shape[0] - col_idx
# plt_list.append(go.Scatter(x=row_idx, y=col_idx, mode='markers', name=name_list[i]))
t = name_list[i] + " " + case_name
t = 'Area ' + file_id + ' - ' + name_list[i]
plt.title(t)
plt.imshow(viz_map[:,:,i])
plot_name = plot_dir + name_list[i] + '_features'
plot_name = plot_dir + file_id + '_' + name_list[i]
plt.savefig(plot_name)
plt.close()
for i in range(viz_map_inac.shape[-1]):
t = "Inacessible " + inac_layers[i] + " " + case_name
t = 'Area ' + file_id + ' - ' + "Inacessible " + inac_layers[i]
plt.title(t)
plt.imshow(viz_map_inac[:,:,i])
plot_name = plot_dir + 'inac_' + inac_layers[i]
plot_name = plot_dir + file_id + '_inac_' + inac_layers[i]
plt.savefig(plot_name)
plt.close()
......
......@@ -18,7 +18,7 @@ from LostPersonModel.main_hiker import run_replicate #change this import to wh
def main(exp_name='test', n_envs=1, n_iter=10):
def main(exp_name='test', start_idx=0, n_envs=1, n_iter=10):
test_extent = 20000
download_extent = 40000
......@@ -31,16 +31,22 @@ def main(exp_name='test', n_envs=1, n_iter=10):
find_latlons = incidents[["find_lat","find_lon"]].to_numpy(dtype=np.float32())
areas = incidents['area'].to_numpy(dtype=np.float32())
start = 0
n_envs = np.size(np.unique(areas))
for i in range(start, start+n_envs):
#Limit what environments we run
if(n_envs < 0):
n_envs = np.size(np.unique(areas))
end_idx = start_idx + n_envs
if(end_idx > np.size(np.unique(areas))):
end_idx = np.size(np.unique(areas))
#Calculate cells from extent
scale_factor = 3/20 # factor to get 6.66667m mapping from 1m mapping (1/6.6667)
extent = np.ceil(scale_factor*download_extent).astype(np.int32)
for i in range(start_idx, end_idx):
#Pull incident locations for environment
i_area = np.argwhere(areas==i)
i_area = np.transpose(i_area)[0]
s = 'Area {0} - indices are {1}'
lst = [i,i_area]
print(s.format(*lst))
#test - print start / end locations on grid
grid = np.zeros((3000,3000),dtype=np.int8())
......@@ -58,12 +64,35 @@ def main(exp_name='test', n_envs=1, n_iter=10):
cur_ipp = ipp_latlons[i_area[incident+subzone]]
ipp_xy = lat_lon2meters(cur_ipp[0],cur_ipp[1])
print(cur_ipp)
#Convert
#Locate find position from IPP
#Convert both to meters
#Use extent / cell count to determine which cell we're in:
#Actually maybe not, main_hiker takes start / find as meters positions
#Position Matrix
#Then grid is basically recreated, we have position matrix x[:] y[:] behavior[:] starts empty
#First index is ? second is timestep, with 2 added to end (why)
#I think I need to fix these. They're 1D arrays.
#Hiker Movement
#First x,y meters position is set to 0,0
#second is chosen randomly, from -1, 0, 1 so we randomly move to an adjacent cell
#Behavior is not initialized so you start by backtracking, to the initial position...
#p_behavior - probability file of hiker actions. looks like 6 bins. We use fitted profile.
#T - length of simulation. walking speed * simulation hours (fitted to 100 hours, 850 m/hr?)
#LL - map limits (3000,3000,1)
#alpha is smoothing
#Result is list of x, y coordinates of the hiker as well as behavior selected.
#I should probably rewrite the whole thing...
#But what I can do is walk back through the steps, adding to a 'heatmap' by doing +1 on cells that are visited
#Then, we normalize it all to 0-1
run_replicate(ipp, find, map, T, p_behavior, alpha, LL)
return
......@@ -137,7 +166,8 @@ def main(exp_name='test', n_envs=1, n_iter=10):
if __name__ == "__main__":
n_env = 1 #Number of environments to test
n_iter = 10
start = 0 #Environment to start at (0 is first, 8 is first large map)
n = 1 #Number of environments to test
mc = 10 #Monte Carlo iterations
main()
main(exp_name='hiker',start_idx=start,n_envs=n,n_iter=mc)
......@@ -313,7 +313,7 @@ def collect_terrain(folder_name='test',start_idx=0,max_collect=1,format_ipps=Fal
#Decide if we want to save pics, and get the elev map (takes a while)
do_plot = True
do_elev = False
do_elev = True
#Loop through unique areas to download
for i in range(start_idx, end_idx):
......@@ -326,67 +326,25 @@ def collect_terrain(folder_name='test',start_idx=0,max_collect=1,format_ipps=Fal
#Now download area centered on first index of area
print("Collecting GIS data %d/%d" % ((i-start_idx)+1,(end_idx-start_idx)))
#Download local map
if(len(i_area) > 0):
if(len(i_area) == 1):
size = extent_test
else:
size = extent_download
ipp = ipp_latlons[i_area[0]]
s = ' Getting Area {0} with IPP(s) {1} - center is {2}'
lst = [i,i_area,ipp]
print(s.format(*lst))
folder_i = folder + '/' + folder + "_" + str(i)
#Call feature_set to make GIS calls
grab_features(ipp, size, sample_dist = res,
case_name = folder_i, save_files = False, save_to_folder = True,
file_id = str(i), plot_data=do_plot, get_elev=do_elev)
print(" Saved terrain in %s" % folder_i)
return
#Limit what we download
if(max_down < 0):
max_down = len(ipp_list)
latlons = incidents[["IPP_lat","IPP_lon"]].to_numpy(dtype=np.float32())
#Now, if there's only one key in an area we can avoid downloading a lot.
#Need to ouput data in a way that indicates if an IPP is a big area or not...
count = 0
do_plot = True
do_elev = True
for i in range(start_down,len(ipp_lat_list)):
print("Collecting GIS data %d/%d" % (i,len(ipp_lat_list)))
#Download local map
if(keys.count(i) < count_thres):
size = extent_test
else:
size = extent_download
if(count < max_down):
count = count + 1
print('Getting initial point - ')
print(ipp_lat_list[i])
folder_i = folder + "_" + str(i)
grab_features(ipp_lat_list[i], size, sample_dist = res, case_name = folder_i, save_files = False, save_to_folder = True, file_id = str(i), plot_data=do_plot, get_elev=do_elev)
return
#Load GIS Features for new area
#grab_features()
#Load elevation
#res = 10 #Resolution of GIS collection
#size = 6000 #Maximum size of map. Is this is latlon, grid cells, ?
#heading is direction of trajectories from north (default 0 degrees?)
#[e,e_interp,x,y,data,lat_lon] = get_terrain_map(ipp_point, sample_dist = res, extent = size, show_plot = True)
#Collect GIS maps and layers for SAR initial positions
def main():
......@@ -397,9 +355,8 @@ def main():
#gis_test()
#group_IPP(listname) #Format incident data correctly
#Friday, 7/26 - make sure we get window size of 625 with larger environment.
#Also, try reducing size of downloads...
collect_terrain(folder_name='test',start_idx=0,max_collect=1)
#This is ready to run now. Can we get heatmaps at the same time?
collect_terrain(folder_name='trust',start_idx=0,max_collect=-1)
#investigate()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment