Commit 3d1c3f13 authored by Roelofsen, Hans's avatar Roelofsen, Hans
Browse files

list potential matches for required not found species

parent c8a24feb
......@@ -20,6 +20,7 @@ sp_req_src = r'c:\Users\roelo008\OneDrive - WageningenUR\a_projects\DOREN\z_scra
doren = dc.Doren(header_src=param_header_src, sp_src=param_sp_src)
doren.initiate(sample=False)
# doren.rename(old_name='Oxycoccus palustris', new_name='Vaccinium oxycoccos')
doren.apply_requirements('req1', 'req2', 'req3', 'req4', 'req8', 'req9', 'req10', aoi_src=param_aoi_src,
dem_src=param_dem_src)
......
......@@ -4,8 +4,8 @@ Hans Roelofsen, 03 June 2020
"""
import numpy as np
import pickle
import argparse
import pickle
parser = argparse.ArgumentParser()
parser.add_argument('batch_nr', help='batch number')
......@@ -17,7 +17,8 @@ batch_nr = int(args.batch_nr)
n_batches = int(args.n_batches)
# Recover the Pickled doren object
pkl_src = './pkl_src/doren_20200812.pkl'
pkl_src = './pkl_src/doren_20200907.pkl'
# pkl_src = r'c:\Users\roelo008\OneDrive - WageningenUR\a_projects\DOREN\b_compiled_data\a_pkl\doren_20200903.pkl'
with open(pkl_src, 'rb') as handle:
doren = pickle.load(handle)
......
......@@ -54,6 +54,7 @@ class Doren:
self.req_sp = None # species requested for processing from external source
self.req_found = None # subset of req_sp found in self.species
self.req_not_found = None # subset of req_sp not found in self.species
self.req_not_found_df = None # dataframe with as above plus alternatives that are found
# base directory for all output
self.base_out_dir = r'c:\Users\roelo008\OneDrive - WageningenUR\a_projects\DOREN\z_scratch'
# source to shapefile with background images
......@@ -71,9 +72,9 @@ class Doren:
# Read EVA species data
species = pd.read_csv(self.sp_src, sep='\t', memory_map=True)
colnames_n = ['plot_obs_id', 'taxonomy', 'taxon_group', 'taxon_group_id', 'turboveg2_concept',
'matched_concept', 'match', 'layer', 'cover_perc', 'cover_code', 'species_name_hdr']
'matched_concept', 'match', 'layer', 'cover_perc', 'cover_code']
species.rename(columns=dict(zip(list(species), colnames_n)), inplace=True)
species['species_name_hdr'] = species.matched_concept.apply(do.strip_leading_quote)
species['species_name_hdr'] = species.matched_concept.astype(str).apply(do.strip_leading_quote)
species['species_name_hdr'] = species.species_name_hdr.apply(do.simplify_species)
self.spec = species
......@@ -145,9 +146,20 @@ class Doren:
self.req_found = self.species.intersection(req_sp_set)
self.req_not_found = req_sp_set.difference(self.species)
msg1 = '\nRead {0} species requested for processing, of which {1} match a species in EVA and {2} do ' \
'not:\n'.format(len(self.req_sp), len(self.req_found), len(self.req_not_found))
msg2 = '\n'.join(self.req_not_found)
# List alternatives
container = []
for sp in self.req_not_found:
alternatives = self.spec.loc[self.spec.turboveg2_concept == sp, 'matched_concept']
if not alternatives.empty:
dat = pd.Series(data={sp: list(set(alternatives))})
else:
dat = pd.Series(data={sp: 'no alternatives found'})
container.append(dat)
self.req_not_found_df = pd.concat(container)
msg1 = '\nRead {0} species requested for processing, of which {1} match a species in EVA ("matched_concept")and {2} do ' \
'not (matching "turboveg2_concepts" given in brackets: \n'.format(len(self.req_sp), len(self.req_found), len(self.req_not_found))
msg2 = self.req_not_found_df.sort_index().to_csv(sep='\t')
self.report += msg1 + msg2 + '\n'
if self.verbose:
print(msg1, msg2)
......@@ -166,13 +178,6 @@ class Doren:
post_count_old = self.spec.loc[self.spec.species_name_hdr == old_name].shape[0]
post_count_new = self.spec.loc[self.spec.species_name_hdr == new_name].shape[0]
# if (pre_count == post_count_new) and (post_count_old == 0):
# msg = ' replaced {0} occurences of {1} with {2}.\n'.format(pre_count, old_name, new_name)
# if self.verbose:
# print(msg)
# self.report += msg
# else:
# raise TypeError('Something went wrong with finding and replacing species name {0}'.format(old_name))
def apply_requirements(self, *reqs, **kwargs):
"""
......
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