diffusion-cartogram 0.2.0__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.
- diffusion_cartogram/__init__.py +202 -0
- diffusion_cartogram/core.py +1329 -0
- diffusion_cartogram/core_2d.py +831 -0
- diffusion_cartogram/visualization.py +1490 -0
- diffusion_cartogram/visualization_2d.py +534 -0
- diffusion_cartogram-0.2.0.dist-info/METADATA +287 -0
- diffusion_cartogram-0.2.0.dist-info/RECORD +10 -0
- diffusion_cartogram-0.2.0.dist-info/WHEEL +5 -0
- diffusion_cartogram-0.2.0.dist-info/licenses/LICENSE +21 -0
- diffusion_cartogram-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""
|
|
2
|
+
diffusion-cartogram: Volumetric Density-Equalizing Reference Map
|
|
3
|
+
|
|
4
|
+
Python implementation of the VDERM algorithm for 3-D shape deformation
|
|
5
|
+
(Choi & Rycroft 2020) and — new in v2.0 — 2-D density-equalizing
|
|
6
|
+
cartogram deformation from GeoJSON / Shapefile inputs.
|
|
7
|
+
|
|
8
|
+
3-D Quick Start
|
|
9
|
+
---------------
|
|
10
|
+
>>> import diffusion_cartogram as vd
|
|
11
|
+
>>>
|
|
12
|
+
>>> surface_pts, normals = vd.create_pcd('mesh.stl', n_pts=25000)
|
|
13
|
+
>>> gp = vd.make_initial_grid(surface_pts, max_points=32768)
|
|
14
|
+
>>> grid = vd.VDERMGrid(gp['shape'], gp['h'], gp['min_bounds'])
|
|
15
|
+
>>> grid.set_density(my_density_function)
|
|
16
|
+
>>> result = vd.run_VDERM(grid, n_max=100, max_eps=0.02)
|
|
17
|
+
>>> deformed = vd.interpolate_to_surface(surface_pts, gp,
|
|
18
|
+
... result.get_displacement_field())
|
|
19
|
+
|
|
20
|
+
2-D Quick Start
|
|
21
|
+
---------------
|
|
22
|
+
>>> pts, crs = vd.read_geojson('countries.geojson')
|
|
23
|
+
>>> gp = vd.make_initial_grid_2d(pts, max_points=16384)
|
|
24
|
+
>>> grid = vd.VDERMGrid2D(gp['shape'], gp['h'], gp['min_bounds'])
|
|
25
|
+
>>> vd.density_from_geotiff(grid, 'population.tif')
|
|
26
|
+
>>> result = vd.run_VDERM(grid) # run_VDERM works for both 2D and 3D
|
|
27
|
+
>>> deformed = vd.interpolate_to_map_2d(pts, gp,
|
|
28
|
+
... result.get_displacement_field())
|
|
29
|
+
>>> vd.plot_map_2d(deformed, title='Population Cartogram')
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
__version__ = '0.2.0'
|
|
33
|
+
|
|
34
|
+
# Core VDERM classes and algorithms
|
|
35
|
+
from .core import (
|
|
36
|
+
VDERMGrid,
|
|
37
|
+
run_VDERM,
|
|
38
|
+
run_VDERM_with_tracking,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# I/O functions
|
|
42
|
+
from .core import (
|
|
43
|
+
write_xyz,
|
|
44
|
+
read_xyz,
|
|
45
|
+
create_pcd,
|
|
46
|
+
export_mesh_file,
|
|
47
|
+
export_mesh_vtk,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Grid utilities
|
|
51
|
+
from .core import (
|
|
52
|
+
compute_grid_dimensions,
|
|
53
|
+
make_initial_grid,
|
|
54
|
+
print_grid_info,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# interpolation and remeshing utilities
|
|
58
|
+
from .core import (
|
|
59
|
+
HAS_PYMESHLAB,
|
|
60
|
+
interpolate_densities,
|
|
61
|
+
interpolate_to_surface,
|
|
62
|
+
interpolate_velocities,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
# Visualization functions (optional - only if matplotlib available)
|
|
66
|
+
try:
|
|
67
|
+
from .visualization import (
|
|
68
|
+
animate_grid_deformation,
|
|
69
|
+
animate_surface_deformation,
|
|
70
|
+
create_side_by_side_animation,
|
|
71
|
+
plot_density_evolution,
|
|
72
|
+
export_all_to_paraview,
|
|
73
|
+
export_meshes_to_paraview,
|
|
74
|
+
export_surface_to_paraview,
|
|
75
|
+
export_grid_to_paraview,
|
|
76
|
+
plot_pcd,
|
|
77
|
+
interactive_pcd_plot,
|
|
78
|
+
)
|
|
79
|
+
_has_visualization = True
|
|
80
|
+
except ImportError:
|
|
81
|
+
_has_visualization = False
|
|
82
|
+
|
|
83
|
+
__all__ = [
|
|
84
|
+
# Core classes and algorithms
|
|
85
|
+
'VDERMGrid',
|
|
86
|
+
'run_VDERM',
|
|
87
|
+
'run_VDERM_with_tracking',
|
|
88
|
+
|
|
89
|
+
# I/O
|
|
90
|
+
'write_xyz',
|
|
91
|
+
'read_xyz',
|
|
92
|
+
'create_pcd',
|
|
93
|
+
'export_mesh_file',
|
|
94
|
+
'export_mesh_vtk',
|
|
95
|
+
|
|
96
|
+
# Grid utilities
|
|
97
|
+
'compute_grid_dimensions',
|
|
98
|
+
'make_initial_grid',
|
|
99
|
+
'print_grid_info',
|
|
100
|
+
|
|
101
|
+
# mesh utilities
|
|
102
|
+
'HAS_PYMESHLAB',
|
|
103
|
+
'interpolate_densities',
|
|
104
|
+
'interpolate_to_surface',
|
|
105
|
+
'interpolate_velocities',
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
# Add visualization functions to __all__ if available
|
|
109
|
+
if _has_visualization:
|
|
110
|
+
__all__.extend([
|
|
111
|
+
'animate_grid_deformation',
|
|
112
|
+
'animate_surface_deformation',
|
|
113
|
+
'create_side_by_side_animation',
|
|
114
|
+
'plot_density_evolution',
|
|
115
|
+
'export_grid_to_paraview',
|
|
116
|
+
'export_surface_to_paraview',
|
|
117
|
+
'export_meshes_to_paraview',
|
|
118
|
+
'export_all_to_paraview',
|
|
119
|
+
'plot_pcd',
|
|
120
|
+
'interactive_pcd_plot',
|
|
121
|
+
])
|
|
122
|
+
|
|
123
|
+
# ── 2-D API ──────────────────────────────────────────────────────────────────
|
|
124
|
+
|
|
125
|
+
# 2-D core classes and algorithms
|
|
126
|
+
from .core_2d import (
|
|
127
|
+
VDERMGrid2D,
|
|
128
|
+
run_VDERM_2d_with_tracking,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
# 2-D grid utilities
|
|
132
|
+
from .core_2d import (
|
|
133
|
+
compute_grid_dimensions_2d,
|
|
134
|
+
make_initial_grid_2d,
|
|
135
|
+
print_grid_info_2d,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
# 2-D interpolation
|
|
139
|
+
from .core_2d import (
|
|
140
|
+
interpolate_densities_2d,
|
|
141
|
+
interpolate_velocities_2d,
|
|
142
|
+
interpolate_to_map_2d,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
# 2-D I/O (always available)
|
|
146
|
+
from .core_2d import (
|
|
147
|
+
write_csv_2d,
|
|
148
|
+
read_csv_2d,
|
|
149
|
+
HAS_GEOPANDAS,
|
|
150
|
+
HAS_RASTERIO,
|
|
151
|
+
read_geojson,
|
|
152
|
+
read_shapefile,
|
|
153
|
+
read_geotiff,
|
|
154
|
+
density_from_geotiff,
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
# 2-D visualization (optional)
|
|
158
|
+
try:
|
|
159
|
+
from .visualization_2d import (
|
|
160
|
+
plot_map_2d,
|
|
161
|
+
plot_density_field_2d,
|
|
162
|
+
plot_map_before_after,
|
|
163
|
+
animate_map_deformation_2d,
|
|
164
|
+
animate_grid_deformation_2d,
|
|
165
|
+
plot_density_evolution_2d,
|
|
166
|
+
)
|
|
167
|
+
_has_visualization_2d = True
|
|
168
|
+
except ImportError:
|
|
169
|
+
_has_visualization_2d = False
|
|
170
|
+
|
|
171
|
+
__all__ += [
|
|
172
|
+
# 2-D classes and algorithms
|
|
173
|
+
'VDERMGrid2D',
|
|
174
|
+
'run_VDERM_2d_with_tracking',
|
|
175
|
+
# 2-D grid utilities
|
|
176
|
+
'compute_grid_dimensions_2d',
|
|
177
|
+
'make_initial_grid_2d',
|
|
178
|
+
'print_grid_info_2d',
|
|
179
|
+
# 2-D interpolation
|
|
180
|
+
'interpolate_densities_2d',
|
|
181
|
+
'interpolate_velocities_2d',
|
|
182
|
+
'interpolate_to_map_2d',
|
|
183
|
+
# 2-D I/O
|
|
184
|
+
'write_csv_2d',
|
|
185
|
+
'read_csv_2d',
|
|
186
|
+
'HAS_GEOPANDAS',
|
|
187
|
+
'HAS_RASTERIO',
|
|
188
|
+
'read_geojson',
|
|
189
|
+
'read_shapefile',
|
|
190
|
+
'read_geotiff',
|
|
191
|
+
'density_from_geotiff',
|
|
192
|
+
]
|
|
193
|
+
|
|
194
|
+
if _has_visualization_2d:
|
|
195
|
+
__all__ += [
|
|
196
|
+
'plot_map_2d',
|
|
197
|
+
'plot_density_field_2d',
|
|
198
|
+
'plot_map_before_after',
|
|
199
|
+
'animate_map_deformation_2d',
|
|
200
|
+
'animate_grid_deformation_2d',
|
|
201
|
+
'plot_density_evolution_2d',
|
|
202
|
+
]
|