Пример #1
0
def driver(host,
           token,
           col,
           exp,
           z_range,
           y_range,
           x_range,
           path="./results/"):

    print("Generating PyMeda Plots...")
    info = locals()
    data_dict = get_data(host, token, col, exp, z_range, y_range, x_range)

    results = run_nomads(data_dict)

    results_key = "_".join(["nomads", col, exp, "z", str(z_range[0]), str(z_range[1]), "y", \
    str(y_range[0]), str(y_range[1]), "x", str(x_range[0]), str(x_range[1])])

    pickle.dump(results, open(path + results_key + ".pkl", "wb"))
    print("Saved pickled results (np array) {} in {}".format(
        results_key, path))

    title = "PyMeda Plots on {}".format(exp)
    pymeda_driver.pymeda_pipeline(results, data_dict, title=title, path=path)

    upload_results(path, results_key)
    return info, results
Пример #2
0
def driver(bucket, host, token, col, exp, z_range, y_range, x_range, path = "./results/"):
    print("Starting Nomads Unsupervised...")
    results_key = "_".join(["nomads-unsupervised", col, exp, "z", str(z_range[0]), str(z_range[1]), "y", \
    str(y_range[0]), str(y_range[1]), "x", str(x_range[0]), str(x_range[1])])

    info = locals()
    try:
        data_dict = get_data(host, token, col, exp, z_range, y_range, x_range)
    except Exception as e:
        logging.info("Failed to pull data from BOSS. Run with smaller cube of data or check if BOSS is online.")
        logging.info(e)
        logging.info("Exiting...")
        upload_results(bucket, path, results_key)
        print_exc()
        return

    try:
        results = run_nomads(data_dict)
    except Exception as e:
        logging.info("Failed to run Nomads-Unsupervised detection algorithm on data.")
        logging.info(e)
        logging.info("Exiting...")
        upload_results(bucket, path, results_key)
        print_exc()
        return

    results = results.astype(np.uint8)
    np.putmask(results, results, 255)


    pickle.dump(results, open(path + "nomads-unsupervised-predictions" + ".pkl", "wb"))
    print("Saved pickled results (np array) {} in {}".format("nomads-unsupervised-predictions.pkl", path))
    norm_data = load_and_preproc(data_dict)


    try:
        pymeda_driver.pymeda_pipeline(results, norm_data, title = "PyMeda Plots on All Predicted Synapses", path = path)
    except:
        logging.info("Failed to generate plots for all predictions. No synapses detected.")

    print("Uploading results...")
    #results = pickle.load(open("./results/nomads-unsupervised-predictions.pkl", "rb"))
    try:
        boss_links = boss_push(token, "collman_nomads", "nomads_predictions", z_range, y_range, x_range, {results_key: results}, results_key)
        with open('results/NDVIS_links.csv', 'w') as csv_file:
            writer = csv.writer(csv_file)
            for key, value in boss_links.items():
                writer.writerow([key, value])
    except Exception as e:
        logging.info("Failed to push results to BOSS. Check permissions and Boss online status.")
        logging.info(e)

    logging.info("Finished job, uploading results. END")

    upload_results(bucket, path, results_key)

    return info, results, boss_links
Пример #3
0
def driver(host,
           token,
           col,
           exp,
           z_range,
           y_range,
           x_range,
           path="./results/"):

    print("Starting Nomads Unsupervised...")
    info = locals()
    data_dict, voxel_size = get_data(host, token, col, exp, z_range, y_range,
                                     x_range)

    results = run_nomads(data_dict)
    results = results.astype(np.uint8)
    np.putmask(results, results, 255)

    results_key = "_".join(["nomads-unsupervised", col, exp, "z", str(z_range[0]), str(z_range[1]), "y", \
    str(y_range[0]), str(y_range[1]), "x", str(x_range[0]), str(x_range[1])])

    pickle.dump(results,
                open(path + "nomads-unsupervised-predictions" + ".pkl", "wb"))
    print("Saved pickled results (np array) {} in {}".format(
        "nomads-unsupervised-predictions.pkl", path))

    print("Generating PyMeda Plots...")

    norm_data = load_and_preproc(data_dict)
    try:
        pymeda_driver.pymeda_pipeline(
            results,
            norm_data,
            title="PyMeda Plots on All Predicted Synapses",
            path=path)
    except:
        print(
            "Not generating plots for all synapses, no predictions classified as Gaba"
        )
    print("Uploading results...")
    #results = pickle.load(open("./results/nomads-unsupervised-predictions.pkl", "rb"))

    boss_links = boss_push(token, "collman_nomads", "nomads_predictions",
                           z_range, y_range, x_range, {results_key: results},
                           results_key)
    with open('results/NDVIS_links.csv', 'w') as csv_file:
        writer = csv.writer(csv_file)
        for key, value in boss_links.items():
            writer.writerow([key, value])
    upload_results(path, results_key)

    return info, results, boss_links
Пример #4
0
def driver(bucket,
           host,
           token,
           col,
           exp,
           z_range,
           y_range,
           x_range,
           path="./results/"):
    print("Starting Nomads Classifier...")
    results_key = "_".join(["nomads-classifier", col, exp, "z", str(z_range[0]), str(z_range[1]), "y", \
    str(y_range[0]), str(y_range[1]), "x", str(x_range[0]), str(x_range[1])])

    info = locals()
    try:
        data_dict = get_data(host, token, col, exp, z_range, y_range, x_range)
    except Exception as e:
        logging.info(
            "Failed to pull data from BOSS. Run with smaller cube of data or check if BOSS is online."
        )
        logging.info(e)
        logging.info("Exiting...")
        upload_results(bucket, path, results_key)
        print_exc()
        return

    try:
        results = run_nomads(data_dict)
    except Exception as e:
        logging.info(
            "Failed to run Nomads-Unsupervised detection algorithm on data.")
        logging.info(e)
        logging.info("Exiting...")
        upload_results(bucket, path, results_key)
        print_exc()
        return

    results = results.astype(np.uint8)
    np.putmask(results, results, 255)

    pickle.dump(results,
                open(path + "nomads-unsupervised-predictions" + ".pkl", "wb"))
    print("Saved pickled predictions (np array) {} in {}".format(
        "nomads-unsupervised-predictions.pkl", path))

    norm_data = load_and_preproc(data_dict)

    try:
        #results = pickle.load(open("results/nomads-unsupervised-predictions.pkl", "rb"))
        connected_components, label_vol = pymeda_driver.label_predictions(
            results)
        synapse_centroids = pymeda_driver.calculate_synapse_centroids(
            connected_components)
        class_list = gaba_classifier_pipeline(data_dict, synapse_centroids)
        no_pred_vol, non_gaba_vol, gaba_vol = split_vol_by_id(
            label_vol, class_list, 3)
    except Exception as e:
        logging.info("Failed to run Nomads-Classfier algorithm on data.")
        logging.info(e)
        logging.info("Exiting...")
        upload_results(bucket, path, results_key)
        print_exc()
        return

    gaba_vol = gaba_vol.astype(np.uint8)
    np.putmask(gaba_vol, gaba_vol, 255)
    non_gaba_vol = non_gaba_vol.astype(np.uint8)
    np.putmask(non_gaba_vol, non_gaba_vol, 255)

    pickle.dump(gaba_vol, open(path + "gaba" + ".pkl", "wb"))
    print("Saved pickled gaba (np array) {} in {}".format("gaba.pkl", path))
    pickle.dump(non_gaba_vol, open(path + "non_gaba" + ".pkl", "wb"))
    print("Saved pickled gaba (np array) {} in {}".format(
        "non_gaba.pkl", path))

    try:
        pymeda_driver.pymeda_pipeline(
            results,
            norm_data,
            title="PyMeda Plots on All Predicted Synapses",
            path=path)
    except:
        logging.info(
            "Failed to generate plots for all predictions. No synapses detected."
        )
    try:
        pymeda_driver.pymeda_pipeline(
            non_gaba_vol,
            norm_data,
            title="PyMeda Plots on Predicted NonGaba Synapses",
            path=path)
    except:
        logging.info(
            "PyMeda failed to generate plots for NonGaba. No Non-Gaba synapses found."
        )
    try:
        pymeda_driver.pymeda_pipeline(
            gaba_vol,
            norm_data,
            title="PyMeda Plots on Predicted Gaba Synapses",
            path=path)
    except:
        logging.info(
            "PyMeda failed to generate plots for Gaba. No Gaba synapses found."
        )

    print("Uploading results...")
    results_dict = {"All": results, "Gaba": gaba_vol, "NonGaba": non_gaba_vol}
    try:
        boss_links = boss_push(token, "collman_nomads", "nomads_predictions",
                               z_range, y_range, x_range, results_dict,
                               results_key)
        with open('results/NDVIS_links.csv', 'w') as csv_file:
            writer = csv.writer(csv_file)
            for key, value in boss_links.items():
                writer.writerow([key, value])
    except Exception as e:
        logging.info(
            "Failed to push results to BOSS. Check permissions and Boss online status."
        )
        logging.info(e)

    logging.info("Finished, uploading results. END")

    upload_results(bucket, path, results_key)

    return info, results, boss_links