-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds png plotting to each step (#148)
* adds png plotting to each step * adds step to plot original reconstruction
- Loading branch information
1 parent
c710e74
commit 9577f70
Showing
6 changed files
with
202 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os | ||
|
||
import matplotlib.pyplot as plt | ||
import boto3 | ||
|
||
from neuron_morphology.morphology import Morphology | ||
from neuron_morphology.swc_io import (morphology_from_swc, morphology_to_swc) | ||
|
||
|
||
s3 = boto3.client("s3") | ||
|
||
|
||
def collect_morphology(bucket: str, | ||
swc_key: str): | ||
swc_response = s3.get_object(Bucket=bucket, | ||
Key=swc_key, | ||
) | ||
return morphology_from_swc(swc_response["Body"]) | ||
|
||
|
||
def morphology_to_s3(bucket: str, key: str, morphology: Morphology): | ||
"""Store morphology in an s3 bucket as swc | ||
Parameters | ||
---------- | ||
bucket : name of the bucket in which to store this dataset | ||
key : at which to store the dataset | ||
morphology : The morphology to store | ||
Returns | ||
------- | ||
key : the argued key | ||
Notes | ||
----- | ||
we must write morphology to "disk" temporarily and send that. | ||
""" | ||
tmp_path = key.split("/")[-1] | ||
morphology_to_swc(morphology, tmp_path) | ||
|
||
s3.upload_file(Filename=tmp_path, Bucket=bucket, Key=key) | ||
os.remove(tmp_path) | ||
return key | ||
|
||
|
||
def morphology_png_to_s3(bucket: str, | ||
key: str, | ||
morphology: Morphology): | ||
|
||
tmp_path = key.split("/")[-1] | ||
|
||
nodes = morphology.nodes() | ||
x = [node['x'] for node in nodes] | ||
y = [node['y'] for node in nodes] | ||
z = [node['z'] for node in nodes] | ||
|
||
fig, ax = plt.subplots(1, 2) | ||
ax[0].scatter(x, y, s=0.1) | ||
ax[0].set_title('x-y view') | ||
ax[1].scatter(z, y, s=0.1) | ||
ax[1].set_title('z-y view') | ||
fig.suptitle(tmp_path[:-4], fontsize=16) | ||
fig.savefig(tmp_path) | ||
|
||
s3.upload_file(Filename=tmp_path, Bucket=bucket, Key=key) | ||
os.remove(tmp_path) | ||
return key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
import json | ||
from typing import Optional | ||
|
||
import boto3 | ||
|
||
from command_utils import collect_morphology, morphology_png_to_s3 | ||
from harness import step_fns_ecs_harness | ||
|
||
s3 = boto3.client("s3") | ||
|
||
|
||
def plot_original(token: Optional[str] = None): | ||
reconstruction_id = os.environ["RECONSTRUCTION_ID"] | ||
working_bucket = os.environ["WORKING_BUCKET"] | ||
run_prefix = os.environ["RUN_PREFIX"] | ||
|
||
input_json_key = f"{run_prefix}/{reconstruction_id}.json" | ||
input_json_response = s3.get_object(Bucket=working_bucket, | ||
Key=input_json_key | ||
) | ||
|
||
input_data = json.load(input_json_response["Body"]) | ||
|
||
swc_key = f"{run_prefix}/{input_data['swc_file']}" | ||
morphology = collect_morphology(working_bucket, swc_key) | ||
return { | ||
"original_png_key": morphology_png_to_s3( | ||
working_bucket, | ||
f"{run_prefix}/original_morphology.png", | ||
morphology) | ||
} | ||
|
||
|
||
def main(): | ||
step_fns_ecs_harness(plot_original) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters