Commit fad729bc authored by Bognár, Á.'s avatar Bognár, Á.
Browse files

module to visualize and post-process irradiance simulation results

parent 4b8dc378
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import os
# we need the ill result, the pts and kts and merge this into some structure, that the corresponding surface name, the sensor point coords (maybe even reelative coords on the surface?) and the irrad value are in one object
# navigate to the project folder and run
def ill_to_df(p_name):
pts = pd.read_csv(r'pts\{}.csv'.format(p_name))
surfnames = list(pts['surf_name']) # read the surf names fom the csv
# make a list of unique names for the ptss. These will be the col names for the ill dataframe
ptsnames = []
n = 0
for i in list(range(len(surfnames))):
if surfnames[i-1] != surfnames[i]:
ptsnames.append(surfnames[i] + '_{}'.format(str(n)))
n = n+1
ptsnames = []
for i in list(range(len(surfnames))):
ptsnames.append(surfnames[i] + 'c{}r{}'.format(pts['ci'][i], )
ill = pd.read_csv(r'res\{}.ill'.format(p_name), sep=' ', skipinitialspace=True, header=None, dtype=np.float64)
# converting fraction hours seems complicated because of rounding errors, so for now, lazily we generate our own timestamps from the first two rows
timestepmins = pd.Timedelta(minutes=int(round((ill[2][1] - ill[2][0]) * 60)))
startdate = pd.Timestamp('2001-01-01 00:00:00') + timestepmins / 2 # date will be always 2001 for now
enddate = pd.Timestamp('2002-01-01 00:00:00') - timestepmins / 2
Timestamp = pd.date_range(start=startdate, end=enddate, freq='{}T'.format(str(timestepmins.seconds/60)))
# getting rid of old time columns and adding the new timestamp + naming the columns
ill.drop([0, 1, 2], axis=1, inplace=True)
oldcol = list(ill.columns)
ill.rename(columns=dict(zip(oldcol, ptsnames)), inplace=True)
ill['Timestamp'] = Timestamp
ill.set_index('Timestamp', inplace=True)
return ill
def view_idf_to_ax(fname=None, idf_txt=None, test=False):
"""This is originally from
This just returns an ax instead of viewing it on order to plot it together with the sensorpoints"""
from geomeppy.view_geometry import _get_collection, _get_collections, _get_surfaces, _get_limits # probably these should not be imported here
from io import StringIO
from eppy.iddcurrent import iddcurrent
from geomeppy import IDF
# type: (Optional[str], Optional[str], Optional[bool]) -> None
if fname and idf_txt:
raise ValueError("Pass either fname or idf_txt, not both.")
# set the IDD for the version of EnergyPlus
iddfhandle = StringIO(iddcurrent.iddtxt)
if IDF.getiddname() is None:
if fname:
# import the IDF
idf = IDF(fname)
elif idf_txt:
idf = IDF()
# create the figure and add the surfaces
ax = plt.axes(projection="3d")
collections = _get_collections(idf, opacity=0.5)
for c in collections:
# calculate and set the axis limits
limits = _get_limits(idf=idf)
return ax
def view_idf_and_ill(p_name, idf_name, sps, ill, save_fig):
from geomeppy.geom.polygons import Polygon3D
"To view the e+ IDF and the DS sensorpoints together. Ill should be a pd.series with time in index"
# TODO implement auto save fig: Save_fig False: no saving, True: save it to /geo
surfcoords = []
polys = []
for surf in sps:
for sp in surf['sensor_points']:
surfcoords.append((sp[0], sp[1], sp[2]))
xs = [c[0] for c in surfcoords]
ys = [c[1] for c in surfcoords]
zs = [c[2] for c in surfcoords]
ax2 = view_idf_to_ax(fname=idf_name, idf_txt=None, test=False)
ax2.scatter(xs, ys, zs, marker='o', s=2, c=ill, cmap='nipy_spectral', vmin=0, vmax=1000)
if save_fig:
plt.savefig('res/vis/{}_{}.png'.format(p_name, str(':', '')))
......@@ -4,7 +4,8 @@ from geomeppy import IDF
from geomeppy import view_geometry
import os
import sys
sys.path.append(os.path.dirname(os.getcwd()) + r'\\daypym')
#sys.path.append(os.path.dirname(os.getcwd()) + r'\\daypym')
from daypym import *
from geomeppy.geom.polygons import (break_polygons, Polygon2D, Polygon3D, Vector2D, Vector3D)
from geomeppy.geom.transformations import align_face, invert_align_face
......@@ -74,7 +75,7 @@ site_info = {
# add wea file data to the site info
# write hea
write_ds_hea(p_name=project_name, p_dir=cwd, bin_dir=r'c:\DAYSIM\bin\\', uni_mat_file=r'daysim_all_mat.rad', site_info=site_info, model_info=None, radiance_params=None) # set bim_dir to the "...\DAYSIM\bin" folder on your computer
write_ds_hea(p_name=project_name, p_dir=cwd, bin_dir=r'c:\DAYSIM4\bin\\', uni_mat_file=r'daysim_all_mat.rad', site_info=site_info, model_info=None, radiance_params=None) # set bim_dir to the "...\DAYSIM\bin" folder on your computer
#run conversion, dc and ill
ds_radfiles2daysim(p_name=project_name, hea_file_name=None)
ds_ds_shortterm(project_name, hea_file_name=None)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment