From 11c9db3268d0a9ff00da80ae1415cfbf6e74c88a Mon Sep 17 00:00:00 2001 From: Hans Roelofsen <hans.roelofsen@wur.nl> Date: Wed, 14 Jul 2021 13:29:49 +0200 Subject: [PATCH] function to get dataframe snl beheertypen --- get_mnp_dk.py | 28 ++++++++++++++++++++++++++++ resources/datamanagement.rmd | 24 ++++++++++++++++++++++++ snl_beheertypen.py | 17 +++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 get_mnp_dk.py create mode 100644 resources/datamanagement.rmd create mode 100644 snl_beheertypen.py diff --git a/get_mnp_dk.py b/get_mnp_dk.py new file mode 100644 index 0000000..4fcaa5a --- /dev/null +++ b/get_mnp_dk.py @@ -0,0 +1,28 @@ +""" +Function to retrieve default MNP draagkracht for species/bt combination +""" + +import pandas as pd +import numpy as np + +# Get default mnp draagkracht values +mnp_dk_src = r'w:\PROJECTS\qmar\MNP-SNL-ParameterSet\Parameters_v06_2019_12_09\03_MNP_versie6_par_density_factors_BT2019_v2.csv' +mnp_dk = pd.read_csv(mnp_dk_src, sep=',',usecols=['Species_code', 'Land_type_code', 'Land_type_quality']) + + +def get_mnp_dk(species_code, bt_code, tab=mnp_dk): + """ + + :param species_code: MNP species code starting with S02, S06, S09 + :param bt_code: BT code NXX.YY.ZZ + :param tab: source table + :return: float draagrkacht + """ + + dk = mnp_dk.loc[(mnp_dk.Species_code == species_code) & (mnp_dk.Land_type_code == bt_code), 'Land_type_quality'] + if not dk.empty: + return float(dk) + else: + return np.nan + + diff --git a/resources/datamanagement.rmd b/resources/datamanagement.rmd new file mode 100644 index 0000000..0c78dfc --- /dev/null +++ b/resources/datamanagement.rmd @@ -0,0 +1,24 @@ +--- +title: "R Notebook" +author: roelo008 +date: 26-May-21 +output: html_notebook +--- + +The [R plugin](https://www.jetbrains.com/help/pycharm/r-plugin-support.html) for IntelliJ-based IDEs provides +handy capabilities to work with the [R Markdown](https://www.jetbrains.com/help/pycharm/r-markdown.html) files. +To [add](https://www.jetbrains.com/help/pycharm/r-markdown.html#add-code-chunk) a new R chunk, +position the caret at any line or the code chunk, then click "+". + +The code chunk appears: +```{r} +``` + +Type any R code in the chunk, for example: +```{r} +mycars <- within(mtcars, { cyl <- ordered(cyl) }) +mycars +``` + +Now, click the **Run** button on the chunk toolbar to [execute](https://www.jetbrains.com/help/pycharm/r-markdown.html#run-r-code) the chunk code. The result should be placed under the chunk. +Click the **Knit and Open Document** to built and preview an output. \ No newline at end of file diff --git a/snl_beheertypen.py b/snl_beheertypen.py new file mode 100644 index 0000000..9d1761e --- /dev/null +++ b/snl_beheertypen.py @@ -0,0 +1,17 @@ +""" +pandas dataframe containing .\resources\snl_beheertypen.csv +Hans Roelofsen, 14/07/2021 +""" + +import os +from pathlib import Path +import pandas as pd + +def get_snl_beheertypen_list(benb_dir): + """ + return snl beheertypen list as pandas df + :param benb_dir: directory of benb_utils + :return: pandas dataframe + """ + os.chdir(benb_dir) + return pd.read_csv(r'./resources/snl_beheertypen.csv', sep=',', comment='#', quotechar='"') \ No newline at end of file -- GitLab