Interpolation sun blockage
Pseudocode
import packages such as topogenesis, pyvista, numpy and scipy.interpolate
load high resolution envelope lattice
load low resolution analysis lattice
# interpolation
extract line spaces for each coordinate:
x_space = np.linspace(start, end, steps)
Interpolating_function = RegularGridInterpolation()
interpolated_values = Interpolating_function(centroids)
# construct lattice
lattice = tg.to_lattice(interpolated_values.reshape(env_lattice.shape))
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered" markdown="1">
<div class="inner_cell" markdown="1">
<div class="text_cell_render border-box-sizing rendered_html" markdown="1">
## 0. Initialization
### 0.1.Importing all necessary libraries and specifying the inputs
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered" markdown="1">
<div class="input">
```python
import os
import topogenesis as tg
import pyvista as pv
import numpy as np
from scipy.interpolate import RegularGridInterpolator
0.2. Load the high resolution envelope lattice
# loading the lattice from csv
lattice_path = os.path.relpath('../data/dynamic output/voxelized_envelope_highres.csv')
env_lattice = tg.lattice_from_csv(lattice_path)
print(env_lattice.shape)
0.3. Load low resolution sun blockage lattice
# loading the lattice from csv
lattice_path = os.path.relpath('../data/dynamic output/sun_blockage_lowres.csv')
low_sunblock_lattice = tg.lattice_from_csv(lattice_path)
print(low_sunblock_lattice.shape)
1. Interpolation
1.1. Interpolating the low-res sun blockage to create the high-res sun blockage lattice
# line spaces
x_space = np.linspace(low_sunblock_lattice.minbound[0], low_sunblock_lattice.maxbound[0],low_sunblock_lattice.shape[0])
y_space = np.linspace(low_sunblock_lattice.minbound[1], low_sunblock_lattice.maxbound[1],low_sunblock_lattice.shape[1])
z_space = np.linspace(low_sunblock_lattice.minbound[2], low_sunblock_lattice.maxbound[2],low_sunblock_lattice.shape[2])
# interpolation function
interpolating_function = RegularGridInterpolator((x_space, y_space, z_space), low_sunblock_lattice, bounds_error=False, fill_value=None)
# high_res lattice
full_lattice = env_lattice + 1
# sample points
sample_points = full_lattice.centroids
# interpolation
interpolated_values = interpolating_function(sample_points)
# lattice construction
sunblock_lattice = tg.to_lattice(interpolated_values.reshape(env_lattice.shape), env_lattice)
# nulling the unavailable cells
sunblock_lattice *= env_lattice
print(sunblock_lattice.shape)
1.2. Visualize the high resolution interpolation of sun blockage
# convert mesh to pv_mesh
def tri_to_pv(tri_mesh):
faces = np.pad(tri_mesh.faces, ((0, 0),(1,0)), 'constant', constant_values=3)
pv_mesh = pv.PolyData(tri_mesh.vertices, faces)
return pv_mesh
# initiating the plotter
p = pv.Plotter(notebook=True)
# Create the spatial reference
grid = pv.UniformGrid()
# Set the grid dimensions: shape because we want to inject our values
grid.dimensions = sunblock_lattice.shape
# The bottom left corner of the data set
grid.origin = sunblock_lattice.minbound
# These are the cell sizes along each axis
grid.spacing = sunblock_lattice.unit
# Add the data values to the cell data
grid.point_arrays["Sun Blockage"] = sunblock_lattice.flatten(order="F") # Flatten the Lattice
# adding the meshes
# p.add_mesh(tri_to_pv(context_mesh), opacity=0.1, style='wireframe')
# adding the volume
opacity = np.array([0,0.6,0.6,0.6,0.6,0.6,0.6])
p.add_volume(grid, cmap="coolwarm", clim=[0, 1.0],opacity=opacity, shade=True)
# plotting
p.show()
1.3. Save the high resolution sun blockage Lattice into a CSV
# save the sun blockage latice to csv
csv_path = os.path.relpath('../data/dynamic output/sun_blockage.csv')
sunblock_lattice.to_csv(csv_path)
Credits
__author__ = "Shervin Azadi and Pirouz Nourian"
__license__ = "MIT"
__version__ = "1.0"
__url__ = "https://github.com/shervinazadi/spatial_computing_workshops"
__summary__ = "Spatial Computing Design Studio Workshop on Solar Envelope"