Commit 8b814bc3 authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

adapt to new config.json

parent 1fec4420
import argparse
import json
from osmaug.combine.collosm_main import collosm_function
import random
import string
def get_random_alphanumeric_string(length):
letters_and_digits = string.ascii_letters + string.digits
result_str = ''.join((random.choice(letters_and_digits) for i in range(length)))
return(result_str.lower())
def main():
"""
Main collosm_function.
"""
parser = argparse.ArgumentParser(description="Argument parsing for combining osm pictures filename to dataset")
parser.add_argument("-c", help="Config")
args = parser.parse_args()
with open(args.c,encoding='utf8') as f:
parser.add_argument("-w", help="path of the workdir")
parser.add_argument("-c", help="json configuration file providing the whole set of parameter")
parser.add_argument("-s", help="json sessions file providing keys about outcomes from aqdl modules")
if not os.path.exists(args.w):
raise ValueError("path "+args.w+" does not exist")
with open(os.path.join(args.w, "config",args.c),encoding='utf8') as f:
collosm_config = json.load(f)
collosm_function(augmosm_config)
with open(os.path.join(args.w, "config",args.s),encoding='utf8') as f:
get_session_config = json.load(f)
key = get_random_alphanumeric_string(20)
collosm_config['sessiondir'] = os.path.join(args.w,"session",key)
collosm_config["tabdir"] = os.path.join(args.w,'session',get_session_config['aqmet'])
collosm_config["tiledir"] = os.path.join(args.w,'session',get_session_config['osmaug_getosm'])
collosm_function(collosm_config)
print("Combining OSM pictures augmentation to dataset completed.")
#save updated sessions file
get_session_config['osmaug_collosm']=key
with open(os.path.join(args.w, "config",args.s), 'w',encoding='utf8') as f_sessions:
json.dump(get_session_config, f_sessions)
if __name__ == "__main__":
main()
......@@ -9,19 +9,20 @@ from osmaug.dictionnary.dictionnary_tf import augm_param_dict,augm_dict
from osmaug.transformation.crop import crop
def collosm_function(params: Dict):
workdir = os.path.join(params['workdir'])
resdir = os.path.join(params['resdir'])
tiledir = os.path.join(params['tiledir'],'tile')
tabdir = os.path.join(params['tabdir'],'tab')
resdir = os.path.join(params['sessiondir'])
res_data_dir = os.path.join(resdir,'tab')
res_img_dir = os.path.join(resdir,'img')
if not os.path.exists(resdir):
os.mkdir(resdir)
df = pd.read_csv(params['file']['name'],sep=',')
df = pd.read_csv(os.path.join(tabdir,'dataset.csv'),sep=',')
df['ID'] = df['ID'].apply(str)
tile = pd.DataFrame.from_dict(params['tile'], orient='columns')
# getting the dimension of each tile. Assuming all tiles get identical dimensions
filename = df.loc[0,'ID']+'_'+tile.loc[0,'name']+'_zoom_'+tile.loc[0,'zoom']+'.jpg'
img = img_as_float(io.imread(os.path.join(workdir,filename)))
img = img_as_float(io.imread(os.path.join(tiledir,filename)))
img_shape = img.shape
res = pd.DataFrame()
......@@ -34,7 +35,7 @@ def collosm_function(params: Dict):
for index_tile, row_tile in tile.iterrows():
filename = row['ID']+'_'+row_tile['name']+'_zoom_'+row_tile['zoom']+'.jpg'
print(filename)
img = img_as_float(io.imread(os.path.join(workdir,filename)))
img = img_as_float(io.imread(os.path.join(tiledir,filename)))
img = augm(img,augm_matrix)
img = crop(img, delta=params['augmentation']['delta_pixel'])
filename_aug = id_augm+'_'+filename
......
import argparse
import json
from osmaug.osm.getosm_main import getosm_main
import random
import string
def get_random_alphanumeric_string(length):
letters_and_digits = string.ascii_letters + string.digits
result_str = ''.join((random.choice(letters_and_digits) for i in range(length)))
return(result_str.lower())
def main():
"""
Main get_osm_rgb function.
"""
parser = argparse.ArgumentParser(description="Argument parsing for getting osm pictures")
parser.add_argument("-c", help="Config")
args = parser.parse_args()
with open(args.c,encoding='utf8') as f:
parser = argparse.ArgumentParser(description="Argument parsing for combining osm pictures filename to dataset")
parser.add_argument("-w", help="path of the workdir")
parser.add_argument("-c", help="json configuration file providing the whole set of parameter")
parser.add_argument("-s", help="json sessions file providing keys about outcomes from aqdl modules")
if not os.path.exists(args.w):
raise ValueError("path "+args.w+" does not exist")
with open(os.path.join(args.w, "config",args.c),encoding='utf8') as f:
getosm_config = json.load(f)
with open(os.path.join(args.w, "config",args.s),encoding='utf8') as f:
get_session_config = json.load(f)
# create a new session for results
key = get_random_alphanumeric_string(20)
getosm_config['sessiondir'] = os.path.join(args.w,"session",key)
getosm_function(getosm_config)
print("Getting OSM as RGB picture completed.")
#save updated sessions file
get_session_config['osmaug_getosm']=key
with open(os.path.join(args.w, "config",args.s), 'w',encoding='utf8') as f_sessions:
json.dump(get_session_config, f_sessions)
if __name__ == "__main__":
main()
......@@ -4,23 +4,25 @@ import os
from osmaug.osm.map import map_wms_source, make_bbox, load_map, map2png, png2jpg
def getosm_function(params: Dict):
sessiondir = os.path.join(params['sessiondir'])
driver_bin = params['driver_bin']
zoom = params['zoom']
source = params['source']
if source['type'] == "wms":
wms_source = map_wms_source(source['url'],source['layers'],source['styles'],source['fmt'],source['transparent'],source['cql_filter'])
else:
wms_source = None
resdir = os.path.join(params['resdir'])
resdir = os.path.join(sessiondir,"tile")
if not os.path.exists(resdir):
os.mkdir(resdir)
points = pd.DataFrame.from_dict(params['points'], orient='columns')
for index, row in points.iterrows():
print("-> "+row['ID'])
tmp = make_bbox(row['coords'],row['conv_crs'],row['delta_meters'])
file = os.path.join(resdir,str(row['ID'])+'_'+str(source['name'])+'_zoom_'+str(zoom)+'.html')
load_map(tmp,wms_source,zoom,file)
tmp_png = map2png(file, 5, driver_bin)
tmp_jpg = png2jpg(tmp_png)
os.remove(file)
os.remove(tmp_png)
sources = pd.DataFrame.from_dict(params['source'], orient='columns')
for i, src in sources.iterrows();
print("**---> "+ src['name'])
if src['type'] == "wms":
wms_source = map_wms_source(src['url'],src['layers'],src['styles'],src['fmt'],src['transparent'],src['cql_filter'])
else:
wms_source = None
for index, row in points.iterrows():
print("-> "+row['ID'])
tmp = make_bbox(row['coords'],row['conv_crs'],row['delta_meters'])
file = os.path.join(resdir,str(row['ID'])+'_'+str(src['name'])+'_zoom_'+str(src['zoom'])+'.html')
load_map(tmp,wms_source,zoom,file)
tmp_png = map2png(file, 5, driver_bin)
tmp_jpg = png2jpg(tmp_png)
os.remove(file)
os.remove(tmp_png)
Supports Markdown
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