Skip to content
Snippets Groups Projects
Commit ff1f484e authored by Maryshca's avatar Maryshca
Browse files

fix

parent 35424baf
Branches main
No related tags found
No related merge requests found
......@@ -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()
......
{
"width": 800,
"height": 600,
"height": 800,
"aspect_ratio": 5,
"building_surface_fraction": 0.5,
"mean_height_of_roughness_elements": 50,
......
{
"width": 800,
"height": 600,
"height": 800,
"aspect_ratio": 1,
"building_surface_fraction": 0.5,
"mean_height_of_roughness_elements": 6,
......
{
"width": 800,
"height": 600,
"height": 800,
"aspect_ratio": 1.2,
"building_surface_fraction": 0.5,
"mean_height_of_roughness_elements": 18,
......
{
"width": 800,
"height": 600,
"height": 800,
"aspect_ratio": 0.3,
"building_surface_fraction": 0.25,
"mean_height_of_roughness_elements": 10,
......
{
"width": 800,
"height": 600,
"height": 800,
"aspect_ratio": 0.2,
"building_surface_fraction": 0.4,
"mean_height_of_roughness_elements": 5,
......
{
"width": 800,
"height": 600,
"height": 800,
"aspect_ratio": 1.2,
"building_surface_fraction": 0.8,
"mean_height_of_roughness_elements": 4,
......
{
"width": 800,
"height": 600,
"height": 800,
"aspect_ratio": 0.9,
"building_surface_fraction": 0.3,
"mean_height_of_roughness_elements": 30,
......
{
"width": 800,
"height": 600,
"height": 800,
"aspect_ratio": 0.6,
"building_surface_fraction": 0.3,
"mean_height_of_roughness_elements": 6,
......
{
"width": 800,
"height": 600,
"height": 800,
"aspect_ratio": 0.12,
"building_surface_fraction": 0.1,
"mean_height_of_roughness_elements": 6,
......
......@@ -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))
......
......@@ -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():
......
......@@ -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
......
......@@ -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)
......
......@@ -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):
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment