Example #1
0
def particles_hist_api_route(database, table):
    databases = particles_databases()
    if not database in databases or not table in databases[database]:
        return api(error="Invalid database or table")

    filt = flask.request.form.get("filt", "")
    if not sql_filt_valid(filt):
        return api(error="Invalid parameters")
    elif filt:
        filt = " WHERE " + filt

    sql = "SELECT Z, EquivDiam FROM `{}`.`{}`{};".format(database, table, filt)
    try:
        rows = database_inst().select(sql)
    except:
        return api(error="SQL error")

    Z, D = [], []
    for row in rows:
        Z.append(row["Z"])
        D.append(row["EquivDiam"])
    Z, D = np.array(Z), np.array(D)

    ND, binsD = np.histogram(D, bins=100)
    NZ, binsZ = np.histogram(Z, bins=100)
    return api({
        "hist": {
            "diam": {
                "N": ND.tolist(),
                "bins": binsD.tolist()
            },
            "z": {
                "N": NZ.tolist(),
                "bins": binsZ.tolist()
            }
        }
    })
Example #2
0
def render(tmpl, **kwargs):
    kwargs["particles_databases"] = particles_databases()
    kwargs["stats_databases"] = stats_databases()
    return flask.render_template(tmpl, **kwargs)
Example #3
0
def particles_hist_route(database, table):
    databases = particles_databases()
    if not database in databases or not table in databases[database]:
        flask.abort(404)
    return render("histograms.htm", database=database, table=table)
Example #4
0
def particles_images_api_route(database, table):
    databases = particles_databases()
    if not database in databases or not table in databases[database]:
        return api(error="Invalid database or table")

    try:
        perpage = int(flask.request.form.get("perpage", 50))
        page = int(flask.request.form.get("page", 0))
        orderby = flask.request.form.get("order_key", "ID")
        order = flask.request.form.get("order", "DESC")
        if not order.upper() in ["ASC", "DESC"]:
            raise Exception()
        filt = flask.request.form.get("filt", "")
        if not sql_filt_valid(filt):
            raise Exception()
        elif filt:
            filt = " WHERE " + filt
    except:
        return api(error="Invalid parameters")

    sql = "SELECT * FROM `{}`.`{}`{} ORDER BY {} {} LIMIT {} OFFSET {};".format(
        database, table, filt, orderby, order, perpage, perpage * page)
    try:
        rows = database_inst().select(sql, cls=ParticlesRow)
    except:
        return api(error="SQL error")

    particles = []
    root = flask.url_for("particles_files_route",
                         database=database,
                         table=table,
                         img="")
    root_recon = root + "recon"
    root_threshold = root + "threshold"
    root_preview = root + "preview"
    ext_res, ext_res_lossy = None, None
    for row in rows:
        if ext_res is None or ext_res_lossy is None:
            ext_res, ext_res_lossy = find_ext(database, table, row)
            if ext_res is None or ext_res_lossy is None:
                return api(error="Image files not found")

        file = row.file()
        file.sub = 0
        file_sub = row.file()
        particles.append({
            "id":
            row.ID,
            "datetime":
            row.DateTime.strftime("%Y-%m-%d %H:%M:%S"),
            "x":
            row.X,
            "y":
            row.Y,
            "z":
            row.Z,
            "diam":
            row.EquivDiam,
            "diamcorr":
            row.EquivDiamCorr,
            "circ":
            row.Circularity,
            "dynrange":
            row.DynRange,
            "effpxsz":
            row.EffPxSz,
            "img":
            file_sub.path(root=root_recon, ext=ext_res, sep="/"),
            "imgth":
            file_sub.path(root=root_threshold, ext=ext_res, sep="/"),
            "imgprev":
            file.path(root=root_preview, ext=ext_res_lossy, sep="/")
        })
    return api({"page": page, "particles": particles})