cgeorgiaw HF Staff commited on
Commit
8bb5d86
·
1 Parent(s): 2777d26

adding more plot types

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -27,8 +27,20 @@ def read_result_from_hub(filename):
27
  return local_path
28
 
29
  def make_visual(boundary):
30
- vis = visualization.plot_surface(boundary)
31
- return vis
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  def gradio_interface() -> gr.Blocks:
34
  with gr.Blocks() as demo:
@@ -62,8 +74,10 @@ def gradio_interface() -> gr.Blocks:
62
  n_field_periods = gr.Number(label="Number of Period Fields", value=3)
63
  generate_btn = gr.Button(value="Generate")
64
 
65
-
66
- plot = gr.Plot()
 
 
67
 
68
  def update_ui(mode):
69
  return (
@@ -77,15 +91,15 @@ def gradio_interface() -> gr.Blocks:
77
  def get_boundary_from_leaderboard(selected_file):
78
  row = full_df[full_df['result_filename'] == selected_file].iloc[0]
79
  if row['problem_type'] == 'mhd_stable':
80
- raise gr.Error("Sorry this isn't implemented for mhd_stable submissions yet!")
81
  else:
82
  boundary = load_boundary(row['boundary_json'])
83
 
84
  vis = make_visual(boundary)
85
  return vis
86
 
87
- dropdown.change(get_boundary_from_leaderboard, dropdown, plot)
88
- rld_btn.click(get_boundary_from_leaderboard, dropdown, plot)
89
 
90
  def get_boundary_vis_from_upload(uploaded_file):
91
  if uploaded_file is None:
@@ -95,7 +109,7 @@ def gradio_interface() -> gr.Blocks:
95
  boundary = load_boundary(data)
96
  return make_visual(boundary)
97
 
98
- upload_box.change(get_boundary_vis_from_upload, inputs=[upload_box], outputs=[plot])
99
 
100
  def generate_random_boundary(aspect_ratio, elongation, rotational_transform, n_field_periods):
101
  boundary = initial_guess.generate_rotating_ellipse(
@@ -104,7 +118,7 @@ def gradio_interface() -> gr.Blocks:
104
  vis = make_visual(boundary)
105
  return vis
106
 
107
- generate_btn.click(generate_random_boundary, [aspect_ratio, elongation, rotational_transform, n_field_periods], plot)
108
 
109
  return demo
110
 
 
27
  return local_path
28
 
29
  def make_visual(boundary):
30
+ boundary_plot = visualization.plot_boundary(boundary)
31
+ interactive_plot = visualization.plot_surface(boundary)
32
+ settings = forward_model.ConstellarationSettings.default_high_fidelity_skip_qi()
33
+ boundary_metrics, boundary_equilibrium = forward_model.forward_model(
34
+ boundary, settings=settings
35
+ )
36
+ boozer_settings = boozer.BoozerSettings(normalized_toroidal_flux=[0.0, 0.25, 1])
37
+ boozer_plot = visualization.plot_boozer_surfaces(
38
+ boundary_equilibrium, settings=boozer_settings
39
+ )
40
+ flux_surface_plot = visualization.plot_flux_surfaces(
41
+ boundary_equilibrium, boundary
42
+ )
43
+ return boundary_plot, interactive_plot, boozer_plot, flux_surface_plot
44
 
45
  def gradio_interface() -> gr.Blocks:
46
  with gr.Blocks() as demo:
 
74
  n_field_periods = gr.Number(label="Number of Period Fields", value=3)
75
  generate_btn = gr.Button(value="Generate")
76
 
77
+ boundary_plot = gr.Plot()
78
+ interactive_plot = gr.Plot()
79
+ boozer_plot = gr.Plot()
80
+ flux_surface_plot = gr.Plot()
81
 
82
  def update_ui(mode):
83
  return (
 
91
  def get_boundary_from_leaderboard(selected_file):
92
  row = full_df[full_df['result_filename'] == selected_file].iloc[0]
93
  if row['problem_type'] == 'mhd_stable':
94
+ raise gr.Error("Sorry this isn't implemented for files with multiple boundaries yet!")
95
  else:
96
  boundary = load_boundary(row['boundary_json'])
97
 
98
  vis = make_visual(boundary)
99
  return vis
100
 
101
+ dropdown.change(get_boundary_from_leaderboard, dropdown, [boundary_plot, interactive_plot, boozer_plot, flux_surface_plot])
102
+ rld_btn.click(get_boundary_from_leaderboard, dropdown, [boundary_plot, interactive_plot, boozer_plot, flux_surface_plot])
103
 
104
  def get_boundary_vis_from_upload(uploaded_file):
105
  if uploaded_file is None:
 
109
  boundary = load_boundary(data)
110
  return make_visual(boundary)
111
 
112
+ upload_box.change(get_boundary_vis_from_upload, inputs=[upload_box], outputs=[boundary_plot, interactive_plot, boozer_plot, flux_surface_plot])
113
 
114
  def generate_random_boundary(aspect_ratio, elongation, rotational_transform, n_field_periods):
115
  boundary = initial_guess.generate_rotating_ellipse(
 
118
  vis = make_visual(boundary)
119
  return vis
120
 
121
+ generate_btn.click(generate_random_boundary, [aspect_ratio, elongation, rotational_transform, n_field_periods], [boundary_plot, interactive_plot, boozer_plot, flux_surface_plot])
122
 
123
  return demo
124