Last active
January 2, 2022 04:53
-
-
Save shkiefer/2dbc9f937d99d79addc4990450819a16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.callback( | |
Output(f'{APP_ID}_geom_rep_mesh', 'children'), | |
Output(f'{APP_ID}_geom_rep_mesh', 'colorDataRange'), | |
Output(f'{APP_ID}_results_colorbar_graph', 'figure'), | |
Output(f'{APP_ID}_results_min_max_dt', 'data'), | |
Input(f'{APP_ID}_plot_button', 'n_clicks'), | |
State(f'{APP_ID}_example_dropdown', 'value'), | |
State(f'{APP_ID}_example_result_dropdown','value'), | |
State(f'{APP_ID}_example_comp_dropdown', 'value'), | |
State(f'{APP_ID}_example_tf_dropdown', 'value') | |
) | |
def dash_vtk_update_grid(n_clicks, example_name, result_name, comp_idx, tf_idx): | |
if any([v is None for v in [example_name, result_name, tf_idx]]): | |
raise PreventUpdate | |
model = dpf.Model(EXAMPLE_MAP[example_name]) | |
result_info = model.metadata.result_info | |
res = next((r for r in result_info.available_results if r.name == result_name), None) | |
mesh = model.metadata.meshed_region | |
if res.n_components == 1: | |
res_op = dpf.Operator(res.operator_name) | |
res_op.inputs.data_sources.connect(model.metadata.data_sources) | |
res_op.inputs.time_scoping([tf_idx+1]) | |
fields = res_op.outputs.fields_container() | |
f0 = fields[0] | |
name = '_'.join(f0.name.split("_")[:-1]) | |
ugrid = get_grid_with_field(mesh, f0) | |
mesh_state = to_mesh_state(ugrid.copy(), field_to_keep=name) | |
elif res.n_components > 1: | |
res_op = dpf.Operator(res.operator_name) | |
res_op.inputs.data_sources.connect(model.metadata.data_sources) | |
res_op.inputs.time_scoping([tf_idx+1]) | |
comp_sel = dpf.operators.logic.component_selector_fc() | |
comp_sel.inputs.connect(res_op.outputs) | |
comp_sel.inputs.component_number.connect(comp_idx) | |
fields = comp_sel.outputs.fields_container() | |
f0 = fields[0] | |
name = '_'.join(f0.name.split("_")[:-1]) | |
ugrid = get_grid_with_field(mesh, f0) | |
mesh_state = to_mesh_state(ugrid.copy(), field_to_keep=name) | |
else: | |
raise PreventUpdate | |
view_max = ugrid[name].max() | |
view_min = ugrid[name].min() | |
rng = [view_min, view_max] | |
name = '_'.join(f0.name.split("_")[:-1]) | |
fig = make_colorbar(name, rng) | |
dt = [{'index':'Max', 'model':view_max}, {'index':'Min', 'model':view_min}] | |
return [dash_vtk.Mesh(state=mesh_state), rng, fig, dt] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment