Skip to content

Commit

Permalink
fix(scripts): keep folder structure of input for processed folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Oli4 committed Jan 31, 2022
1 parent c76b306 commit bb6bcef
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 149 deletions.
6 changes: 4 additions & 2 deletions octseg/scripts/commands/drusen.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def drusen(ctx: click.Context, drusen_threshold, overwrite):
# Load data
data = data_readers[datatype](path)
# Read layers
layers_filepath = output_path / path.stem / "layers.pkl"
output_dir = output_path / path.relative_to(input_path).parent / path.stem
layers_filepath = output_dir / "layers.pkl"
try:
with open(layers_filepath, "rb") as myfile:
layers = pickle.load(myfile)
Expand All @@ -78,7 +79,8 @@ def drusen(ctx: click.Context, drusen_threshold, overwrite):
# Compute drusen
drusen = drusen2d(data.layers["RPE"], data.layers["BM"], data.shape)
clean_drusen = filter_by_height(drusen, minimum_height=drusen_threshold)
drusen_filepath = output_path / path.stem / "drusen.pkl"
output_dir = output_path / path.relative_to(input_path).parent / path.stem
drusen_filepath = output_dir / "drusen.pkl"
with open(drusen_filepath, "wb") as myfile:
pickle.dump(clean_drusen, myfile)

Expand Down
2 changes: 1 addition & 1 deletion octseg/scripts/commands/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def layers(ctx: click.Context, model_id, overwrite, gpu):
# Predict layers
data = get_layers(data, model_id)
# Save predicted layers
output_dir = output_path / path.stem
output_dir = output_path / path.relative_to(input_path).parent / path.stem
output_dir.mkdir(parents=True, exist_ok=True)
with open(output_dir / ("layers.pkl"), "wb") as myfile:
pickle.dump(data.layers, myfile)
Expand Down
13 changes: 10 additions & 3 deletions octseg/scripts/commands/plot_bscans.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ def plot_bscans(ctx: click.Context, drusen, layers, volumes):
# Load data
data = data_readers[datatype](path)
# Load layers and drusen
layers_filepath = output_path / path.stem / "layers.pkl"
drusen_filepath = output_path / path.stem / "drusen.pkl"
output_dir = output_path / path.relative_to(input_path).parent / path.stem
layers_filepath = output_dir / "layers.pkl"
drusen_filepath = output_dir / "drusen.pkl"

try:
with open(layers_filepath, "rb") as myfile:
Expand All @@ -89,7 +90,13 @@ def plot_bscans(ctx: click.Context, drusen, layers, volumes):
bscan.layers[key] = heights
data._drusen = drusen_data

save_path = output_path / "plots" / "bscans" / path.stem
save_path = (
output_path
/ "plots"
/ "bscans"
/ path.relative_to(input_path).parent
/ path.stem
)
save_path.mkdir(parents=True, exist_ok=True)
for bscan in tqdm(data):
bscan.plot(drusen=drusen, layers=layers)
Expand Down
13 changes: 10 additions & 3 deletions octseg/scripts/commands/plot_enface.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ def plot_enface(ctx: click.Context, drusen, bscan_area, bscan_positions):
# Load data
data = data_readers[datatype](path)
# Load layers and drusen
layers_filepath = output_path / path.stem / "layers.pkl"
drusen_filepath = output_path / path.stem / "drusen.pkl"
output_dir = output_path / path.relative_to(input_path).parent / path.stem
layers_filepath = output_dir / "layers.pkl"
drusen_filepath = output_dir / "drusen.pkl"

try:
with open(layers_filepath, "rb") as myfile:
Expand All @@ -69,7 +70,13 @@ def plot_enface(ctx: click.Context, drusen, bscan_area, bscan_positions):
bscan.layers[key] = heights
data._drusen = drusen_data

save_path = output_path / "plots" / "enface"
save_path = (
output_path
/ "plots"
/ "enface"
/ path.relative_to(input_path).parent
/ path.stem
)
save_path.mkdir(parents=True, exist_ok=True)

if not bscan_positions:
Expand Down
5 changes: 3 additions & 2 deletions octseg/scripts/commands/quantify.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ def quantify(ctx: click.Context, radii, sectors, offsets):
# Load data
data = data_readers[datatype](path)
# Read layers
layers_filepath = output_path / path.stem / "layers.pkl"
drusen_filepath = output_path / path.stem / "drusen.pkl"
output_dir = output_path / path.relative_to(input_path).parent / path.stem
layers_filepath = output_dir / "layers.pkl"
drusen_filepath = output_dir / "drusen.pkl"

try:
with open(layers_filepath, "rb") as myfile:
Expand Down
Loading

0 comments on commit bb6bcef

Please sign in to comment.