mplStrater 0.0.5__tar.gz → 0.0.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mplstrater-0.0.7/PKG-INFO +74 -0
- mplstrater-0.0.7/README.md +52 -0
- {mplStrater-0.0.5 → mplstrater-0.0.7}/mplStrater/__init__.py +87 -88
- mplstrater-0.0.7/mplStrater/data.py +100 -0
- {mplStrater-0.0.5 → mplstrater-0.0.7}/mplStrater/strata.py +140 -129
- mplstrater-0.0.7/mplStrater.egg-info/PKG-INFO +74 -0
- {mplStrater-0.0.5 → mplstrater-0.0.7}/mplStrater.egg-info/SOURCES.txt +4 -2
- mplstrater-0.0.7/mplStrater.egg-info/requires.txt +6 -0
- mplstrater-0.0.7/pyproject.toml +54 -0
- mplstrater-0.0.7/tests/test_data.py +71 -0
- mplstrater-0.0.7/tests/test_strata.py +48 -0
- mplStrater-0.0.5/PKG-INFO +0 -66
- mplStrater-0.0.5/README.md +0 -41
- mplStrater-0.0.5/mplStrater/data.py +0 -92
- mplStrater-0.0.5/mplStrater.egg-info/PKG-INFO +0 -66
- mplStrater-0.0.5/mplStrater.egg-info/requires.txt +0 -18
- mplStrater-0.0.5/setup.py +0 -55
- {mplStrater-0.0.5 → mplstrater-0.0.7}/LICENSE +0 -0
- {mplStrater-0.0.5 → mplstrater-0.0.7}/mplStrater.egg-info/dependency_links.txt +0 -0
- {mplStrater-0.0.5 → mplstrater-0.0.7}/mplStrater.egg-info/top_level.txt +0 -0
- {mplStrater-0.0.5 → mplstrater-0.0.7}/setup.cfg +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mplStrater
|
|
3
|
+
Version: 0.0.7
|
|
4
|
+
Summary: plot geologic stratigraphic columns with python
|
|
5
|
+
Author-email: giocaizzi <giocaizzi@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Documentation, https://giocaizzi.github.io/mplStrater/
|
|
8
|
+
Project-URL: Bug Reports, https://github.com/giocaizzi/mplStrater/issues
|
|
9
|
+
Project-URL: Source, https://github.com/giocaizzi/mplStrater
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.11.5
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: geopandas
|
|
16
|
+
Requires-Dist: matplotlib
|
|
17
|
+
Requires-Dist: numpy>=1.17
|
|
18
|
+
Requires-Dist: pandas
|
|
19
|
+
Requires-Dist: rasterio
|
|
20
|
+
Requires-Dist: rio_color
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
<div align="center">
|
|
24
|
+
|
|
25
|
+
# mplStrater
|
|
26
|
+
|
|
27
|
+
**Geologic stratigraphic columns on matplotlib figures.**
|
|
28
|
+
|
|
29
|
+
[](https://pypi.org/project/mplStrater/)
|
|
30
|
+
[](https://pypi.org/project/mplStrater/)
|
|
31
|
+
[](https://github.com/giocaizzi/mplStrater/actions/workflows/ci.yml)
|
|
32
|
+
[](https://codecov.io/gh/giocaizzi/mplStrater)
|
|
33
|
+
[](https://giocaizzi.github.io/mplStrater/)
|
|
34
|
+
[](https://github.com/astral-sh/ruff)
|
|
35
|
+
[](LICENSE)
|
|
36
|
+
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
This package provides the possibility to plot geologic stratigraphic columns with a structured symbology and labelling system on `matplotlib` figures.
|
|
42
|
+
|
|
43
|
+
The package allows to use georeferenced rasters as basemap.
|
|
44
|
+
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
Additionally, the package has the capability to just plot the single stratigraphic columns.
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install mplStrater
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Documentation
|
|
58
|
+
|
|
59
|
+
Documentation with examples: [giocaizzi.github.io/mplStrater](https://giocaizzi.github.io/mplStrater/).
|
|
60
|
+
|
|
61
|
+
## Development
|
|
62
|
+
|
|
63
|
+
Requires [uv](https://docs.astral.sh/uv/).
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
git clone https://github.com/giocaizzi/mplStrater.git
|
|
67
|
+
cd mplStrater
|
|
68
|
+
uv sync
|
|
69
|
+
make check
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# mplStrater
|
|
4
|
+
|
|
5
|
+
**Geologic stratigraphic columns on matplotlib figures.**
|
|
6
|
+
|
|
7
|
+
[](https://pypi.org/project/mplStrater/)
|
|
8
|
+
[](https://pypi.org/project/mplStrater/)
|
|
9
|
+
[](https://github.com/giocaizzi/mplStrater/actions/workflows/ci.yml)
|
|
10
|
+
[](https://codecov.io/gh/giocaizzi/mplStrater)
|
|
11
|
+
[](https://giocaizzi.github.io/mplStrater/)
|
|
12
|
+
[](https://github.com/astral-sh/ruff)
|
|
13
|
+
[](LICENSE)
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
This package provides the possibility to plot geologic stratigraphic columns with a structured symbology and labelling system on `matplotlib` figures.
|
|
20
|
+
|
|
21
|
+
The package allows to use georeferenced rasters as basemap.
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
Additionally, the package has the capability to just plot the single stratigraphic columns.
|
|
26
|
+
|
|
27
|
+

|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install mplStrater
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Documentation
|
|
36
|
+
|
|
37
|
+
Documentation with examples: [giocaizzi.github.io/mplStrater](https://giocaizzi.github.io/mplStrater/).
|
|
38
|
+
|
|
39
|
+
## Development
|
|
40
|
+
|
|
41
|
+
Requires [uv](https://docs.astral.sh/uv/).
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
git clone https://github.com/giocaizzi/mplStrater.git
|
|
45
|
+
cd mplStrater
|
|
46
|
+
uv sync
|
|
47
|
+
make check
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
[MIT](LICENSE)
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
"""
|
|
2
|
+
mplStrater: plot stratigraphic columns with python.
|
|
3
|
+
"""
|
|
4
|
+
|
|
1
5
|
import matplotlib.pyplot as plt
|
|
2
|
-
import pandas as pd
|
|
3
|
-
import geopandas as gp
|
|
4
6
|
import numpy as np
|
|
5
|
-
import rasterio
|
|
7
|
+
import rasterio
|
|
6
8
|
from rasterio.plot import show
|
|
7
9
|
import rio_color.operations as rio
|
|
8
10
|
from rio_color.colorspace import ColorSpace as cs
|
|
9
11
|
from rio_color.colorspace import convert_arr
|
|
10
12
|
from mplStrater.strata import Column
|
|
11
13
|
import matplotlib.patheffects as pe
|
|
12
|
-
from matplotlib.gridspec import GridSpec
|
|
13
14
|
|
|
14
|
-
__version__="0.0.
|
|
15
|
+
__version__ = "0.0.7"
|
|
16
|
+
|
|
15
17
|
|
|
16
18
|
class StratigraphicMap:
|
|
17
19
|
"""
|
|
18
|
-
This
|
|
20
|
+
This is the stratigraphic map.
|
|
19
21
|
|
|
20
22
|
Arguments:
|
|
21
23
|
strataframe (:obj:`mplStrater.data.StrataFrame`): a StrataFrame object containing data to be plotted.
|
|
@@ -24,7 +26,7 @@ class StratigraphicMap:
|
|
|
24
26
|
|
|
25
27
|
Attributes:
|
|
26
28
|
strataframe (:obj:`mplStrater.data.StrataFrame`): the linked StrataFrame object
|
|
27
|
-
df (:obj:`pandas.DataFrame`): dataframe with stratigrafic information grouped by point.
|
|
29
|
+
df (:obj:`pandas.DataFrame`): dataframe with stratigrafic information grouped by point.
|
|
28
30
|
f (:obj:`matplotlib.Figure`): matplotlib figure with stratigraphic map
|
|
29
31
|
ax (:obj:`matplotlib.Axes`): matplotlib axes with stratigraphic map
|
|
30
32
|
fig_kwd (dict): keywords to pass to `matplotlib.pyplot.subplots()`
|
|
@@ -32,60 +34,55 @@ class StratigraphicMap:
|
|
|
32
34
|
img_alpha (:obj:`numpy.array`): 2D array of alpha channel
|
|
33
35
|
"""
|
|
34
36
|
|
|
35
|
-
def __init__(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
def __init__(
|
|
38
|
+
self, strataframe, basemap_path=None, fig_kwd=None, label_hardcoding=None
|
|
39
|
+
):
|
|
40
|
+
# strataframe
|
|
41
|
+
self.strataframe = strataframe
|
|
42
|
+
self.df = strataframe.strataframe
|
|
43
|
+
|
|
44
|
+
# handle label_hardcoding
|
|
45
|
+
self.label_hardcoding = label_hardcoding
|
|
46
|
+
|
|
47
|
+
# handle fig_kwd
|
|
44
48
|
if fig_kwd is None:
|
|
45
|
-
self.fig_kwd={
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
elif isinstance(fig_kwd,dict):
|
|
50
|
-
self.fig_kwd=fig_kwd
|
|
49
|
+
self.fig_kwd = {"figsize": (10, 10), "dpi": 300}
|
|
50
|
+
elif isinstance(fig_kwd, dict):
|
|
51
|
+
self.fig_kwd = fig_kwd
|
|
51
52
|
else:
|
|
52
53
|
raise ValueError("Incorrect fig_kwd argument. Must be None or dict.")
|
|
53
54
|
|
|
54
|
-
#handle basemap
|
|
55
|
-
if basemap_path is not None and isinstance(basemap_path,str):
|
|
55
|
+
# handle basemap
|
|
56
|
+
if basemap_path is not None and isinstance(basemap_path, str):
|
|
56
57
|
with rasterio.open(basemap_path) as basemap:
|
|
57
|
-
self.img_rgb=basemap.read((1,2,3))
|
|
58
|
-
self.img_alpha=basemap.read(4)
|
|
59
|
-
self.img_transform=basemap.transform
|
|
58
|
+
self.img_rgb = basemap.read((1, 2, 3))
|
|
59
|
+
self.img_alpha = basemap.read(4)
|
|
60
|
+
self.img_transform = basemap.transform
|
|
60
61
|
self.normalize_raster()
|
|
61
62
|
elif basemap_path is None:
|
|
62
|
-
self.img_rgb=None
|
|
63
|
-
self.img_alpha=None
|
|
63
|
+
self.img_rgb = None
|
|
64
|
+
self.img_alpha = None
|
|
64
65
|
else:
|
|
65
66
|
raise ValueError("Must specify string path to a georeferenced raster.")
|
|
66
|
-
|
|
67
|
-
def plot(self,legend):
|
|
67
|
+
|
|
68
|
+
def plot(self, legend):
|
|
68
69
|
"""
|
|
69
70
|
creates figure and plots the data.
|
|
70
71
|
"""
|
|
71
|
-
self.f,self.ax=plt.subplots(
|
|
72
|
-
1,
|
|
72
|
+
self.f, self.ax = plt.subplots(
|
|
73
|
+
1,
|
|
74
|
+
1,
|
|
73
75
|
figsize=self.fig_kwd["figsize"],
|
|
74
76
|
dpi=self.fig_kwd["dpi"],
|
|
75
77
|
)
|
|
76
78
|
self.ax.set_xticks([])
|
|
77
79
|
self.ax.set_yticks([])
|
|
78
|
-
self.ax.tick_params(
|
|
79
|
-
axis="both",
|
|
80
|
-
which="both",
|
|
81
|
-
left=False,
|
|
82
|
-
bottom=False
|
|
83
|
-
)
|
|
80
|
+
self.ax.tick_params(axis="both", which="both", left=False, bottom=False)
|
|
84
81
|
self.plot_basemap(self.ax)
|
|
85
82
|
self.plot_points(self.ax)
|
|
86
|
-
self.plot_strata_columns(legend=legend,ax=self.ax)
|
|
83
|
+
self.plot_strata_columns(legend=legend, ax=self.ax)
|
|
87
84
|
|
|
88
|
-
def plot_basemap(self,ax,color_correction=True):
|
|
85
|
+
def plot_basemap(self, ax, color_correction=True):
|
|
89
86
|
"""
|
|
90
87
|
sets basemap if this has been correctly specified.
|
|
91
88
|
|
|
@@ -94,37 +91,41 @@ class StratigraphicMap:
|
|
|
94
91
|
color_correction (bool): execute color correction with `rio-color` package.
|
|
95
92
|
|
|
96
93
|
"""
|
|
97
|
-
if
|
|
94
|
+
if (
|
|
95
|
+
self.img_alpha is not None
|
|
96
|
+
and self.img_rgb is not None
|
|
97
|
+
and self.img_transform is not None
|
|
98
|
+
):
|
|
98
99
|
if color_correction is True:
|
|
99
100
|
convert_arr(self.img_rgb, src=cs.rgb, dst=cs.lch)
|
|
100
|
-
self.img_rgb=rio.saturation(self.img_rgb, 0.5)
|
|
101
|
-
|
|
102
|
-
#ci riattacco alpha channel
|
|
103
|
-
desaturated=np.concatenate((self.img_rgb,self.img_alpha),axis=0)
|
|
101
|
+
self.img_rgb = rio.saturation(self.img_rgb, 0.5)
|
|
102
|
+
|
|
103
|
+
# ci riattacco alpha channel
|
|
104
|
+
desaturated = np.concatenate((self.img_rgb, self.img_alpha), axis=0)
|
|
104
105
|
|
|
105
|
-
#plotto
|
|
106
|
-
show(desaturated,transform=self.img_transform,ax=ax)
|
|
107
|
-
return
|
|
106
|
+
# plotto
|
|
107
|
+
show(desaturated, transform=self.img_transform, ax=ax)
|
|
108
|
+
return
|
|
108
109
|
|
|
109
110
|
def normalize_raster(self):
|
|
110
111
|
"""
|
|
111
112
|
Normalize content of georeferenced RGBA raster to to 0.0-1.0 format.
|
|
112
113
|
"""
|
|
113
|
-
r=self.img_rgb[0
|
|
114
|
-
g=self.img_rgb[1
|
|
115
|
-
b=self.img_rgb[2
|
|
114
|
+
r = self.img_rgb[0, :, :].copy()
|
|
115
|
+
g = self.img_rgb[1, :, :].copy()
|
|
116
|
+
b = self.img_rgb[2, :, :].copy()
|
|
116
117
|
|
|
117
|
-
r=(r-np.amin(r))/(np.amax(r)-np.amin(r))
|
|
118
|
-
g=(g-np.amin(g))/(np.amax(g)-np.amin(g))
|
|
119
|
-
b=(b-np.amin(b))/(np.amax(b)-np.amin(b))
|
|
118
|
+
r = (r - np.amin(r)) / (np.amax(r) - np.amin(r))
|
|
119
|
+
g = (g - np.amin(g)) / (np.amax(g) - np.amin(g))
|
|
120
|
+
b = (b - np.amin(b)) / (np.amax(b) - np.amin(b))
|
|
120
121
|
|
|
121
|
-
self.img_rgb=np.stack((r,g,b),axis=0)
|
|
122
|
+
self.img_rgb = np.stack((r, g, b), axis=0)
|
|
122
123
|
|
|
123
|
-
alpha=self.img_alpha.copy()
|
|
124
|
-
self.img_alpha=(alpha-np.amin(alpha))/(np.amax(alpha)-np.amin(alpha))
|
|
125
|
-
self.img_alpha=self.img_alpha[np.newaxis
|
|
124
|
+
alpha = self.img_alpha.copy()
|
|
125
|
+
self.img_alpha = (alpha - np.amin(alpha)) / (np.amax(alpha) - np.amin(alpha))
|
|
126
|
+
self.img_alpha = self.img_alpha[np.newaxis, :, :]
|
|
126
127
|
|
|
127
|
-
def plot_points(self,ax):
|
|
128
|
+
def plot_points(self, ax):
|
|
128
129
|
"""
|
|
129
130
|
plot points
|
|
130
131
|
|
|
@@ -132,8 +133,8 @@ class StratigraphicMap:
|
|
|
132
133
|
ax (:obj:`matplotlib.axes`) ax on which to plot the points.
|
|
133
134
|
"""
|
|
134
135
|
####punti
|
|
135
|
-
self.df.plot(ax=ax,color="black",markersize=8)
|
|
136
|
-
#labels
|
|
136
|
+
self.df.plot(ax=ax, color="black", markersize=8)
|
|
137
|
+
# labels
|
|
137
138
|
for x, y, label in zip(self.df.geometry.x, self.df.geometry.y, self.df.ID):
|
|
138
139
|
ax.annotate(
|
|
139
140
|
label,
|
|
@@ -142,13 +143,10 @@ class StratigraphicMap:
|
|
|
142
143
|
ha="right",
|
|
143
144
|
fontsize=5,
|
|
144
145
|
textcoords="offset points",
|
|
145
|
-
path_effects=[
|
|
146
|
-
|
|
147
|
-
linewidth=2,
|
|
148
|
-
foreground="white"
|
|
149
|
-
)])
|
|
146
|
+
path_effects=[pe.withStroke(linewidth=2, foreground="white")],
|
|
147
|
+
)
|
|
150
148
|
|
|
151
|
-
def savefig(self,path):
|
|
149
|
+
def savefig(self, path):
|
|
152
150
|
"""
|
|
153
151
|
save figure
|
|
154
152
|
|
|
@@ -157,33 +155,34 @@ class StratigraphicMap:
|
|
|
157
155
|
"""
|
|
158
156
|
return self.f.savefig(path)
|
|
159
157
|
|
|
160
|
-
def plot_strata_columns(self,legend,ax):
|
|
158
|
+
def plot_strata_columns(self, legend, ax):
|
|
161
159
|
"""
|
|
162
160
|
plot all stratigraphic columns in strataframe.
|
|
163
161
|
Arguments:
|
|
164
162
|
ax (:obj:`matplotlib.axes`) ax on which to plot the points.
|
|
165
163
|
"""
|
|
166
|
-
#stratigraphy columns
|
|
164
|
+
# stratigraphy columns
|
|
167
165
|
for i in range(len(self.df)):
|
|
168
|
-
c=Column(
|
|
169
|
-
#figure
|
|
170
|
-
ax,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
166
|
+
c = Column(
|
|
167
|
+
# figure
|
|
168
|
+
ax,
|
|
169
|
+
legend,
|
|
170
|
+
# id
|
|
171
|
+
self.df.loc[i, "ID"],
|
|
172
|
+
# coords
|
|
173
|
+
(self.df.loc[i, "x"], self.df.loc[i, "y"]),
|
|
174
|
+
# scale
|
|
175
|
+
self.df.loc[i, "scale"],
|
|
177
176
|
self.strataframe.max_depth,
|
|
178
|
-
#stratigraphic data
|
|
179
|
-
self.df.loc[i,"layers"],
|
|
180
|
-
self.df.loc[i,"fill_list"],
|
|
181
|
-
self.df.loc[i,"hatch_list"],
|
|
182
|
-
#labels
|
|
183
|
-
self.df.loc[i,"lbl1_list"],
|
|
184
|
-
self.df.loc[i,"lbl2_list"],
|
|
185
|
-
self.df.loc[i,"lbl3_list"]
|
|
177
|
+
# stratigraphic data
|
|
178
|
+
self.df.loc[i, "layers"],
|
|
179
|
+
self.df.loc[i, "fill_list"],
|
|
180
|
+
self.df.loc[i, "hatch_list"],
|
|
181
|
+
# labels
|
|
182
|
+
self.df.loc[i, "lbl1_list"],
|
|
183
|
+
self.df.loc[i, "lbl2_list"],
|
|
184
|
+
self.df.loc[i, "lbl3_list"],
|
|
185
|
+
)
|
|
186
186
|
c.fill_column()
|
|
187
187
|
c.set_inset_params()
|
|
188
188
|
c.label_column(hardcoding=self.label_hardcoding)
|
|
189
|
-
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import numpy as np
|
|
3
|
+
import geopandas as gp
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class StrataFrame:
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
StrataFrame is a `pandas.DataFrame` object with some added methods
|
|
10
|
+
functional to stratigraphic column plotting.
|
|
11
|
+
|
|
12
|
+
Arguments:
|
|
13
|
+
df (:obj:`pandas.DataFrame`): dataframe of stratigraphic data.
|
|
14
|
+
epsg (str) : EPSG code string of GeoDataFrame CRS
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, df=None, epsg=None):
|
|
19
|
+
|
|
20
|
+
# geodf
|
|
21
|
+
self.epsg = epsg
|
|
22
|
+
|
|
23
|
+
# handle path_to_data values
|
|
24
|
+
if df is not None and isinstance(df, pd.DataFrame):
|
|
25
|
+
self.df = df
|
|
26
|
+
self.set_df()
|
|
27
|
+
self.geodf()
|
|
28
|
+
else:
|
|
29
|
+
raise ValueError("Must provide a pandas dataframe with stratigraphic data.")
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
def set_df(self):
|
|
33
|
+
"""
|
|
34
|
+
process the dataframe to get the desired information to plot the data.
|
|
35
|
+
"""
|
|
36
|
+
profondita = self.group_layers(self.df)
|
|
37
|
+
matrici = self.group_data(self.df, "fill", "fill_list")
|
|
38
|
+
pericolosita = self.group_data(self.df, "hatch", "hatch_list")
|
|
39
|
+
destino = self.group_data(self.df, "lbl1", "lbl1_list")
|
|
40
|
+
amianto_qual = self.group_data(self.df, "lbl2", "lbl2_list")
|
|
41
|
+
amianto_quant = self.group_data(self.df, "lbl3", "lbl3_list")
|
|
42
|
+
|
|
43
|
+
# merged dfs
|
|
44
|
+
merged = pd.merge(matrici, profondita, on=["ID", "x", "y"])
|
|
45
|
+
merged = pd.merge(merged, pericolosita, on=["ID", "x", "y"])
|
|
46
|
+
merged = pd.merge(merged, destino, on=["ID", "x", "y"])
|
|
47
|
+
merged = pd.merge(merged, amianto_qual, on=["ID", "x", "y"])
|
|
48
|
+
merged = pd.merge(merged, amianto_quant, on=["ID", "x", "y"])
|
|
49
|
+
|
|
50
|
+
# scale and max depth
|
|
51
|
+
merged["scale"] = merged.layers.apply(max)
|
|
52
|
+
self.max_depth = merged.scale.max()
|
|
53
|
+
# store output
|
|
54
|
+
self.strataframe = merged
|
|
55
|
+
|
|
56
|
+
def geodf(self):
|
|
57
|
+
"""
|
|
58
|
+
Sets the strataframe as GeoDataFrame of the given Coordinate Reference System (crs).
|
|
59
|
+
"""
|
|
60
|
+
self.strataframe = gp.GeoDataFrame(
|
|
61
|
+
self.strataframe,
|
|
62
|
+
geometry=gp.points_from_xy(self.strataframe.x, self.strataframe.y),
|
|
63
|
+
)
|
|
64
|
+
self.strataframe = self.strataframe.set_crs(epsg=self.epsg)
|
|
65
|
+
|
|
66
|
+
@staticmethod
|
|
67
|
+
def group_layers(df):
|
|
68
|
+
"""
|
|
69
|
+
group layers in required format.
|
|
70
|
+
|
|
71
|
+
Arguments:
|
|
72
|
+
df (:obj:`pandas.DataFrame`): dataframe of stratigraphic data.
|
|
73
|
+
"""
|
|
74
|
+
profondita = df.groupby(["ID", "x", "y"])[["from", "to"]].agg(list)
|
|
75
|
+
profondita["layers"] = profondita["from"] + profondita["to"]
|
|
76
|
+
profondita = profondita.drop(["from", "to"], axis=1)
|
|
77
|
+
profondita["layers"] = profondita["layers"].apply(lambda x: np.unique(x))
|
|
78
|
+
return profondita
|
|
79
|
+
|
|
80
|
+
@staticmethod
|
|
81
|
+
def group_data(df, colname1, colname2):
|
|
82
|
+
"""
|
|
83
|
+
group data in required format.
|
|
84
|
+
|
|
85
|
+
Arguments:
|
|
86
|
+
df (:obj:`pandas.DataFrame`): dataframe of stratigraphic data.
|
|
87
|
+
colname1,colname2 (str, :obj:`list` of :obj:`str`): column names for `pandas.groupBy`
|
|
88
|
+
"""
|
|
89
|
+
# df con lista data
|
|
90
|
+
data = (
|
|
91
|
+
df.groupby(["ID", "x", "y"])[colname1]
|
|
92
|
+
.apply(list)
|
|
93
|
+
.reset_index(name=colname2)
|
|
94
|
+
)
|
|
95
|
+
# duplicazione ultimo elemento per pareggiare i conti
|
|
96
|
+
for i in range(len(data)):
|
|
97
|
+
temp = data.loc[i, colname2]
|
|
98
|
+
temp.append(temp[-1])
|
|
99
|
+
data.at[i, colname2] = temp
|
|
100
|
+
return data
|