Commit 38b2912d authored by Roelofsen, Hans's avatar Roelofsen, Hans
Browse files

non-ascii char rm from filename

parent 37e7b8ba
......@@ -22,7 +22,7 @@ sp_req_src = r'c:\Users\roelo008\Wageningen University & Research\DOREN - Genera
sp_req_sheet, column = 'PGO-1', 'newsoort'
# sp_req_src = r'c:\Users\roelo008\Wageningen University & Research\DOREN - General\2020-09-17 uniek soorten per habitat (2).xlsx'
testing = False
testing = True
doren = dc.Doren(header_src=param_header_src, sp_src=param_sp_src)
doren.initiate(sample=testing)
......@@ -38,6 +38,14 @@ doren.add_posch(posch_src_dir=param_posch)
doren.get_requested_species(xls=sp_req_src, sheet=sp_req_sheet, col=column, simplify_names=False)
doren.test()
sp = 'Holcus lanatus'
doren.select_plts_w_species(species_name=sp)
for structuurtype in doren.structuurtypes:
doren.nearest_positive_queryd(col='structuurtype', val=structuurtype)
doren.get_bedekking_selected_sp()
doren.write_stuff('plot_covars_file')
doren.write_stuff('species_single_file')
doren.write_stuff('species_list')
doren.write_stuff('typische_soorten')
doren.write_stuff('report')
......
......@@ -11,7 +11,6 @@ import datetime
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import shapely
import random
from utils import doren as do
......@@ -45,6 +44,7 @@ class Doren:
self.sel_sp_coverage = None # Series of coverage of selected species in the positive plots
self.buffer_gdf = None # holder for geodataframe w. buffers
self.sel_species = None # holder for a species
self.sel_species_ascii = None # holder for a species name with ascci encondig
self.buffer_size = None # holder for buffer size
self.structuurtypes = None # holder for list of structuurtypes. Must be list, not set, for ordering!
self.sample = False # Dataset is a random sample of all plots, for testing purposes.
......@@ -101,8 +101,9 @@ class Doren:
self.weird_species = sp_series.loc[~sp_check]
# Read EVA Header data
# header_src = r"W:\PROJECTS\Doren19\a_brondata\EVA\delivery_20201118\EVA_Doren_header.csv"
eva = pd.read_csv(self.header_src, comment='#', sep=',', low_memory=False,
memory_map=True,
memory_map=True, quotechar='"',
usecols=['PlotObservationID', 'TV2 relevé number', 'Country','Longitude', 'Latitude',
'Date of recording', 'Dataset', 'EUNIS_Old', 'EUNIS_New'])
try:
......@@ -121,6 +122,10 @@ class Doren:
eva['plot_point_wgs84'] = [shapely.geometry.Point(x, y) for (x, y) in eva.plot_coordinates_wgs84]
eva['plot_coordinates_3035'] = eva.plot_coordinates_wgs84.apply(do.lon_lat_2_east_north)
# Replace "," in composite EUNIS codes
eva.eunis_old = eva.eunis_old.str.replace(',', '-')
eva.eunis_new = eva.eunis_new.str.replace(',', '-')
# Assign final EUNIS code using EUNIS_new where possible else EUNIS_old
use_old_indx = eva.loc[(eva.eunis_new.isna()) | (eva.eunis_new == '?') | (eva.eunis_new == 'I')].index
use_new_indx = eva.index.difference(use_old_indx)
......@@ -128,7 +133,7 @@ class Doren:
eva.loc[use_old_indx, 'eunis_code'] = eva.loc[use_old_indx, 'eunis_old']
eva.loc[use_new_indx, 'eunis_src'] = 'eunis_new'
eva.loc[use_old_indx, 'eunis_src'] = 'eunis_old'
eva.eunis_code.fillna('?') # Fill NAs where EUNIS_Old was also NA
eva.eunis_code.fillna('?', inplace=True) # Fill NAs where EUNIS_Old was also NA
# Attach as attribute
self.eva = gp.GeoDataFrame(eva, geometry='plot_coordinates_3035', crs={"init": "epsg:3035"})
......@@ -543,6 +548,7 @@ class Doren:
"""header data of plots containing the species"""
self.sel_species = species_name
self.sel_species_ascii = self.sel_species.replace('ë', 'e').encode('ascii', 'replace')
self.positive_plots = set(self.spec.plot_obs_id[self.spec.species_name_hdr == species_name])
self.negative_plots = self.eva.index.difference(self.positive_plots)
......@@ -789,7 +795,8 @@ class Doren:
return None
# Dedicated directory for the PG output and output filename
pg_out_name = '{0}_NDep_Nearest'.format(self.sel_species.replace(' ', '_'))
# TODO: replace non-ascii characters
pg_out_name = '{0}_NDep_Nearest'.format(self.sel_species_ascii)
pg_dir = os.path.join(out_dir, 'pg_input')
if not os.path.isdir(pg_dir):
os.mkdir(pg_dir)
......
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