Skip to content
Snippets Groups Projects
Commit b0fefd04 authored by Wit, Allard de's avatar Wit, Allard de
Browse files

Fixed a few problems in the grompy.DataAccessProvider

bumped to version 1.1.1
parent b040846d
No related branches found
No related tags found
No related merge requests found
......@@ -7,4 +7,4 @@ from .dap import DataAccessProvider
from .cmd import cli
__version__ = "1.1.0"
\ No newline at end of file
__version__ = "1.1.1"
\ No newline at end of file
......@@ -36,7 +36,7 @@ class DataAccessProvider:
self.datasets_enabled = set(self.datasets)
# Build connection to parcel info
self.engine = sa.create_engine(self.parcel_dsn)
self.engine = open_DB_connection(grompy_yaml, self.parcel_dsn)
meta = sa.MetaData(self.engine)
self.tbl_perc_info = sa.Table(self.parcel_table, meta, autoload=True)
self.limit = int(1e9) if limit is None else limit
......@@ -68,7 +68,7 @@ class DataAccessProvider:
"""Enables a dataset for reading with grompy..
"""
if dataset in self.datasets:
self.datasets_enabled.update(dataset)
self.datasets_enabled.add(dataset)
else:
print(f"'{dataset}' unknown, should be one of: {self.datasets}")
......
%% Cell type:markdown id: tags:
# Accessing GroenMonitor data with GroMPy
%% Cell type:code id: tags:
``` python
import os, sys
import time
from pathlib import Path
import pandas as pd
import matplotlib.style
matplotlib.style.use("ggplot")
import matplotlib.pyplot as plt
sys.path.append(r"E:\CRUCIAL\source\grompy")
import grompy
```
%% Cell type:code id: tags:
``` python
perc2019 = Path(r"F:\data\groenmonitor") / "sentinel2_observations_2019.db3"
dsn = f"sqlite:///{perc2019}"
dap = grompy.DataAccessProvider(dsn=dsn)
len(dap)
```
%% Output
772563
%% Cell type:code id: tags:
``` python
dap = grompy.DataAccessProvider(dsn=dsn, gws_gewasc=256)
len(dap)
```
%% Output
15800
%% Cell type:code id: tags:
``` python
dap = grompy.DataAccessProvider(dsn=dsn, gws_gewasc=256, area_gt=10)
len(dap)
```
%% Output
1467
%% Cell type:code id: tags:
``` python
dap = grompy.DataAccessProvider(dsn=dsn, gws_gewasc=256, area_gt=10, provincie="Flevoland")
len(dap)
```
%% Output
212
%% Cell type:code id: tags:
``` python
dap = grompy.DataAccessProvider(dsn=dsn, gws_gewasc=256, area_gt=10, provincie="Flevoland", limit=9)
len(dap)
```
%% Output
212
%% Cell type:code id: tags:
``` python
fig, axes = plt.subplots(nrows=3, ncols=3, figsize=(15,15), sharex=True)
axes = axes.flatten()
for i, (perc_info, df) in enumerate(dap):
axes[i].plot_date(df.index, df.NDVI, linestyle="-", marker="o", color="seagreen")
axes[i].set_title(perc_info.fieldID)
fig.autofmt_xdate()
```
%% Output
C:\Miniconda3\envs\py3_crucial\lib\site-packages\pandas\plotting\_matplotlib\converter.py:103: FutureWarning: Using an implicitly registered datetime converter for a matplotlib plotting method. The converter was registered by pandas on import. Future versions of pandas will require you to explicitly register matplotlib converters.
To register the converters:
>>> from pandas.plotting import register_matplotlib_converters
>>> register_matplotlib_converters()
warnings.warn(msg, FutureWarning)
%% Cell type:code id: tags:
``` python
df.head()
```
%% Output
day B02 B03 B04 B05 B06 B07 B08 \
day
2019-01-18 2019-01-18 430.0 423.0 541.0 653.0 694.0 736.0 821.0
2019-01-21 2019-01-21 487.0 564.0 759.0 887.0 932.0 988.0 1104.0
2019-02-15 2019-02-15 412.0 638.0 825.0 936.0 986.0 1045.0 1170.0
2019-02-25 2019-02-25 878.0 1202.0 1492.0 1677.0 1746.0 1829.0 2004.0
2019-02-27 2019-02-27 1061.0 1378.0 1661.0 1870.0 1933.0 2018.0 2191.0
B11 B12 B8A NDVI
day
2019-01-18 788.0 609.0 789.0 0.2040
2019-01-21 1260.0 1069.0 1086.0 0.1801
2019-02-15 1462.0 1244.0 1147.0 0.1729
2019-02-25 2650.0 2618.0 1957.0 0.1460
2019-02-27 3012.0 3039.0 2144.0 0.1363
%% Cell type:code id: tags:
``` python
dap = grompy.DataAccessProvider(dsn=dsn, gws_gewasc=265, area_gt=10, provincie="Friesland")
len(dap)
```
%% Output
403
%% Cell type:code id: tags:
``` python
t1 = time.time()
for perc_info, df in dap:
pass
elapsed = time.time() - t1
print(f"Accessing {len(dap)} parcels took {elapsed/len(dap):6.1} seconds per parcel.")
```
%% Output
Accessing 403 parcels took 0.006 seconds per parcel.
%% Cell type:code id: tags:
``` python
from pylab import *
```
%% Cell type:code id: tags:
``` python
plot((df.B08-df.B04)/(df.B08+df.B04), marker="o")
```
%% Output
[<matplotlib.lines.Line2D at 0x41b3943860>]
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment