-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauncher.py
84 lines (72 loc) · 2.96 KB
/
launcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import pickle
import shutil
#
import osgeo
from shapely.geometry import Polygon
import geopandas as gpd
import yaml
from yaml.loader import SafeLoader
import sys
sys.path.insert(0, r".\Codes")
from Codes.functions import Tools
force=True
path_codes = './Codes'
path_work = os.getcwd()
path_inputs = './Inputs'
file_inputs = 'config.yaml'
inputs = yaml.load(open(os.path.join(path_inputs,file_inputs),'rb'),Loader = SafeLoader)
if not 'Projects' in os.listdir():
os.mkdir('Projects')
path_project = os.path.join('./Projects',inputs['Project'])
try :
os.mkdir(path_project)
print('Project '+inputs['Project']+' has been created in Projects')
except:
if force:
pass
else:
print('The project : '+inputs['Project']+' already exists, if you wanna continue put force=True in this script.')
raise
shutil.copy(os.path.join(path_inputs,'config.yaml'),os.path.join(path_project,'config.yaml'))
shutil.copy(os.path.join(path_codes,'template_postprocess.py'),os.path.join(path_project,'postprocess.py'))
shutil.copy('job_check.py',os.path.join(path_project,'job_check.py'))
shutil.copy('job_post.slurm',os.path.join(path_project,'job_post.slurm'))
if inputs['NatureROI']=='Transects':
if inputs['CreateTransects']:
Tools.createTransects(inputs,os.getcwd())
transects = pickle.load(open(os.path.join('./DataExample',inputs['NewPathTransect']),'rb'))
else:
transects = pickle.load(open(os.path.join('./DataExample',inputs['PathTransect']),'rb'))
ROIs,TRs = Tools.polyFromTransects(transects,d_ref = inputs['SizeROI'])
elif inputs['NatureROI']=='Polygon':
ROIs = [[inputs['ROI_array']]]
TRs=[[0]]
transects=TRs
if inputs['SaveShpROI']:
polygons = [Polygon(coords[0]) for coords in ROIs]
# gdf = gpd.GeoDataFrame(geometry=polygons,crs = 4326)
# gdf.to_file(os.path.join(path_project,'ROIs.shp'))
c=0
for i in ROIs:
TR_out = dict()
for j in TRs[c]:
TR_out[j] = transects[j]
# TR_out[j]['transect_proj'] = Tools.convert_epsg(TR_out[j]['transect'][:,::-1],4326,3857)[:,:2]
tmp = 'poly_'+str(c)
path_tmp = os.path.join(path_project,tmp)
if not(tmp in os.listdir(path_project)):
os.mkdir(path_tmp)
pickle.dump(i,open(os.path.join(path_tmp,'poly.json'),'wb'))
pickle.dump(TR_out,open(os.path.join(path_tmp,'transects.p'),'wb'))
shutil.copy(os.path.join(path_codes,'template_download.py'),os.path.join(path_tmp,'download.py'))
shutil.copy(os.path.join(path_codes,'template_main_process.py'),os.path.join(path_tmp,'main_process.py'))
shutil.copy('job.slurm',os.path.join(path_tmp,'job.slurm'))
# L=["python download.py \n", "python main_process.py \n"]
# job = open(os.path.join(path_tmp,"job.slurm"),"a")
# job.writelines(L)
# job.close()
os.chdir(path_tmp)
os.system('sbatch job.slurm')
os.chdir(path_work)
c+=1