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

testing funtion to doren main class

parent 1d3080b4
......@@ -20,4 +20,4 @@ echo $SLURM_ARRAY_TASK_ID
# Run
cd /home/WUR/roelo008/projs/doren_2019
python run_species.py $SLURM_ARRAY_TASK_ID 50 doren_20201001.pkl
\ No newline at end of file
python run_species.py $SLURM_ARRAY_TASK_ID 50 doren_20201005.pkl
\ No newline at end of file
......@@ -20,6 +20,7 @@ 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_20201001.pkl'
with open(pkl_src, 'rb') as handle:
doren = pickle.load(handle)
......
......@@ -310,7 +310,7 @@ class Doren:
self.eva['totN_kg_ha'] = self.eva.loc[:, 'totN_mg_m2'].divide(100)
self.eva['totN_mol_ha'] = self.eva.loc[:, 'totN_kg_ha'].divide(14)
self.update_status()
self.update_status(covar=['totN_mg_m2', 'totN_kg_ha', 'totN_mol_ha'])
self.report += 'Added NDep from POSCH: {0} rows remaining.\n'.format(self.eva.shape[0])
def add_covar(self, covar_dir, covar_src, covar_name, nominal=False, keep_all=False, raster=True, **kwargs):
......@@ -716,7 +716,11 @@ class Doren:
self.species = set(self.spec.species_name_hdr)
self.status.update(n_plots=self.eva.shape[0], columns=self.eva.columns.tolist(), n_species=len(self.species))
if covar:
self.status['covars'] += covar
if not isinstance(covar, list):
covar_lst = [covar]
else:
covar_lst = covar
self.status['covars'] += covar_lst
def reset_species_sel(self):
# reset self.positive_plots and self.negative_plots
......@@ -742,26 +746,26 @@ class Doren:
self.report += 'Testing dataset integrity\n'
# Check for NAs
for check_col in self.status['covars'] + ['plot_id', 'country', 'year', 'veg_type', 'plot_coordinates_wgs84']:
for check_col in self.status['covars'] + ['plot_id', 'year', 'veg_type', 'plot_coordinates_wgs84']:
nas = self.eva.loc[:, check_col].isna()
if any(nas):
msg = '{0} NA values found for {1} (index: {2})\n'.format(len(nas), check_col, self.eva.loc[nas].index)
msg = '{0} -- {1} NA values found (index: {2})\n'.format(check_col, sum(nas), self.eva.loc[nas].index)
else:
msg = '{0} -- no missing data\n'.format(check_col)
self.report += msg
# Check for invalid vals
earliest_yr, latest_yr = self.eva.year.min(), self.eva.year.max()
self.report += 'Plot years are between {0}-{1}\n'.format(earliest_yr, latest_yr)
for check_col in [x for x in self.status['covars'] if not x.endswith('precip')]:
for check_col in [x for x in self.status['covars'] if not (x.endswith('precip') or
self.eva.loc[:, x].dtype.name == 'object')]:
sub_zeros = self.eva.loc[:, check_col] < 0
if any(sub_zeros):
msg = '{0} NA values found for {1} (index: {2})\n'.format(len(sub_zeros), check_col,
self.eva.loc[sub_zeros].index)
msg = '{0} values below 0 found for {1} (index: {2})\n'.format(sum(sub_zeros), check_col,
self.eva.loc[sub_zeros].index)
else:
msg = '{0} -- all values > 0\n'
msg = '{0} -- all values > 0\n'.format(check_col)
self.report += msg
if self.eva.index.difference(set(self.spec.plot_obs_id)).empty:
......
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