Commit ed39744a authored by Roelofsen, Hans's avatar Roelofsen, Hans
Browse files

adding method to merge EUNIS types

parent 7052db49
......@@ -2,12 +2,14 @@
import os
import pickle
from utils import doren_classes as dc
# os.environ['GDAL_DATA'] = r'C:\Users\roelo008\Miniconda3\envs\doren\Library\share\gdal'
param_header_src = r'c:\Users\roelo008\OneDrive - WageningenUR\a_projects\DOREN\a_brondata\EVA\EVA_Doren_header.csv'
param_sp_src = r'c:\Users\roelo008\OneDrive - WageningenUR\a_projects\DOREN\a_brondata\EVA\EVA_Doren_species.csv'
param_aoi_src = r'c:\Users\roelo008\OneDrive - WageningenUR\a_projects\DOREN\geodata\AOI\ne_50m_cntrs_AOI_diss_fin.shp'
param_dem_src = r'c:\Users\roelo008\OneDrive - WageningenUR\a_projects\DOREN\a_brondata\covariables\DEM\DTM_3035.tif'
param_posch = r'c:\Users\roelo008\OneDrive - WageningenUR\a_projects\DOREN\a_brondata\POSCH_dep\v2'
param_posch = r'W:\PROJECTS\Doren19\a_brondata\POSCH_dep\20201012delivery'
cv_soil_dir = r'c:\Users\roelo008\OneDrive - WageningenUR\a_projects\DOREN\a_brondata\covariables\soil\b_processed'
cv_soil_src = 'WRBLEV1_laea.tif'
cv_cntr_dir = r'c:\Users\roelo008\OneDrive - WageningenUR\a_projects\DOREN\geodata\countries'
......@@ -17,17 +19,24 @@ cv_precp_src = "EObs_v200e_rr_5yrmean"
cv_temp_dir = r'c:\Users\roelo008\OneDrive - WageningenUR\a_projects\DOREN\a_brondata\covariables\EObs\2_compiled'
cv_temp_src = "EObs_v200e_tg_5yrmean"
sp_req_src = r'c:\Users\roelo008\Wageningen University & Research\DOREN - General\2020-09-17 uniek soorten per habitat.xlsx'
sp_req_sheet, col = 'PGO-1', 'newsoort'
# sp_req_src = r'c:\Users\roelo008\Wageningen University & Research\DOREN - General\2020-09-17 uniek soorten per habitat (2).xlsx'
eunis_plot_source = r'w:\PROJECTS\Doren19\a_brondata\covariables\EUNIS\levering_20201110\EVA_Doren_header.txt'
testing = False
doren = dc.Doren(header_src=param_header_src, sp_src=param_sp_src)
doren.initiate(sample=False)
doren.apply_requirements('req1', 'req2', 'req3', 'req4', 'req8', 'req9', 'req10', aoi_src=param_aoi_src,
dem_src=param_dem_src)
doren.initiate(sample=testing)
doren.apply_requirements('req1', 'req2', 'req3', 'req4', 'req8', 'req9', 'req10',
aoi_src=None if testing else param_aoi_src, dem_src=param_dem_src)
doren.add_covar(covar_dir=cv_cntr_dir, covar_src=cv_cntr_src, covar_name='country', raster=False, column='SOV_A3')
doren.add_posch(posch_src_dir=param_posch)
doren.add_covar(covar_dir=cv_soil_dir, covar_src=cv_soil_src, covar_name='soil_type', nominal=True)
doren.add_yearly_covar(covar_dir=cv_precp_dir, covar_src_basename=cv_precp_src, covar_name='five_yearly_precip')
doren.add_yearly_covar(covar_dir=cv_temp_dir, covar_src_basename=cv_temp_src, covar_name='five_yearly_temp')
doren.get_requested_species(xls=sp_req_src, sheet='PGO-1', col='newsoort', simplify_names=False)
doren.add_eunis(eunis_plot_src=eunis_plot_source)
doren.add_posch(posch_src_dir=param_posch)
doren.get_requested_species(xls=sp_req_src, sheet=sp_req_sheet, col=col, simplify_names=False)
doren.test()
doren.write_stuff('species_list')
......@@ -51,4 +60,5 @@ post.initiate(sample=False, species_col='matched_concept')
post.select_plts_w_species('Sparganium natans')
print(post.eva.shape)
print(len(post.positive_plots))
'''
\ No newline at end of file
'''
......@@ -2,8 +2,6 @@
Script for taking a pre-existing DOREN pkl object and processing a subset of its requested species
Hans Roelofsen, 03 June 2020
"""
import os
import numpy as np
import argparse
import pickle
......@@ -14,30 +12,42 @@ parser.add_argument('n_batches', help='number of batches')
parser.add_argument('pkl', help='name of pkl source')
args = parser.parse_args()
batch_nr = int(args.batch_nr)
n_batches = int(args.n_batches)
# Recover the Pickled doren object
pkl_src = os.path.join('./pkl_src/', args.pkl)
#pkl_src = r'c:\Users\roelo008\OneDrive - WageningenUR\a_projects\DOREN\b_compiled_data\a_pkl\doren_20201005.pkl'
# pkl_src = os.path.join('./pkl_src/', args.pkl)
pkl_src = r'c:\Users\roelo008\OneDrive - WageningenUR\a_projects\DOREN\b_compiled_data\a_pkl\doren_20201118.pkl'
with open(pkl_src, 'rb') as handle:
doren = pickle.load(handle)
doren.base_out_dir = r'./c_out'
# doren.base_out_dir = r'./c_out'
# doren.req_sp = None
# sp_req_src = r'c:\Users\roelo008\Wageningen University & Research\DOREN - General\2020-09-17 uniek soorten per habitat (2).xlsx'
# doren.get_requested_species(xls=sp_req_src, sheet='Verdringingssoorten', col='wetenschappelijke naam', simplify_names=False)
structuurtypes = list(set(doren.eva.structuurtype))
# Determine subset of requested species to proces
sel = np.array_split(np.arange(0, len(doren.req_sp)), n_batches)[batch_nr].tolist()
print('Commencing processing of {0} species...'.format(len(sel)))
# Process subset of requested species
for i, j in enumerate(sel, start=1):
for i, j in enumerate(sel, start=0):
sp = doren.req_sp[j]
try:
print(' doing species {0} of {1}: {2}'.format(i, len(sel), sp))
print('Doing species {0} of {1}: {2}'.format(i, len(sel), sp))
doren.select_plts_w_species(species_name=sp)
doren.nearest_positive()
for structuurtype in structuurtypes:
doren.nearest_positive_of_type(col='structuurtype', val=structuurtype)
doren.get_bedekking_selected_sp()
doren.write_stuff('species_single_file')
if batch_nr == n_batches and i == len(sel):
# Write the covar file once
doren.write_stuff('plot_covars_file')
except OSError:
continue
doren.write_stuff('report')
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
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