|
| 1 | +import logging |
| 2 | + |
| 3 | +import pandas as pd |
| 4 | +from flask import Blueprint, current_app, render_template, session |
| 5 | + |
| 6 | +import synanno.backend.ng_util as ng_util |
| 7 | +from synanno import initialize_global_variables |
| 8 | +from synanno.backend.processing import ( |
| 9 | + calculate_number_of_pages_for_neuron_section_based_loading, |
| 10 | + determine_volume_dimensions, |
| 11 | + load_cloud_volumes, |
| 12 | +) |
| 13 | +from synanno.routes.opendata import ( |
| 14 | + calculate_scale_factor, |
| 15 | + handle_neuron_view, |
| 16 | + set_coordinate_resolution, |
| 17 | +) |
| 18 | + |
| 19 | +logging.basicConfig(level="INFO") |
| 20 | +logger = logging.getLogger(__name__) |
| 21 | + |
| 22 | +blueprint = Blueprint("demo", __name__) |
| 23 | + |
| 24 | + |
| 25 | +@blueprint.route("/demo", methods=["GET"]) |
| 26 | +def demo(): |
| 27 | + """Displays a loading page and resets the session storage. |
| 28 | +
|
| 29 | + Returns: |
| 30 | + Renders the loading page. |
| 31 | + """ |
| 32 | + |
| 33 | + # Reset logic |
| 34 | + session.clear() |
| 35 | + initialize_global_variables(current_app) |
| 36 | + |
| 37 | + return render_template("demo_setup.html", next_route="/demo_annotation") |
| 38 | + |
| 39 | + |
| 40 | +@blueprint.route("/demo_annotation", methods=["GET"]) |
| 41 | +def demo_init(): |
| 42 | + """Initializes the demo data and renders the annotation view. |
| 43 | +
|
| 44 | + Returns: |
| 45 | + Renders the annotation view after initializing the demo data. |
| 46 | + """ |
| 47 | + # Upload logic |
| 48 | + current_app.view_style = "view_style" |
| 49 | + current_app.tiles_per_page = 12 |
| 50 | + |
| 51 | + current_app.crop_size_x = 256 |
| 52 | + current_app.crop_size_y = 256 |
| 53 | + current_app.crop_size_z = 6 |
| 54 | + |
| 55 | + current_app.coordinate_order = {"x": (4, 8), "y": (4, 8), "z": (33, 33)} |
| 56 | + |
| 57 | + source_url = "gs://h01-release/data/20210601/4nm_raw" |
| 58 | + target_url = "gs://h01-release/data/20210729/c3/synapses/whole_ei_onlyvol" |
| 59 | + neuropil_url = "gs://h01-release/data/20210601/proofread_104" |
| 60 | + |
| 61 | + current_app.synapse_data = pd.read_csv("/app/h01/h01_104_materialization.csv") |
| 62 | + |
| 63 | + load_cloud_volumes(source_url, target_url, neuropil_url, "~/.cloudvolume/secrets") |
| 64 | + |
| 65 | + current_app.vol_dim = determine_volume_dimensions() |
| 66 | + |
| 67 | + set_coordinate_resolution() |
| 68 | + calculate_scale_factor() |
| 69 | + |
| 70 | + current_app.vol_dim_scaled = tuple( |
| 71 | + int(a * b) for a, b in zip(current_app.vol_dim, current_app.scale.values()) |
| 72 | + ) |
| 73 | + |
| 74 | + current_app.selected_neuron_id = 2325998949 |
| 75 | + |
| 76 | + handle_neuron_view(neuropil_url) |
| 77 | + current_app.neuron_ready = "true" |
| 78 | + current_app.n_pages = calculate_number_of_pages_for_neuron_section_based_loading() |
| 79 | + |
| 80 | + if current_app.ng_version is None: |
| 81 | + ng_util.setup_ng( |
| 82 | + app=current_app._get_current_object(), |
| 83 | + source="precomputed://" + source_url, |
| 84 | + target="precomputed://" + target_url, |
| 85 | + neuropil="precomputed://" + neuropil_url, |
| 86 | + ) |
| 87 | + |
| 88 | + page = 1 |
| 89 | + return render_template( |
| 90 | + "annotation.html", |
| 91 | + page=page, |
| 92 | + n_pages=current_app.n_pages, |
| 93 | + grid_opacity=current_app.grid_opacity, |
| 94 | + neuron_id=current_app.selected_neuron_id, |
| 95 | + neuronReady=current_app.neuron_ready, |
| 96 | + neuronSections=current_app.sections, |
| 97 | + synapsePointCloud=current_app.snapped_point_cloud, |
| 98 | + activeNeuronSection=( |
| 99 | + current_app.page_section_mapping[page][0] |
| 100 | + if page in current_app.page_section_mapping |
| 101 | + else 0 |
| 102 | + ), |
| 103 | + activeSynapseIDs=current_app.synapse_data.query("page == @page").index.tolist(), |
| 104 | + ) |
0 commit comments