From 94ef1007cc7c77c7da1165c4a7a0931cdd6b70e5 Mon Sep 17 00:00:00 2001 From: Mikkel Pedersen Date: Wed, 7 Sep 2022 14:49:36 +0200 Subject: [PATCH] fix(entry): Update recipe Added this to keep the changes somewhere. Will check up on it before sending PR. --- pollination/three_phase/entry.py | 57 ++++++++++--------- .../three_phase/_multiply_matrix.py | 38 ++++++++++++- .../three_phase/three_phase/calculation.py | 4 +- .../three_phase/three_phase/preparation.py | 8 +-- .../two_phase/dynamic/_raytracing.py | 22 ++++++- .../three_phase/two_phase/dynamic/entry.py | 36 ++++++++++-- 6 files changed, 125 insertions(+), 40 deletions(-) diff --git a/pollination/three_phase/entry.py b/pollination/three_phase/entry.py index 8633630..bb6cb18 100644 --- a/pollination/three_phase/entry.py +++ b/pollination/three_phase/entry.py @@ -103,11 +103,11 @@ def create_rad_folder(self, input_model=model, grid_filter=grid_filter): }, { 'from': CreateRadianceFolderGrid()._outputs.model_sensor_grids_file, - 'to': 'results/2_phase/_model_grids_info.json' + 'to': 'results/_model_grids_info.json' }, { 'from': CreateRadianceFolderGrid()._outputs.sensor_grids_file, - 'to': 'results/2_phase/_info.json' + 'to': 'results/_info.json' }, { 'from': CreateRadianceFolderGrid()._outputs.receivers, @@ -168,7 +168,7 @@ def create_direct_sky( ] @task(template=PrepareMultiphase, needs=[create_rad_folder, generate_sunpath]) - def prepare_dynamic( + def prepare_multiphase( self, model=create_rad_folder._outputs.model_folder, sunpath=generate_sunpath._outputs.sunpath, phase=5, cpu_count=cpu_count, cpus_per_grid=3, min_sensor_count=min_sensor_count, static='include' @@ -176,25 +176,28 @@ def prepare_dynamic( return [ { 'from': PrepareMultiphase()._outputs.scene_folder, - 'to': 'resources/octrees' + 'to': 'resources/dynamic/octree' }, { 'from': PrepareMultiphase()._outputs.grid_folder, - 'to': 'resources/grid' + 'to': 'resources/dynamic/grid' }, { 'from': PrepareMultiphase()._outputs.scene_info }, { 'from': PrepareMultiphase()._outputs.two_phase_info + }, + { 'from': PrepareMultiphase()._outputs.grid_states_file, + 'to': 'results/grid_states.json' } ] @task( template=DynamicGroup, - loop=prepare_dynamic._outputs.two_phase_info, + loop=prepare_multiphase._outputs.two_phase_info, needs=[ - create_rad_folder, prepare_dynamic, + create_rad_folder, prepare_multiphase, create_total_sky, create_direct_sky, create_sky_dome, generate_sunpath ], @@ -209,25 +212,26 @@ def prepare_dynamic( def calculate_two_phase_matrix( self, identifier='{{item.identifier}}', + light_path='{{item.light_path}}', radiance_parameters=radiance_parameters, sensor_grids_info='{{item.sensor_grids_info}}', - sensor_grids_folder=prepare_dynamic._outputs.grid_folder, - octree_file=prepare_dynamic._outputs.scene_folder, - octree_file_direct=prepare_dynamic._outputs.scene_folder, - octree_file_with_suns=prepare_dynamic._outputs.scene_folder, + sensor_grids_folder=prepare_multiphase._outputs.grid_folder, + octree_file=prepare_multiphase._outputs.scene_folder, + octree_file_direct=prepare_multiphase._outputs.scene_folder, + octree_file_with_suns=prepare_multiphase._outputs.scene_folder, sky_dome=create_sky_dome._outputs.sky_dome, total_sky=create_total_sky._outputs.sky_matrix, direct_sky=create_direct_sky._outputs.sky_matrix, sun_modifiers=generate_sunpath._outputs.sun_modifiers, bsdf_folder=create_rad_folder._outputs.bsdf_folder, - results_folder='../../../results/2_phase' + results_folder='../../../results' ): pass @task( template=ThreePhaseInputsPreparation, needs=[ - create_rad_folder, prepare_dynamic, + create_rad_folder, prepare_multiphase, create_total_sky, create_sky_dome ], sub_folder='calcs/3_phase/', @@ -238,7 +242,7 @@ def calculate_two_phase_matrix( def prepare_three_phase( self, model_folder=create_rad_folder._outputs.model_folder, - octree=prepare_dynamic._outputs.scene_folder, + octree=prepare_multiphase._outputs.scene_folder, sky_dome=create_sky_dome._outputs.sky_dome, bsdf_folder=create_rad_folder._outputs.bsdf_folder, dmtx_group_params=dmtx_group_params @@ -255,11 +259,11 @@ def prepare_three_phase( { 'from': ThreePhaseInputsPreparation()._outputs.grouped_apertures_folder, 'to': '../../model/sender' - }, - { - 'from': ThreePhaseInputsPreparation()._outputs.results_info, - 'to': '../../results/3_phase/_info.json' } + # { + # 'from': ThreePhaseInputsPreparation()._outputs.results_info, + # 'to': '../../results/3_phase/_info.json' + # } ] @task(template=ReadJSONList, needs=[prepare_three_phase]) @@ -271,7 +275,7 @@ def multiplication_info_to_json( @task( template=ThreePhaseMatrixCalculation, needs=[ - create_rad_folder, prepare_dynamic, + create_rad_folder, prepare_multiphase, create_total_sky, create_sky_dome, prepare_three_phase, multiplication_info_to_json ], @@ -288,16 +292,17 @@ def calculate_three_phase_matrix_total( receivers=create_rad_folder._outputs.receivers, view_mtx_rad_params=view_mtx_rad_params, daylight_mtx_rad_params=daylight_mtx_rad_params, - octree=prepare_dynamic._outputs.scene_folder, + octree=prepare_multiphase._outputs.scene_folder, sky_dome=create_sky_dome._outputs.sky_dome, sky_matrix=create_total_sky._outputs.sky_matrix, bsdf_folder=create_rad_folder._outputs.bsdf_folder, ): - return [ - { - 'from': ThreePhaseMatrixCalculation()._outputs.results, - 'to': '../../results/3_phase' - } - ] + # return [ + # { + # 'from': ThreePhaseMatrixCalculation()._outputs.results, + # 'to': '../../results' + # } + # ] + pass results = Outputs.folder(source='results') diff --git a/pollination/three_phase/three_phase/_multiply_matrix.py b/pollination/three_phase/three_phase/_multiply_matrix.py index 81d9db4..cd34b7b 100644 --- a/pollination/three_phase/three_phase/_multiply_matrix.py +++ b/pollination/three_phase/three_phase/_multiply_matrix.py @@ -1,6 +1,7 @@ from pollination_dsl.dag import Inputs, DAG, task from dataclasses import dataclass from pollination.honeybee_radiance.matrix import MatrixMultiplicationThreePhase +from pollination.honeybee_radiance_postprocess.translate import BinaryToNpy @dataclass @@ -10,6 +11,18 @@ class MultiplyMatrixDag(DAG): description='Aperture state identifier.' ) + light_path = Inputs.str( + description='Aperture state identifier.' + ) + + grid_id = Inputs.str( + description='Aperture state identifier.' + ) + + state_id = Inputs.str( + description='Aperture state identifier.' + ) + sky_vector = Inputs.file( description='Path to sky vector.' ) @@ -30,11 +43,32 @@ class MultiplyMatrixDag(DAG): def multiply_threephase_matrix( self, identifier=identifier, sky_vector=sky_vector, view_matrix=view_matrix, t_matrix=t_matrix, - daylight_matrix=daylight_matrix + daylight_matrix=daylight_matrix, + output_format='f', + conversion='raw', + header='keep' ): return [ { 'from': MatrixMultiplicationThreePhase()._outputs.output_matrix, - 'to': '{{identifier}}.ill' + 'to': 'temp/{{identifier}}.ill' + } + ] + + @task( + template=BinaryToNpy, + needs=[multiply_threephase_matrix] + ) + def binary_to_npy( + self, + matrix_file=multiply_threephase_matrix._outputs.output_matrix, + light_path=light_path, + state_id=state_id, + grid_id=grid_id + ): + return [ + { + 'from': BinaryToNpy()._outputs.output_file, + 'to': '../../results/{{light_path}}/{{state_id}}/total/{{grid_id}}.npy' } ] diff --git a/pollination/three_phase/three_phase/calculation.py b/pollination/three_phase/three_phase/calculation.py index 2bacdd9..01d5906 100644 --- a/pollination/three_phase/three_phase/calculation.py +++ b/pollination/three_phase/three_phase/calculation.py @@ -118,7 +118,6 @@ def daylight_mtx_calculation( # multiply all the matrices for all the states @task( template=MultiplyMatrixDag, - sub_folder='results', loop=multiplication_info, needs=[daylight_mtx_calculation], sub_paths={ @@ -130,6 +129,9 @@ def daylight_mtx_calculation( def multiply_matrix( self, identifier='{{item.identifier}}', + light_path='{{item.light_path}}', + grid_id='{{item.grid_id}}', + state_id='{{item.state_id}}', sky_vector=sky_matrix, view_matrix='view_mtx', t_matrix=model_folder, diff --git a/pollination/three_phase/three_phase/preparation.py b/pollination/three_phase/three_phase/preparation.py index 8ac553a..dcd7fbc 100644 --- a/pollination/three_phase/three_phase/preparation.py +++ b/pollination/three_phase/three_phase/preparation.py @@ -78,10 +78,10 @@ def get_three_phase_combinations( states_info=model_folder ): return [ - { - 'from': MultiPhaseCombinations()._outputs.results_mapper, - 'to': 'results/_info.json' - }, + # { + # 'from': MultiPhaseCombinations()._outputs.results_mapper, + # 'to': 'results/_info.json' + # }, { 'from': MultiPhaseCombinations()._outputs.multiplication_file, 'to': 'multiplication_info.json' diff --git a/pollination/three_phase/two_phase/dynamic/_raytracing.py b/pollination/three_phase/two_phase/dynamic/_raytracing.py index 6a2eb2f..3d82958 100644 --- a/pollination/three_phase/two_phase/dynamic/_raytracing.py +++ b/pollination/three_phase/two_phase/dynamic/_raytracing.py @@ -5,7 +5,8 @@ from pollination.honeybee_radiance.contrib import DaylightContribution from pollination.honeybee_radiance.coefficient import DaylightCoefficient -from pollination.honeybee_radiance.sky import AddRemoveSkyMatrix +from pollination.honeybee_radiance_postprocess.sky import AddRemoveSkyMatrix +from pollination.honeybee_radiance_postprocess.translate import BinaryToNpy @dataclass @@ -141,6 +142,23 @@ def output_matrix_math( return [ { 'from': AddRemoveSkyMatrix()._outputs.results_file, - 'to': '../final/{{self.name}}.ill' + 'to': '../final/total/{{self.name}}.ill' + } + ] + + @task( + template=BinaryToNpy, + needs=[direct_sunlight] + ) + def direct_sunlight_to_npy( + self, + name=grid_name, + matrix_file=direct_sunlight._outputs.result_file, + conversion='47.4 119.9 11.6' + ): + return [ + { + 'from': BinaryToNpy()._outputs.output_file, + 'to': '../final/direct_sunlight/{{self.name}}.ill' } ] diff --git a/pollination/three_phase/two_phase/dynamic/entry.py b/pollination/three_phase/two_phase/dynamic/entry.py index 60d3b7a..991cd7e 100644 --- a/pollination/three_phase/two_phase/dynamic/entry.py +++ b/pollination/three_phase/two_phase/dynamic/entry.py @@ -1,7 +1,7 @@ from pollination_dsl.dag import Inputs, DAG, task from pollination_dsl.dag.inputs import ItemType from dataclasses import dataclass -from pollination.honeybee_radiance.grid import MergeFolderData +from pollination.honeybee_radiance_postprocess.grid import MergeFolderData from ._raytracing import DynamicRayTracing @@ -21,6 +21,12 @@ class DynamicGroup(DAG): 'apertures in the model.', default='__static__' ) + light_path = Inputs.str( + description='Identifier for the light path of this two-phase study. This value ' + 'is the identifier of the aperture group or is set to __static___ for the ' + 'static apertures in the model.', default='__static__' + ) + radiance_parameters = Inputs.str( description='The radiance parameters for ray tracing.', default='-ab 2 -ad 5000 -lw 2e-05' @@ -115,15 +121,35 @@ def two_phase_raytracing( 'dist_info': '_redist_info.json' } ) - def restructure_results( - self, identifier=identifier, - input_folder='initial_results/final', + def restructure_total_results( + self, identifier=identifier, light_path=light_path, + input_folder='initial_results/final/total', + extension='ill', dist_info=sensor_grids_folder, + results_folder=results_folder + ): + return [ + { + 'from': MergeFolderData()._outputs.output_folder, + 'to': '{{self.results_folder}}/{{self.light_path}}/{{self.identifier}}/total' + } + ] + + @task( + template=MergeFolderData, + needs=[two_phase_raytracing], + sub_paths={ + 'dist_info': '_redist_info.json' + } + ) + def restructure_direct_sunlight_results( + self, identifier=identifier, light_path=light_path, + input_folder='initial_results/final/direct_sunlight', extension='ill', dist_info=sensor_grids_folder, results_folder=results_folder ): return [ { 'from': MergeFolderData()._outputs.output_folder, - 'to': '{{self.results_folder}}/{{self.identifier}}' + 'to': '{{self.results_folder}}/{{self.light_path}}/{{self.identifier}}/direct_sunlight' } ]