Esempio n. 1
0
def get_shape_width_sid(sid):
    shape = blcontrol.beamline.sample_view.get_shape(sid)

    if shape is not None:
        shape = shape.as_dict()
        return {"shape": to_camel(shape)}

    return shape
Esempio n. 2
0
def get_shapes():
    shape_dict = {}

    for shape in blcontrol.beamline.sample_view.get_shapes():
        s = shape.as_dict()
        shape_dict.update({shape.id: s})

    return {"shapes": to_camel(shape_dict)}
Esempio n. 3
0
def send_shapes(update_positions=False, movable={}):

    shape_dict = {}
    for shape in blcontrol.shapes.get_shapes():
        if update_positions:
            shape.update_position(blcontrol.diffractometer.motor_positions_to_screen)

        s = to_camel(shape.as_dict())
        shape_dict.update({shape.id: s})

    socketio.emit("update_shapes", {"shapes": shape_dict}, namespace="/hwr")
Esempio n. 4
0
def send_shapes(update_positions=False, movable={}):

    shape_dict = {}
    for shape in blcontrol.beamline.sample_view.get_shapes():
        if update_positions:
            shape.update_position(
                blcontrol.beamline.diffractometer.motor_positions_to_screen)

        s = to_camel(shape.as_dict())
        shape_dict.update({shape.id: s})

    socketio.emit("update_shapes", {"shapes": shape_dict}, namespace="/hwr")
Esempio n. 5
0
def shape_mock_result(sid):
    shape = blcontrol.shapes.get_shape(sid)
    hm = {}
    cm = {}

    if shape:
        from random import random

        for i in range(1, shape.num_rows * shape.num_cols + 1):
            hm[i] = [
                i,
                [
                    int(random() * 255),
                    int(random() * 255),
                    int(random() * 255),
                    int(random()),
                ],
            ]

        for i in range(1, shape.num_rows * shape.num_cols + 1):
            cm[i] = [
                i,
                [
                    int(random() * 255),
                    int(random() * 255),
                    int(random() * 255),
                    int(random()),
                ],
            ]

    res = {"heatmap": hm, "crystalmap": cm}

    blcontrol.shapes.set_grid_data(sid, res)
    signals.grid_result_available(to_camel(shape.as_dict()))

    return Response(status=200)
Esempio n. 6
0
def shape_mock_result(sid):
    shape = blcontrol.beamline.sample_view.camera.get_shape(sid)
    hm = {}
    cm = {}

    if shape:
        from random import random

        for i in range(1, shape.num_rows * shape.num_cols + 1):
            hm[i] = [
                i,
                [
                    int(random() * 255),
                    int(random() * 255),
                    int(random() * 255),
                    int(random()),
                ],
            ]

        for i in range(1, shape.num_rows * shape.num_cols + 1):
            cm[i] = [
                i,
                [
                    int(random() * 255),
                    int(random() * 255),
                    int(random() * 255),
                    int(random()),
                ],
            ]

    res = {"heatmap": hm, "crystalmap": cm}

    blcontrol.beamline.sample_view.camera.set_grid_data(sid, res)
    signals.grid_result_available(to_camel(shape.as_dict()))

    return Response(status=200)
Esempio n. 7
0
def update_shapes(shapes):
    updated_shapes = []

    for s in shapes:
        shape_data = from_camel(s)
        pos = []

        # Get the shape if already exists
        shape = blcontrol.beamline.sample_view.get_shape(
            shape_data.get("id", -1))

        # If shape does not exist add it
        if not shape:
            refs, t = shape_data.pop("refs", []), shape_data.pop("t", "")

            # Store pixels per mm for third party software, to facilitate
            # certain calculations

            beam_info_dict = beam_info_dict = beamlineutils.get_beam_info()

            shape_data[
                "pixels_per_mm"] = blcontrol.beamline.diffractometer.get_pixels_per_mm(
                )
            shape_data["beam_pos"] = (
                beam_info_dict.get("position")[0],
                beam_info_dict.get("position")[1],
            )
            shape_data["beam_width"] = beam_info_dict.get("size_x", 0)
            shape_data["beam_height"] = beam_info_dict.get("size_y", 0)

            # Shape does not have any refs, create a new Centered position
            if not refs:
                x, y = shape_data["screen_coord"]
                mpos = blcontrol.beamline.diffractometer.get_centred_point_from_coord(
                    x, y, return_by_names=True)
                pos.append(mpos)

                # We also store the center of the grid
                if t == "G":
                    # coords for the center of the grid
                    x_c = x + (shape_data["num_cols"] /
                               2.0) * shape_data["cell_width"]
                    y_c = y + (shape_data["num_rows"] /
                               2.0) * shape_data["cell_height"]
                    center_positions = blcontrol.beamline.diffractometer.get_centred_point_from_coord(
                        x_c, y_c, return_by_names=True)
                    pos.append(center_positions)

                shape = blcontrol.beamline.sample_view.add_shape_from_mpos(
                    pos, (x, y), t)

            else:
                shape = blcontrol.beamline.sample_view.add_shape_from_refs(
                    refs, t)

        # shape will be none if creation failed, so we check if shape exists
        # before setting additional parameters
        if shape:
            shape.update_from_dict(shape_data)
            shape_dict = to_camel(shape.as_dict())
            updated_shapes.append(shape_dict)

    return {"shapes": updated_shapes}
Esempio n. 8
0
def shape_add_cell_result(sid, cell, result):
    from mxcube3.routes import signals

    shape = blcontrol.beamline.sample_view.get_shape(sid)
    shape.set_cell_result(cell, result)
    signals.grid_result_available(to_camel(shape.as_dict()))
Esempio n. 9
0
def handle_grid_result(shape):
    from mxcube3.routes import signals

    signals.grid_result_available(to_camel(shape.as_dict()))