04 solar outside

import os
import topogenesis as tg
import pyvista as pv
import trimesh as tm
import numpy as np
import pickle
import csv
#This script will multiply the solar access of each voxels with its amount of facades
########################################################################################
#Loading the complete lattice and the complete solar access
lattice_path = os.path.relpath("data\lattice_complete_3_6.csv")
envelope_lattice = tg.lattice_from_csv(lattice_path)

with open("data/solar_access_complete_3_6.txt", "rb") as fp:   # Unpickling
    access_lattice = pickle.load(fp)
########################################################################################


########################################################################################
#Initializing a simple list with voxel coordinates
coords = []
coords_val = []
for i in range(len(envelope_lattice)):
    for j in range(len(envelope_lattice[0])):
        for k in range(len(envelope_lattice[0][0])):
            coords.append([i, j, k])
            coords_val.append([i, j, k, envelope_lattice[i][j][k]])
########################################################################################


########################################################################################
#Counting neighbouring voxels
calc = [-1, 1]
result_list = []

for i in coords:
    result = 6
    x = i[0]
    y = i[1]
    z = i[2]
    for j in calc:
        if [x+j, y, z] in coords:
            index = coords.index([x+j, y, z])
            if coords_val[index][3] == True:
                result -= 1
        if [x, y+j, z] in coords:
            index = coords.index([x, y+j, z])
            if coords_val[index][3] == True:
                result -= 1
        if [x, y, z+j] in coords:
            index = coords.index([x, y, z+j])
            if coords_val[index][3] == True:
                result -= 1
    result_list.append([x, y, z, result])
########################################################################################


########################################################################################
#Disregarding the ground as open facade and creating multipliers
for i in range(len(result_list)):
    if result_list[i][2] == 0:
        result_list[i][3] -= 1
    result_list[i][3] /= 6

#Creating the new solar access list based on the multiplier
for i in result_list:
    x = i[0]
    y = i[1]
    z = i[2]
    val = i[3]
    access_lattice[x][y][z] *= val
########################################################################################


########################################################################################
#Exporting the new solar acces lattice
sunacc_lattice = tg.to_lattice(access_lattice, envelope_lattice)
csv_path_access = os.path.relpath("data\solar_access_outside_3_6.csv")
sunacc_lattice.to_csv(csv_path_access)
########################################################################################
print("done")
[[[0.20555567 0.20555567 0.20555567 ... 0.         0.         0.        ]
  [0.10277783 0.10277783 0.10277783 ... 0.         0.         0.        ]
  [0.10277783 0.10277783 0.10277783 ... 0.         0.         0.        ]
  ...
  [0.105      0.105      0.105      ... 0.         0.         0.        ]
  [0.105      0.105      0.105      ... 0.         0.         0.        ]
  [0.21       0.21       0.21       ... 0.         0.         0.        ]]

 [[0.10277783 0.10277783 0.10277783 ... 0.         0.         0.        ]
  [0.         0.         0.         ... 0.         0.         0.        ]
  [0.         0.         0.         ... 0.         0.         0.        ]
  ...
  [0.         0.         0.         ... 0.         0.         0.        ]
  [0.         0.         0.         ... 0.         0.         0.        ]
  [0.105      0.105      0.105      ... 0.         0.         0.        ]]

 [[0.10277783 0.10277783 0.10277783 ... 0.         0.         0.        ]
  [0.         0.         0.         ... 0.         0.         0.        ]
  [0.         0.         0.         ... 0.         0.         0.        ]
  ...
  [0.         0.         0.         ... 0.         0.         0.        ]
  [0.         0.         0.         ... 0.         0.         0.        ]
  [0.105      0.105      0.105      ... 0.         0.         0.        ]]

 ...

 [[0.0544445  0.0544445  0.0544445  ... 0.         0.         0.        ]
  [0.         0.         0.         ... 0.         0.         0.        ]
  [0.         0.         0.         ... 0.         0.         0.        ]
  ...
  [0.         0.         0.         ... 0.         0.         0.        ]
  [0.         0.         0.         ... 0.         0.         0.        ]
  [0.07333333 0.07333333 0.07333333 ... 0.         0.         0.        ]]

 [[0.0544445  0.0544445  0.0544445  ... 0.         0.         0.        ]
  [0.         0.         0.         ... 0.         0.         0.        ]
  [0.         0.         0.         ... 0.         0.         0.        ]
  ...
  [0.         0.         0.         ... 0.         0.         0.        ]
  [0.         0.         0.         ... 0.         0.         0.        ]
  [0.07333333 0.07333333 0.07333333 ... 0.         0.         0.        ]]

 [[0.108889   0.108889   0.108889   ... 0.         0.         0.        ]
  [0.0544445  0.0544445  0.0544445  ... 0.         0.         0.        ]
  [0.0544445  0.0544445  0.0544445  ... 0.         0.         0.        ]
  ...
  [0.07333333 0.07333333 0.07333333 ... 0.         0.         0.        ]
  [0.07333333 0.07333333 0.07333333 ... 0.         0.         0.        ]
  [0.14666667 0.14666667 0.14666667 ... 0.         0.         0.        ]]]


Last update: January 25, 2021