edmt 1.0.1.dev0__py3-none-any.whl

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.
@@ -0,0 +1,207 @@
1
+ import geopandas as gpd
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import contextily as cx
5
+ from pyproj import CRS
6
+
7
+ from edmt.contrib.utils import clean_vars
8
+
9
+ class Mapping:
10
+ def __init__(self):
11
+ # Initialize any necessary attributes
12
+ pass
13
+
14
+ # @staticmethod
15
+ # def gplot(df, column=None, title=None, legend=True, fill=None, grids=None, **additional_args):
16
+ # df = df.copy()
17
+ # df = df.to_crs(epsg=4326)
18
+
19
+ # ax = plt.subplots(figsize=(10, 10))
20
+ # plot_args = {
21
+ # "ax": ax,
22
+ # "alpha": 0.6,
23
+ # "edgecolor": "black",
24
+ # "column": column,
25
+ # "legend": legend,
26
+ # "legend_kwds": {
27
+ # "loc": "lower right",
28
+ # "bbox_to_anchor": (1, 0),
29
+ # "frameon": True,
30
+ # "title": column,
31
+ # },
32
+ # "facecolor": fill,
33
+ # }
34
+ # plot_args = clean_vars(additional_args, **plot_args)
35
+ # df.plot(**plot_args)
36
+ # cx.add_basemap(ax, crs=df.crs, source=cx.providers.OpenStreetMap.Mapnik)
37
+ # return ax
38
+
39
+ # class Mapping:
40
+
41
+ # def __init__(self):
42
+ # # Initialize any necessary attributes
43
+ # pass
44
+
45
+ # @staticmethod
46
+ # def gplot(df, column=None, title=None, ax=None, legend=True, fill=None,grids=None, **additional_args):
47
+ # # print(f"Plot started at: {datetime.now()}")
48
+ # # start_time = time.time()
49
+
50
+ # df = df.copy()
51
+ # df = df.to_crs(epsg=4326) # Ensure WGS 84
52
+
53
+ # # Create plot
54
+ # if ax is None:
55
+ # _, ax = plt.subplots(figsize=(10, 10))
56
+
57
+ # # Default plot arguments
58
+ # plot_args = {
59
+ # "ax": ax,
60
+ # "alpha": 0.6,
61
+ # "edgecolor": "black",
62
+ # "column": column,
63
+ # "legend": legend,
64
+ # "legend_kwds": {
65
+ # "loc": "lower right",
66
+ # "bbox_to_anchor": (1, 0),
67
+ # "frameon": True,
68
+ # "title": column,
69
+ # },
70
+ # "facecolor" : fill
71
+ # }
72
+
73
+ # # Title
74
+ # if title:
75
+ # ax.set_title(title, fontsize=14)
76
+
77
+ # # Add grids
78
+ # if grids:
79
+ # ax.grid(visible=True, linestyle="--", linewidth=0.5, alpha=0.7)
80
+
81
+ # # Clean and merge additional arguments
82
+ # plot_args = clean_vars(additional_args, **plot_args)
83
+
84
+ # # Plot the GeoDataFrame
85
+ # df.plot(**plot_args)
86
+
87
+ # # Add a frame around the map
88
+ # for spine in ax.spines.values():
89
+ # spine.set_edgecolor("black")
90
+ # spine.set_linewidth(1.5)
91
+
92
+ # # Add basemap
93
+ # cx.add_basemap(ax, crs=df.crs, source=cx.providers.OpenStreetMap.Mapnik)
94
+
95
+ # # end_time = time.time()
96
+ # # execution_time = end_time - start_time
97
+ # # print(f"Execution time: {execution_time:.2f} seconds.")
98
+ # return ax
99
+
100
+ # # def gplot(df, column=None, title=None, legend=True, fill=None, grids=None):
101
+
102
+ # # df = df.copy()
103
+ # # if df.crs is None:
104
+ # # raise ValueError("Input GeoDataFrame must have a CRS defined.")
105
+ # # if df.crs != CRS.from_epsg(4326):
106
+ # # df = df.to_crs(epsg=4326) # Ensure WGS 84
107
+
108
+ # # ax=ax
109
+
110
+ # # # Default plot arguments
111
+ # # plot_args = {
112
+ # # "ax": ax,
113
+ # # "alpha": 0.6,
114
+ # # "edgecolor": "black",
115
+ # # }
116
+
117
+ # # # Add column-specific arguments if a column is provided
118
+ # # if column:
119
+ # # plot_args["column"] = column
120
+ # # plot_args["legend"] = legend
121
+ # # plot_args["legend_kwds"] = {
122
+ # # "loc": "lower right",
123
+ # # "bbox_to_anchor": (1, 0),
124
+ # # "frameon": True,
125
+ # # "title": column,
126
+ # # }
127
+
128
+ # # # Add fill color
129
+ # # if fill:
130
+ # # plot_args["color"] = fill
131
+
132
+ # # # Set title
133
+ # # if title:
134
+ # # ax.set_title(title, fontsize=14)
135
+
136
+ # # # Add grids if specified
137
+ # # if grids:
138
+ # # ax.grid(visible=True, linestyle="--", linewidth=0.5, alpha=0.7)
139
+
140
+ # # # Plot the GeoDataFrame
141
+ # # df.plot(**plot_args)
142
+
143
+ # # # Add a frame around the map
144
+ # # for spine in ax.spines.values():
145
+ # # spine.set_edgecolor("black")
146
+ # # spine.set_linewidth(1.5)
147
+
148
+ # # # Add basemap
149
+ # # cx.add_basemap(ax, crs=df.crs, source=cx.providers.OpenStreetMap.Mapnik)
150
+ # # return ax
151
+
152
+ # @staticmethod
153
+ # def TileLayer(self, df):
154
+
155
+ # "list of base layers to use"
156
+
157
+ # """
158
+ # Add names, opacity,
159
+
160
+ # addl_args()
161
+
162
+ # Use clean var to
163
+ # """
164
+
165
+ # @staticmethod
166
+ # def title(df):
167
+ # """
168
+ # Plot a GeoDataFrame with optional dynamic column-based styling and a categorical legend.
169
+ # """
170
+ # df = df.copy()
171
+ # df = df.to_crs(epsg=4326) # Ensure WGS 84
172
+
173
+ # # Create plot
174
+ # if ax is None:
175
+ # _, ax = plt.subplots(figsize=(10, 10))
176
+
177
+ # return ax
178
+
179
+ # @staticmethod
180
+ # def legend(df):
181
+
182
+ # return df
183
+
184
+ # @staticmethod
185
+ # def scale_bar(df):
186
+
187
+ # return df
188
+
189
+ # @staticmethod
190
+ # def add_table(df):
191
+
192
+ # return df
193
+
194
+ # @staticmethod
195
+ # def html(df):
196
+
197
+ # return df
198
+
199
+ # @staticmethod
200
+ # def png(df):
201
+
202
+ # return df
203
+
204
+ # @staticmethod
205
+ # def legend(df):
206
+
207
+ # return df
edmt/mapping/maps.py ADDED
@@ -0,0 +1,77 @@
1
+ import contextily as cx
2
+ from edmt.contrib.utils import clean_vars
3
+ # from geopandas import plotting as plot
4
+
5
+ class Mapping:
6
+ def __init__(self,**kwargs):
7
+ self.default_crs = 4326
8
+ self.df_cache = None
9
+ self.ax = None
10
+
11
+ def process_df(self, df):
12
+ """
13
+ Process the GeoDataFrame for plotting.
14
+ Includes caching and CRS transformation.
15
+ """
16
+ self.df_cache = df.copy()
17
+ return self.df_cache.to_crs(epsg=self.default_crs)
18
+
19
+ def get_crs(self):
20
+ return self.default_crs
21
+
22
+ def set_crs(self, crs):
23
+ self.default_crs = crs
24
+
25
+ def gplot(self, df,column:str=None,**kwargs):
26
+ """
27
+ Plot the GeoDataFrame and store the axis object.
28
+ """
29
+ df = self.process_df(df)
30
+ self.ax = df.plot(alpha=0.7,column=column)
31
+ cx.add_basemap(self.ax, source=cx.providers.CartoDB.Positron)
32
+ self.ax.set_axis_off()
33
+ return self
34
+
35
+ def figure(self, width, height):
36
+ if self.ax:
37
+ self.ax.set_figwidth(width)
38
+ self.ax.set_figheight(height)
39
+ return self
40
+
41
+ # usage
42
+ # figure(12, 6)
43
+
44
+ def add_colorbar(self):
45
+ if self.ax:
46
+ self.ax.get_figure().colorbar
47
+ return self
48
+
49
+ def add_axis(self):
50
+ if self.ax:
51
+ self.ax.set_axis_on()
52
+ return self
53
+
54
+ def add_title(self, title):
55
+ if self.ax:
56
+ self.ax.set_title(title)
57
+ return self
58
+
59
+ def add_grids(self):
60
+ if self.ax:
61
+ self.ax.grid(visible=True, linestyle="--", linewidth=0.5, alpha=0.7)
62
+ return self
63
+
64
+ def add_labels(self):
65
+ if self.ax:
66
+ self.ax.tick_params(labeltop=False, labelright=False, labelsize=8, pad=-20)
67
+ return self
68
+
69
+
70
+
71
+ def add_basemap(self, providers=None,tile=None):
72
+ if providers and tile:
73
+ source = f"cx.providers.{providers}.{tile}"
74
+ if self.ax:
75
+ cx.add_basemap(self.ax, source=source)
76
+ self.ax.set_axis_off()
77
+ return self
@@ -0,0 +1,15 @@
1
+ from .drones import (
2
+ Airdata,
3
+ airPoint,
4
+ df_to_gdf,
5
+ airLine,
6
+ airSegment
7
+ )
8
+
9
+ __all__ = [
10
+ "Airdata",
11
+ "airPoint",
12
+ "df_to_gdf",
13
+ "airLine",
14
+ "airSegment"
15
+ ]