Commit 6bc3ee89 authored by Bryson Howell's avatar Bryson Howell

Trying to get feature_set.py to run on my end

parent 6fc50d65
...@@ -46,12 +46,12 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he ...@@ -46,12 +46,12 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he
name_list = ['rivers_bdd', 'rivers', 'roads', 'lakes', 'powerlines', 'railroads', 'trails'] name_list = ['rivers_bdd', 'rivers', 'roads', 'lakes', 'powerlines', 'railroads', 'trails']
inac_layers = ['rivers_bdd', 'lakes'] inac_layers = ['rivers_bdd', 'lakes']
gis = GIS(username="larkinheintzman",password="Meepp97#26640") # linked my arcgis pro account gis = GIS(api_key="AAPKe7cb1ab4f2ba44748cf53ac4f30d0caavu5t_-uMdWP8SRjtoea3s66-cRyFZmMTNx4rqy2w5sjwegU_tbJyBesd0LCMmdtV") # linked Bryson's pro account
ap_meters = lat_lon2meters(anchor_point[0], anchor_point[1]) ap_meters = lat_lon2meters(anchor_point[0], anchor_point[1])
scale_factor = 3/20 # factor to get 6.66667m mapping from 1m mapping (1/6.6667) scale_factor = 3/20 # factor to get 6.66667m mapping from 1m mapping (1/6.6667)
scaled_extent = np.ceil(scale_factor*extent).astype(np.int) scaled_extent = np.ceil(scale_factor*extent).astype(np.int32)
viz_cnt = 0 viz_cnt = 0
viz_map = np.zeros([scaled_extent,scaled_extent,len(name_list)+len(inac_layers)]) viz_map = np.zeros([scaled_extent,scaled_extent,len(name_list)+len(inac_layers)])
...@@ -90,7 +90,7 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he ...@@ -90,7 +90,7 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he
print("error on query: {}".format(e)) print("error on query: {}".format(e))
print("{} layer failed on query, trying again ...".format(name_list[i])) print("{} layer failed on query, trying again ...".format(name_list[i]))
# gis. # gis.
gis = GIS(username="larkinheintzman",password="Meepp97#26640") # linked my arcgis pro account gis = GIS(api_key="AAPKe7cb1ab4f2ba44748cf53ac4f30d0caavu5t_-uMdWP8SRjtoea3s66-cRyFZmMTNx4rqy2w5sjwegU_tbJyBesd0LCMmdtV") # linked my arcgis pro account
lyr = FeatureLayer(url=url, gis=gis) lyr = FeatureLayer(url=url, gis=gis)
print("query time {}".format(query_endtime - query_starttime)) print("query time {}".format(query_endtime - query_starttime))
...@@ -99,16 +99,16 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he ...@@ -99,16 +99,16 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he
print("{} layer failed too many times, leaving empty".format(name_list[i])) print("{} layer failed too many times, leaving empty".format(name_list[i]))
if save_files: if save_files:
if save_to_folder: if save_to_folder:
fn = "map_layers\\" + case_name + "\\"+name_list[i]+"_data_"+file_id+".csv" fn = "./map_layers/" + case_name + "/"+name_list[i]+"_data_"+file_id+".csv"
np.savetxt(fn,bin_map,delimiter=",", fmt='%f') np.savetxt(fn,bin_map,delimiter=",", fmt='%f')
if name_list[i] in inac_layers: if name_list[i] in inac_layers:
fn = "map_layers\\" + case_name + "\\" + name_list[i] + "_inac_data_" + file_id + ".csv" fn = "./map_layers/" + case_name + "/" + name_list[i] + "_inac_data_" + file_id + ".csv"
np.savetxt(fn, bin_map, delimiter=",", fmt='%f') np.savetxt(fn, bin_map, delimiter=",", fmt='%f')
else: else:
fn = "map_layers\\" + name_list[i]+"_data_"+file_id+".csv" fn = "./map_layers/" + name_list[i]+"_data_"+file_id+".csv"
np.savetxt(fn,bin_map,delimiter=",", fmt='%f') np.savetxt(fn,bin_map,delimiter=",", fmt='%f')
if name_list[i] in inac_layers: if name_list[i] in inac_layers:
fn = "map_layers\\" + name_list[i] + "_inac_data_" + file_id + ".csv" fn = "./map_layers/" + name_list[i] + "_inac_data_" + file_id + ".csv"
np.savetxt(fn, bin_map, delimiter=",", fmt='%f') np.savetxt(fn, bin_map, delimiter=",", fmt='%f')
continue continue
print("{} layer sucessfully queried".format(name_list[i])) print("{} layer sucessfully queried".format(name_list[i]))
...@@ -213,7 +213,7 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he ...@@ -213,7 +213,7 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he
pts_inac = np.delete(pts_inac, np.where(np.equal(pt,pts_inac).all(1)), axis = 0) pts_inac = np.delete(pts_inac, np.where(np.equal(pt,pts_inac).all(1)), axis = 0)
# binarization step # binarization step
pts_inac = np.round(pts_inac).astype(np.int) pts_inac = np.round(pts_inac).astype(np.int32)
# flip y axis # flip y axis
pts_inac[:,1] = inac_bin_map.shape[1] - pts_inac[:,1] pts_inac[:,1] = inac_bin_map.shape[1] - pts_inac[:,1]
# remove any points outside limits of binary map (fixes round versus ceil issues) # remove any points outside limits of binary map (fixes round versus ceil issues)
...@@ -226,8 +226,8 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he ...@@ -226,8 +226,8 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he
# trim features to scaled extent # trim features to scaled extent
[x_pts, y_pts] = trim_extent(x_pts, y_pts, scaled_extent) [x_pts, y_pts] = trim_extent(x_pts, y_pts, scaled_extent)
# binarization step # binarization step
x_pts_idx = np.round(x_pts).astype(np.int) x_pts_idx = np.round(x_pts).astype(np.int32)
y_pts_idx = np.round(y_pts).astype(np.int) y_pts_idx = np.round(y_pts).astype(np.int32)
# flip y axis because indices are fliped # flip y axis because indices are fliped
y_pts_idx = bin_map.shape[1] - y_pts_idx y_pts_idx = bin_map.shape[1] - y_pts_idx
...@@ -246,10 +246,10 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he ...@@ -246,10 +246,10 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he
viz_cnt = viz_cnt + 1 viz_cnt = viz_cnt + 1
if save_files: if save_files:
if save_to_folder: if save_to_folder:
fn = "map_layers\\" + case_name + "\\" + name_list[i] + "_inac_data_" + file_id + ".csv" fn = "./map_layers/" + case_name + "/" + name_list[i] + "_inac_data_" + file_id + ".csv"
np.savetxt(fn, inac_bin_map, delimiter=",", fmt='%f') np.savetxt(fn, inac_bin_map, delimiter=",", fmt='%f')
else: else:
fn = "map_layers\\" + name_list[i] + "_inac_data_" + file_id + ".csv" fn = "./map_layers/" + name_list[i] + "_inac_data_" + file_id + ".csv"
np.savetxt(fn, inac_bin_map, delimiter=",", fmt='%f') np.savetxt(fn, inac_bin_map, delimiter=",", fmt='%f')
...@@ -257,10 +257,10 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he ...@@ -257,10 +257,10 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he
viz_cnt = viz_cnt + 1 viz_cnt = viz_cnt + 1
if save_files: if save_files:
if save_to_folder: if save_to_folder:
fn = "map_layers\\" + case_name + "\\" + name_list[i]+"_data_"+file_id+".csv" fn = "./map_layers/" + case_name + "/" + name_list[i]+"_data_"+file_id+".csv"
np.savetxt(fn,bin_map,delimiter=",", fmt='%f') np.savetxt(fn,bin_map,delimiter=",", fmt='%f')
else: else:
fn = "map_layers\\" + name_list[i]+"_data_"+file_id+".csv" fn = "./map_layers/" + name_list[i]+"_data_"+file_id+".csv"
np.savetxt(fn,bin_map,delimiter=",", fmt='%f') np.savetxt(fn,bin_map,delimiter=",", fmt='%f')
...@@ -272,10 +272,10 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he ...@@ -272,10 +272,10 @@ def grab_features(anchor_point, extent, sample_dist = 10, case_name = 'blah', he
if save_files: if save_files:
if save_to_folder: if save_to_folder:
elv_filename = "map_layers\\" + case_name + "\\elv_data_" + file_id + ".csv" elv_filename = "./map_layers/" + case_name + "/elv_data_" + file_id + ".csv"
np.savetxt(elv_filename,e_interp,delimiter=",", fmt='%f') np.savetxt(elv_filename,e_interp,delimiter=",", fmt='%f')
else: else:
elv_filename = "map_layers\\elv_data_" + file_id + ".csv" elv_filename = "./map_layers/elv_data_" + file_id + ".csv"
np.savetxt(elv_filename,e_interp,delimiter=",", fmt='%f') np.savetxt(elv_filename,e_interp,delimiter=",", fmt='%f')
if plot_data: if plot_data:
...@@ -406,7 +406,8 @@ if __name__ == "__main__": ...@@ -406,7 +406,8 @@ if __name__ == "__main__":
# [48.64606, -122.4247,'[48.64606, -122.4247]'] # [48.64606, -122.4247,'[48.64606, -122.4247]']
] ]
base_dir = 'C:/Users/Larkin/ags_grabber' #You should be running this script from the base dir
base_dir = './'
# for item in ics: # for item in ics:
# try: # try:
...@@ -427,14 +428,14 @@ if __name__ == "__main__": ...@@ -427,14 +428,14 @@ if __name__ == "__main__":
anchor_point = [float(ics_pt[0]), float(ics_pt[1])] anchor_point = [float(ics_pt[0]), float(ics_pt[1])]
extent = 10e3 extent = 10e3
save_flag = True save_flag = True
plot_flag = False plot_flag = True
file_extension = 'temp' file_extension = 'temp'
sample_dist = int(extent/100) sample_dist = int(extent/100)
heading = 0 heading = 0
start_time = time.time() start_time = time.time()
grab_features(anchor_point = anchor_point, extent = extent, sample_dist = sample_dist, case_name = str(ics_pt[2]), grab_features(anchor_point = anchor_point, extent = extent, sample_dist = sample_dist, case_name = str(ics_pt[2]),
heading = heading, save_files = save_flag, save_to_folder = False, file_id = file_extension, plot_data = plot_flag) heading = heading, save_files = save_flag, save_to_folder = True, file_id = file_extension, plot_data = plot_flag)
time.sleep(1) # wait for... files to settle? time.sleep(1) # wait for... files to settle?
# run matlab # run matlab
...@@ -442,4 +443,4 @@ if __name__ == "__main__": ...@@ -442,4 +443,4 @@ if __name__ == "__main__":
res = eng.importmap_py(str(ics_pt[2]), base_dir) res = eng.importmap_py(str(ics_pt[2]), base_dir)
print("------- total time = {} seconds, iteration {}/{} ------".format(time.time() - start_time,i,len(ics))) print("------- total time = {} seconds, iteration {}/{} ------".format(time.time() - start_time,i,len(ics)))
eng.quit() eng.quit()
\ No newline at end of file
...@@ -46,6 +46,7 @@ def make_featmap(linfeat,savedir): ...@@ -46,6 +46,7 @@ def make_featmap(linfeat,savedir):
name = savedir + "kentland_features" name = savedir + "kentland_features"
#Convert to png format image #Convert to png format image
print(np.shape(linfeat))
feat_int8 = (linfeat*255).astype(np.uint8) feat_int8 = (linfeat*255).astype(np.uint8)
img = Image.fromarray(feat_int8) img = Image.fromarray(feat_int8)
img.save('./unity_data/kentland_features.png') img.save('./unity_data/kentland_features.png')
......
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