From ff1f484edcf24fcb8988f28d656df6add86b5d0c Mon Sep 17 00:00:00 2001 From: Maryshca <kuzmichova.maria@ya.ru> Date: Tue, 19 Nov 2024 15:22:21 +0300 Subject: [PATCH] fix --- app.py | 2 +- configs/compact_high_rise.json | 2 +- configs/compact_low_rise.json | 2 +- configs/compact_mid_rise.json | 2 +- configs/heavy_industry.json | 2 +- configs/large_low_rise.json | 2 +- configs/lightweight_low_rise.json | 2 +- configs/open_high_rise.json | 2 +- configs/open_low_rise.json | 2 +- configs/sparsley_build.json | 2 +- generator.py | 10 +++++- map_edit.py | 4 +-- map_edit_callbacks.py | 16 ++++++++-- remote_run.py | 8 ++--- remote_run_callbacks.py | 52 ++++++++++++++++++++++++------- remote_run_ui.py | 2 ++ 16 files changed, 81 insertions(+), 31 deletions(-) diff --git a/app.py b/app.py index 7232385..6b37656 100644 --- a/app.py +++ b/app.py @@ -46,9 +46,9 @@ def exit_callback(): connections[conn].close() def construct_ui(): + config_ui.construct_ui() remote_run_ui.construct_ui() map_edit_ui.construct_ui() - config_ui.construct_ui() setup_handlers() setup_fonts() diff --git a/configs/compact_high_rise.json b/configs/compact_high_rise.json index 5377415..69448d2 100644 --- a/configs/compact_high_rise.json +++ b/configs/compact_high_rise.json @@ -1,6 +1,6 @@ { "width": 800, - "height": 600, + "height": 800, "aspect_ratio": 5, "building_surface_fraction": 0.5, "mean_height_of_roughness_elements": 50, diff --git a/configs/compact_low_rise.json b/configs/compact_low_rise.json index 85f5da1..b3b44f4 100644 --- a/configs/compact_low_rise.json +++ b/configs/compact_low_rise.json @@ -1,6 +1,6 @@ { "width": 800, - "height": 600, + "height": 800, "aspect_ratio": 1, "building_surface_fraction": 0.5, "mean_height_of_roughness_elements": 6, diff --git a/configs/compact_mid_rise.json b/configs/compact_mid_rise.json index 8c13e06..3382d4c 100644 --- a/configs/compact_mid_rise.json +++ b/configs/compact_mid_rise.json @@ -1,6 +1,6 @@ { "width": 800, - "height": 600, + "height": 800, "aspect_ratio": 1.2, "building_surface_fraction": 0.5, "mean_height_of_roughness_elements": 18, diff --git a/configs/heavy_industry.json b/configs/heavy_industry.json index 53ae904..92ebc62 100644 --- a/configs/heavy_industry.json +++ b/configs/heavy_industry.json @@ -1,6 +1,6 @@ { "width": 800, - "height": 600, + "height": 800, "aspect_ratio": 0.3, "building_surface_fraction": 0.25, "mean_height_of_roughness_elements": 10, diff --git a/configs/large_low_rise.json b/configs/large_low_rise.json index 5cc56dd..7c0ae86 100644 --- a/configs/large_low_rise.json +++ b/configs/large_low_rise.json @@ -1,6 +1,6 @@ { "width": 800, - "height": 600, + "height": 800, "aspect_ratio": 0.2, "building_surface_fraction": 0.4, "mean_height_of_roughness_elements": 5, diff --git a/configs/lightweight_low_rise.json b/configs/lightweight_low_rise.json index 40a8452..54dc32f 100644 --- a/configs/lightweight_low_rise.json +++ b/configs/lightweight_low_rise.json @@ -1,6 +1,6 @@ { "width": 800, - "height": 600, + "height": 800, "aspect_ratio": 1.2, "building_surface_fraction": 0.8, "mean_height_of_roughness_elements": 4, diff --git a/configs/open_high_rise.json b/configs/open_high_rise.json index 2329717..870c97f 100644 --- a/configs/open_high_rise.json +++ b/configs/open_high_rise.json @@ -1,6 +1,6 @@ { "width": 800, - "height": 600, + "height": 800, "aspect_ratio": 0.9, "building_surface_fraction": 0.3, "mean_height_of_roughness_elements": 30, diff --git a/configs/open_low_rise.json b/configs/open_low_rise.json index fae24b5..84d73df 100644 --- a/configs/open_low_rise.json +++ b/configs/open_low_rise.json @@ -1,6 +1,6 @@ { "width": 800, - "height": 600, + "height": 800, "aspect_ratio": 0.6, "building_surface_fraction": 0.3, "mean_height_of_roughness_elements": 6, diff --git a/configs/sparsley_build.json b/configs/sparsley_build.json index e3bdd66..44d56bd 100644 --- a/configs/sparsley_build.json +++ b/configs/sparsley_build.json @@ -1,6 +1,6 @@ { "width": 800, - "height": 600, + "height": 800, "aspect_ratio": 0.12, "building_surface_fraction": 0.1, "mean_height_of_roughness_elements": 6, diff --git a/generator.py b/generator.py index bc10c5b..a624c3b 100644 --- a/generator.py +++ b/generator.py @@ -130,7 +130,7 @@ class LCZ: print(desired) def gen_building_heights(self): - self.building_heights = self.rng.uniform(self.min_building_height, self.max_building_height - self.min_building_height, self.n_buildings) + self.building_heights = self.rng.uniform(self.min_building_height, self.max_building_height + 1, self.n_buildings) def gen_buildings(self): splitter = Splitter(self.min_building_distance, self.min_building_width, self.rng) @@ -254,6 +254,14 @@ class LCZ: return height_map if __name__ == '__main__': + import sys + + if sys.argc > 1: + t = sys.argv[1] + lcz = LCZ(config_path=f'configs/{t}.json') + lcz.to_model_input_building('map.txt') + sys.exit(0) + lcz_types = ['compact_high_rise', 'compact_mid_rise', 'compact_low_rise', 'open_high_rise', 'open_mid_rise', 'open_low_rise', 'lightweight_low_rise', 'large_low_rise', 'sparsley_build', 'heavy_industry'] fig, axs = plt.subplots(2, 2, figsize=(10, 6)) diff --git a/map_edit.py b/map_edit.py index 5b96d1d..c0c3d40 100644 --- a/map_edit.py +++ b/map_edit.py @@ -15,9 +15,9 @@ def load_height_map(file_path): def dump_height_map(height_map, file_path): with open(file_path, "w", encoding="utf-8") as file: w, h = height_map.shape - height_map *= get_map_window_value('max_height') + data = height_map * get_map_window_value('max_height') file.write(f"{w} {h}\n") - for row in height_map: + for row in data: file.write(" ".join(list(map(str, map(int, row)))) + "\n") def update_texture(): diff --git a/map_edit_callbacks.py b/map_edit_callbacks.py index dfde03c..90d561b 100644 --- a/map_edit_callbacks.py +++ b/map_edit_callbacks.py @@ -35,15 +35,23 @@ def add_map_to_config_clb(s, a, u): for key in keys: del config[key] - set_main_window_value('config', config) - delete_item_children_and_clear_aliases(f'{get_config_file_path()}.topography') config['topography.mode'] = CfgVar(key='mode', value='ascii-mask') config['topography.filename'] = CfgVar(key='filename', value=get_height_map_file_path()) + config['topography.xmin'] = CfgVar(key='xmin', value=config['domain.x'].value, value_type='DOUBLE') + config['topography.xmax'] = CfgVar(key='xmax', value=config['domain.x'].value + config['domain.length'].value, value_type='DOUBLE') + config['topography.ymin'] = CfgVar(key='ymin', value=config['domain.y'].value, value_type='DOUBLE') + config['topography.ymax'] = CfgVar(key='ymax', value=config['domain.y'].value + config['domain.width'].value, value_type='DOUBLE') + config['topography.height_scale'] = CfgVar(key='height_scale', value=1.0, value_type='DOUBLE') add_item_to_config_ui('topography.mode', before=f'{get_config_file_path()}.{before}') add_item_to_config_ui('topography.filename', before=dpg.last_item()) + add_item_to_config_ui('topography.xmin', before=dpg.last_item()) + add_item_to_config_ui('topography.xmax', before=dpg.last_item()) + add_item_to_config_ui('topography.ymin', before=dpg.last_item()) + add_item_to_config_ui('topography.ymax', before=dpg.last_item()) + add_item_to_config_ui('topography.height_scale', before=dpg.last_item()) dump_height_map(get_map_window_value('buildings_map'), get_height_map_file_path()) @@ -205,7 +213,9 @@ def map_open_clb(s, a, u): open_map(height_map_file_path) def generate_map_clb(s, a, u): - height_map = LCZ(config_path=os.path.join(BASE_PATH, 'configs', f'{s}.json')).to_height_map(dtype=np.float64) + lcz = LCZ(config_path=os.path.join(BASE_PATH, 'configs', f'{s}.json')) + lcz.check_params() + height_map = lcz.to_height_map(dtype=np.float64) max_height = np.max(height_map) height_map /= max_height diff --git a/remote_run.py b/remote_run.py index 29fe8d1..e8daa48 100644 --- a/remote_run.py +++ b/remote_run.py @@ -148,11 +148,11 @@ if __name__ == '__main__': conn = Connection(LOMONOSOV_HOST, 'gashchuk2011_2043', id_rsa_path='D:/lab/id_rsa') - building_session = BuildingSession(conn, LOM_BUILD, 'code/nsenx', gitlab_login, gitlab_password) + #building_session = BuildingSession(conn, LOM_BUILD, 'code/nsenx', gitlab_login, gitlab_password) - while building_session.building(): - print(building_session.output()) - time.sleep(2) + # while building_session.building(): + # print(building_session.output()) + # time.sleep(2) # conn = Connection(LAB_HOST, server_login, server_password) diff --git a/remote_run_callbacks.py b/remote_run_callbacks.py index 3a4f1c3..8294e94 100644 --- a/remote_run_callbacks.py +++ b/remote_run_callbacks.py @@ -16,6 +16,17 @@ from dynamic_ui import construct_model_output_structure_ui from config import dump_config, load_config from style import get_accent_color +def add_running_session_ui(running_session_id, machine, model): + with dpg.table_row(parent='models_table', tag=running_session_id): + dpg.add_text(MODEL_TO_LABEL[model], tag=f'{running_session_id}_model') + dpg.add_text(MACHINE_TO_LABEL[machine], tag=f'{running_session_id}_machine') + dpg.add_text('building', color=list(get_accent_color()[:3]) + [255], tag=f'{running_session_id}_status') + with dpg.group(horizontal=False): + dpg.add_spacer(height=0) + dpg.add_progress_bar(label='progress', default_value=0.0, tag=f'{running_session_id}_progress_bar', height=FONT_SIZE, width=150) + dpg.add_button(label='download output', enabled=False, tag=f'{running_session_id}_download_button', callback=show_download_output_window_clb, user_data=running_session_id) + dpg.bind_item_theme(f'{running_session_id}_progress_bar', 'progress_bar_theme') + def update_run_model_window(): builds = get_run_window_value('builds') connections = get_run_window_value('connections') @@ -39,6 +50,31 @@ def update_run_model_window(): dpg.hide_item('lab_server_group') dpg.show_item('lomonosov_server_group') +def save_running_session(running_session_id): + with open('sessions.txt', 'a+', encoding='utf-8') as log: + model = dpg.get_value(f'{running_session_id}_model') + machine = dpg.get_value(f'{running_session_id}_machine') + log.write(f'{running_session_id};{machine};{model}\n') + +def write_log(output): + if not output: + return + + with open('log.txt', 'a+', encoding='utf-8') as log: + log.write(output + '\n') + +def load_running_sessions(): + if not os.path.exists('sessions.txt'): + return + + with open('sessions.txt', 'r', encoding='utf-8') as file: + for line in file: + running_session_id, machine, model = line.strip('\r\n').split(';') + add_running_session_ui(running_session_id, LABEL_TO_MACHINE[machine], LABEL_TO_MODEL[model]) + dpg.set_value(f'{running_session_id}_status', 'exited long ago') + dpg.hide_item(f'{running_session_id}_progress_bar') + dpg.enable_item(f'{running_session_id}_download_button') + def update_run_model_window_clb(s, a, u): update_run_model_window() @@ -53,17 +89,6 @@ def show_run_model_window_clb(s, a, u): dpg.show_item('run_model_window') -def add_running_session_ui(running_session_id, machine, model): - with dpg.table_row(parent='models_table', tag=running_session_id): - dpg.add_text(MODEL_TO_LABEL[model], tag=f'{running_session_id}_model') - dpg.add_text(MACHINE_TO_LABEL[machine], tag=f'{running_session_id}_machine') - dpg.add_text('building', color=list(get_accent_color()[:3]) + [255], tag=f'{running_session_id}_status') - with dpg.group(horizontal=False): - dpg.add_spacer(height=0) - dpg.add_progress_bar(label='progress', default_value=0.0, tag=f'{running_session_id}_progress_bar', height=FONT_SIZE, width=150) - dpg.add_button(label='download output', enabled=False, tag=f'{running_session_id}_download_button', callback=show_download_output_window_clb, user_data=running_session_id) - dpg.bind_item_theme(f'{running_session_id}_progress_bar', 'progress_bar_theme') - def make_execute_command(): np = int(dpg.get_value('-np')) arch = dpg.get_value('-arch') @@ -162,6 +187,8 @@ def run_model(): add_running_session_ui(running_session_id, machine, model) + save_running_session(running_session_id) + if (machine, model) not in builds: dpg.hide_item(f'{running_session_id}_progress_bar') @@ -213,6 +240,7 @@ def run_model(): while running_session.running(): output = running_session.output() + write_log(output) update_progress(running_session_id, output) dpg.set_value(f'{running_session_id}_status', 'successful run') @@ -275,6 +303,8 @@ def download_output(): for filepath in download: conn.download(f'{running_session_id}/output/{filepath}', os.path.join(prefix, filepath)) + conn.download(f'{running_session_id}/map.txt', os.path.join(prefix, 'map.txt')) + dpg.set_value(f'{running_session_id}_status', 'downloaded') def download_output_clb(s, a, u): diff --git a/remote_run_ui.py b/remote_run_ui.py index 0db6185..4296665 100644 --- a/remote_run_ui.py +++ b/remote_run_ui.py @@ -49,6 +49,8 @@ def construct_remote_run_window(): with dpg.theme_component(dpg.mvAll): dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (255, 255, 255, 100), category=dpg.mvThemeCat_Core) + # load_running_sessions() + def construct_run_model_window(): xoffset = 400 width = 300 -- GitLab