示例#1
0
def update_output(date, session_id, user_id):
    """ The callback is used to load a new image when the date has changed.
        Date change can be triggered by the date selector box or indirectly by the arrow buttons,
        which change the date selector box.
        Besides loading images, this callback loads the annotation from the current user session
        and the annotations from the folder.
    
    Arguments:
        date {[type]} -- [description]
        session_id {[type]} -- [description]
    
    Raises:
        PreventUpdate: [description]
    
    Returns:
        [type] -- [description]
    """
    global data

    static_label = []
    info_box = "No info"

    if date is not None:
        index = data.index.get_loc(date, method="nearest")

        if isinstance(index, slice):
            index = index.start

        try:
            key = data.iloc[index]["filename"]
            img = imio.imread(io.BytesIO(store[key]))
        except Exception as e:
            print(e)
            info_box = "Error loading the image"
            img = np.zeros(img_shape, dtype="uint8")

        img = img[::img_downsampling, ::img_downsampling, :]
        image_content = array_to_data_url(img)

        # load data from index
        start_and_image = (
            '{"version":"2.4.3","objects":[{"type":"image","version":"2.4.3", "originX":"left","originY":"top","left":0,"top":0,"width":%d,"height":%d,"src":"%s"}'
            % (img.shape[1], img.shape[0], image_content))

        # load local annotations if exist
        datetime = data.index[index]
        file_id = datetime.strftime("%Y%m%d_%H%M%S")
        try:
            df = read_csv(session_id, file_id, user_id)
        except Exception as e:
            print('Could not read annotation file', e)
            df = None

        # Load the annotations from the server
        try:
            global_df = stuett.read_csv_with_store(annotation_store,
                                                   "annotations.csv")
            global_df = global_df[stuett.to_datetime(global_df["start_time"])
                                  == datetime]
            df = pd.concat([global_df, df])
        except Exception as e:
            print(e)

        # create the data that is passed to dash_canvas
        rectangles = [""]
        if df is not None:
            rects = []
            for i, row in df.iterrows():
                if row["__target"] in static_label_mapping:
                    if row["__target"] not in static_label:
                        static_label.append(row["__target"])

                left = row["start_x"]
                top = row["start_y"]
                right = row["end_x"]
                bottom = row["end_y"]

                if left is None or pd.isnull(left):
                    continue

                label = static_label_mapping[str(row["__target"])]
                if label not in bb_label_reverse_mapping:
                    continue
                stroke = bb_label_reverse_mapping[label]
                rect = (
                    ',{"type":"rect","version":"2.4.3","originX":"left","transparentCorners":false,"originY":"top","left":%f,"top":%f,"right":%f,"bottom":%f,"width":0,"height":0,"fill":"transparent","stroke":"%s","strokeWidth":2}'
                    % (left, top, right, bottom, stroke))

                rects.append(rect)

            if rects:
                rectangles = rects

        end_objects = "]}"

        string = [start_and_image]
        string += rectangles
        string += [end_objects]

        json_data = "".join(string)

        return json_data, index, str(datetime), static_label

    raise PreventUpdate
示例#2
0
            prefix="",
            account_name=account_name,
            account_key=account_key,
        )
else:
    input_store = stuett.DirectoryStore(args.user_annotations)
    output_store = stuett.DirectoryStore(annotations_path)

print(args.user_annotations)

annotation_dict = {}
for key in input_store.keys():
    fn = Path(key)
    if fn.suffix != ".csv":
        continue
    df = stuett.read_csv_with_store(input_store, key, dict(nrows=3))
    df["__session"] = str(fn.parent)
    filename = fn.name
    if filename not in annotation_dict:
        annotation_dict[filename] = {
            "key": key,
            "modif_ts": pd.to_datetime(df["__creation_time"].iloc[0]),
        }
    else:
        current_time = annotation_dict[filename]["modif_ts"]
        new_time = pd.to_datetime(df["__creation_time"].iloc[0])
        if new_time > current_time:
            print("Newer annotation found for %s. Replace in dict" % file_name)
            annotation_dict[filename] = annotation_dict[filename] = {
                "key": key,
                "modif_ts": new_time,
示例#3
0
def read_csv(session_id, file_id, user_id=None):
    global local_store
    filename = session_id + "-" + str(user_id) + f"/{file_id}.csv"
    return stuett.read_csv_with_store(local_store, filename)
    )
    account_key = (
        get_setting("azure")["account_key"] if setting_exists("azure") else None
    )
    annotation_store = stuett.ABSStore(
        container="hackathon-on-permafrost",
        prefix="annotations",
        account_name=account_name,
        account_key=account_key,
        blob_service_kwargs={},
    )
else:
    annotation_store = stuett.DirectoryStore(annotations_path)


df = stuett.read_csv_with_store(annotation_store, "automatic_labels_mountaineers.csv")
df['start_time'] = pd.to_datetime(df['start_time'] )
df['end_time'] = pd.to_datetime(df['end_time'] )
df.index = df['start_time']
df = df['2017-08-01':'2017-08-02']


fig = go.Figure(
    layout=dict(
        xaxis={"type": "date"},
        xaxis_range=[
            pd.to_datetime("2017-08-01"),
            pd.to_datetime("2017-08-02"),
        ],
    )
)