diff --git a/app.py b/app.py index 72323858509971fc985b782c8faa75c2c481ae21..6b3765640443b41982a7db67af9fbb2f06889233 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 53774152ab5c90afd4c457a692ff8e72ef1f983a..69448d236ab7e05b0d162a9bce82114905fcfc62 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 85f5da15afe7e6a4bc1089b3e3b0acf27fc22ef1..b3b44f472cbb597dc18dffff0ad71b30123412fe 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 8c13e0695c1752cb933a2973b9c5964dc6a6fab0..3382d4c6ee69969f435b95a11fae69e661590bf5 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 53ae904adb1ecd4c10ee7566733037baf8c12cf5..92ebc620ac51ec9da8a59531609a176fe39a5e2e 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 5cc56dd3ad5b2a2d734141bfff423ac6f2d81db5..7c0ae864dc719d138e1396a6c75d3b45a1773948 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 40a845224aafdefd87c0088d56d9e950a9800b7a..54dc32f0eccd8f14bb0705873e130fbe7e2a8cf7 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 2329717adefe43b755b58cb97f83cab22a05c685..870c97f46273a274de6dc183ad5764f1a1c2518c 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 fae24b54d97fe48784e3780a75c049c09131d92e..84d73df239cc6e579680f3b1f8b3be51f1362e87 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 e3bdd6677772a61aae94c8ea1b6987b1ead88055..44d56bd4509aa2896d0492c27418d239d4140c91 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 bc10c5bc7b136a426ed658a81d236587147c093d..a624c3b69e132c18d6fe2233e1cbc513222bc487 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 5b96d1dbe38c9c4f9992eab4aa5edf98e153cac6..c0c3d40e5f65f86ccacfce616dccf8013b4e6bcf 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 dfde03cc58dba09f01d087c2da9ed3360c449c0c..90d561b2e5df062185daf7d90c508a40e41ea647 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 29fe8d1f936f215f4041a1ce5e4b633da162c526..e8daa4828744cb80b966c2ef6bb5b22ccc83f16e 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 3a4f1c331902c7b659b0b4d3d16093afa371c129..8294e941566b3ecd9c7d14f48813655d6ac0282e 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 0db618505cf6790fb6f159ad372341a912405751..4296665fc8b1af488bc5b5546f8c15ac2692b368 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