voxcity 0.6.21__py3-none-any.whl → 0.6.22__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.

Potentially problematic release.


This version of voxcity might be problematic. Click here for more details.

@@ -2387,166 +2387,6 @@ def _rgb_tuple_to_plotly_color(rgb_tuple):
2387
2387
 
2388
2388
 
2389
2389
  def visualize_voxcity_plotly(
2390
- voxel_array,
2391
- meshsize,
2392
- classes=None,
2393
- voxel_color_map='default',
2394
- opacity=None,
2395
- max_dimension=128,
2396
- downsample=None,
2397
- title=None,
2398
- width=1000,
2399
- height=800,
2400
- show=True,
2401
- return_fig=False,
2402
- ):
2403
- """
2404
- Interactive 3D visualization of a voxcity voxel grid using Plotly.
2405
-
2406
- Parameters
2407
- ----------
2408
- voxel_array : np.ndarray
2409
- 3D array of voxel class IDs with shape (nx, ny, nz).
2410
- meshsize : float
2411
- Physical size of each voxel in meters.
2412
- classes : list[int], optional
2413
- Voxel class IDs to render. Defaults to prominent classes if None. Typical IDs:
2414
- - -3: Buildings
2415
- - -2: Vegetation
2416
- - -1: Underground
2417
- - 1..: Ground surface classes
2418
- voxel_color_map : str
2419
- Name of color scheme to fetch via get_voxel_color_map.
2420
- opacity : float or dict[int,float], optional
2421
- Single opacity for all classes (0-1) or per-class mapping.
2422
- max_dimension : int
2423
- If any axis exceeds this and downsample is None, auto downsample to keep
2424
- dimensions <= max_dimension.
2425
- downsample : int, optional
2426
- Explicit stride for all axes (e.g., 2 renders every other voxel).
2427
- title : str, optional
2428
- Figure title.
2429
- width, height : int
2430
- Figure size in pixels.
2431
- show : bool
2432
- Whether to display the figure (default True).
2433
- return_fig : bool
2434
- Whether to return the plotly Figure object.
2435
-
2436
- Notes
2437
- -----
2438
- - Uses one Isosurface trace per class with isomin/isomax around the class value.
2439
- - For large grids, consider downsampling for performance.
2440
- """
2441
- if voxel_array is None or getattr(voxel_array, 'ndim', 0) != 3:
2442
- raise ValueError("voxel_array must be a 3D numpy array (nx, ny, nz)")
2443
-
2444
- vox = voxel_array
2445
-
2446
- # Downsample for performance if requested or auto-needed
2447
- stride = 1
2448
- if downsample is not None and downsample > 1:
2449
- stride = int(downsample)
2450
- else:
2451
- nx, ny, nz = vox.shape
2452
- max_dim = max(nx, ny, nz)
2453
- if max_dim > max_dimension:
2454
- # ceil so that max_dim/stride <= max_dimension
2455
- stride = int(np.ceil(max_dim / max_dimension))
2456
-
2457
- if stride > 1:
2458
- vox = vox[::stride, ::stride, ::stride]
2459
-
2460
- nx, ny, nz = vox.shape
2461
- # Coordinate axes in meters
2462
- x = np.arange(nx, dtype=float) * meshsize * stride
2463
- y = np.arange(ny, dtype=float) * meshsize * stride
2464
- z = np.arange(nz, dtype=float) * meshsize * stride
2465
-
2466
- # Select default classes if not provided: render all non-zero classes present
2467
- if classes is None:
2468
- classes = np.unique(vox[vox != 0]).tolist()
2469
-
2470
- if not classes:
2471
- raise ValueError("No classes to visualize (voxel grid may be empty)")
2472
-
2473
- # Colors
2474
- vox_dict = get_voxel_color_map(voxel_color_map)
2475
- class_to_color = {}
2476
- for c in classes:
2477
- color_rgb = vox_dict.get(int(c), [128, 128, 128])
2478
- class_to_color[c] = _rgb_tuple_to_plotly_color(color_rgb)
2479
-
2480
- # Opacity per class
2481
- def get_opacity(c):
2482
- if isinstance(opacity, dict):
2483
- return float(opacity.get(c, 0.6))
2484
- if isinstance(opacity, (int, float)):
2485
- return float(opacity)
2486
- # defaults: buildings opaque, vegetation semi
2487
- return 0.95 if c == -3 else 0.6
2488
-
2489
- # Build figure
2490
- fig = go.Figure()
2491
-
2492
- # Precompute flat coordinates for isosurface
2493
- # Plotly Isosurface accepts 1D arrays for x, y, z defining positions
2494
- # combined with a 3D value grid.
2495
- X = np.broadcast_to(x[:, None, None], (nx, ny, nz)).ravel()
2496
- Y = np.broadcast_to(y[None, :, None], (nx, ny, nz)).ravel()
2497
- Z = np.broadcast_to(z[None, None, :], (nx, ny, nz)).ravel()
2498
-
2499
- for cls in classes:
2500
- # Skip if class not present
2501
- if not np.any(vox == cls):
2502
- continue
2503
-
2504
- # Colorscale with a single color
2505
- color = class_to_color.get(cls, "rgb(128,128,128)")
2506
- colorscale = [[0.0, color], [1.0, color]]
2507
-
2508
- # Use binary mask per class to ensure iso level lies strictly between 0 and 1
2509
- M = (vox == cls).astype(np.uint8).ravel()
2510
-
2511
- fig.add_trace(
2512
- go.Isosurface(
2513
- x=X,
2514
- y=Y,
2515
- z=Z,
2516
- value=M,
2517
- isomin=0.5,
2518
- isomax=0.5001,
2519
- surface_count=1,
2520
- caps=dict(x_show=False, y_show=False, z_show=False),
2521
- colorscale=colorscale,
2522
- showscale=False,
2523
- opacity=get_opacity(cls),
2524
- name=str(cls),
2525
- )
2526
- )
2527
-
2528
- # Layout
2529
- fig.update_layout(
2530
- title=title or "VoxCity 3D (Plotly)",
2531
- width=width,
2532
- height=height,
2533
- scene=dict(
2534
- xaxis_title="X (m)",
2535
- yaxis_title="Y (m)",
2536
- zaxis_title="Z (m)",
2537
- aspectmode="data",
2538
- ),
2539
- legend=dict(itemsizing='constant')
2540
- )
2541
-
2542
- if show:
2543
- fig.show()
2544
- if return_fig:
2545
- return fig
2546
- return None
2547
-
2548
-
2549
- def visualize_voxcity_plotly_voxels(
2550
2390
  voxel_array,
2551
2391
  meshsize,
2552
2392
  classes=None,
@@ -2572,10 +2412,11 @@ def visualize_voxcity_plotly_voxels(
2572
2412
  vox = voxel_array
2573
2413
 
2574
2414
  # Downsample for performance if requested or auto-needed
2575
- stride = 1
2576
- if downsample is not None and downsample > 1:
2577
- stride = int(downsample)
2415
+ # Respect explicit downsample even when it is 1 (no auto-downsample)
2416
+ if downsample is not None:
2417
+ stride = max(1, int(downsample))
2578
2418
  else:
2419
+ stride = 1
2579
2420
  nx, ny, nz = vox.shape
2580
2421
  max_dim = max(nx, ny, nz)
2581
2422
  if max_dim > max_dimension:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: voxcity
3
- Version: 0.6.21
3
+ Version: 0.6.22
4
4
  Summary: voxcity is an easy and one-stop tool to output 3d city models for microclimate simulation by integrating multiple geospatial open-data
5
5
  License: MIT
6
6
  License-File: AUTHORS.rst
@@ -29,10 +29,10 @@ voxcity/simulator/view.py,sha256=k3FoS6gsibR-eDrTHJivJSQfvN3Tg8R8eSTeMqd9ans,939
29
29
  voxcity/utils/__init__.py,sha256=Q-NYCqYnAAaF80KuNwpqIjbE7Ec3Gr4y_khMLIMhJrg,68
30
30
  voxcity/utils/lc.py,sha256=722Gz3lPbgAp0mmTZ-g-QKBbAnbxrcgaYwb1sa7q8Sk,16189
31
31
  voxcity/utils/material.py,sha256=H8K8Lq4wBL6dQtgj7esUW2U6wLCOTeOtelkTDJoRgMo,10007
32
- voxcity/utils/visualization.py,sha256=rPPxZeoMvzDblZe6A2vgRkX1PHXVdft6l36nLOuSRkU,114774
32
+ voxcity/utils/visualization.py,sha256=kccIndyz3idTTSVMwGgniQ7zFuKLRRnOP4pgyn1xs20,109849
33
33
  voxcity/utils/weather.py,sha256=cb6ZooL42Hc4214OtFiJ78cCgWYM6VE-DU8S3e-urRg,48449
34
- voxcity-0.6.21.dist-info/licenses/AUTHORS.rst,sha256=m82vkI5QokEGdcHof2OxK39lf81w1P58kG9ZNNAKS9U,175
35
- voxcity-0.6.21.dist-info/licenses/LICENSE,sha256=s_jE1Df1nTPL4A_5GCGic5Zwex0CVaPKcAmSilxJPPE,1089
36
- voxcity-0.6.21.dist-info/METADATA,sha256=mt2V_ZeRFL7UUBuEeUUUc_Br_fhvB9pPtbXVTaTvobY,26227
37
- voxcity-0.6.21.dist-info/WHEEL,sha256=M5asmiAlL6HEcOq52Yi5mmk9KmTVjY2RDPtO4p9DMrc,88
38
- voxcity-0.6.21.dist-info/RECORD,,
34
+ voxcity-0.6.22.dist-info/licenses/AUTHORS.rst,sha256=m82vkI5QokEGdcHof2OxK39lf81w1P58kG9ZNNAKS9U,175
35
+ voxcity-0.6.22.dist-info/licenses/LICENSE,sha256=s_jE1Df1nTPL4A_5GCGic5Zwex0CVaPKcAmSilxJPPE,1089
36
+ voxcity-0.6.22.dist-info/METADATA,sha256=DB0CXRCCFsr_THg8zt7BcGF-2GtXlBMzHFdKAES6jC0,26227
37
+ voxcity-0.6.22.dist-info/WHEEL,sha256=M5asmiAlL6HEcOq52Yi5mmk9KmTVjY2RDPtO4p9DMrc,88
38
+ voxcity-0.6.22.dist-info/RECORD,,