File size: 1,087 Bytes
3e2d18e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import json
import os
from itertools import chain
from dotenv import load_dotenv
import pandas as pd
def to_relative_focus(stack):
best_index = stack["best_index"]
images = stack["images"]
best_value = images[best_index]["focus_value"]
for i in range(len(images)):
images[i]["focus_value"] = images[i]["focus_value"] - best_value
return stack
def flatten_stack(stack):
images = stack["images"]
def f(image):
del image["neighbours"]
image["stack_id"] = stack["stack_id"]
image["obj_name"] = stack["obj_name"]
return image
images = list(map(f, images))
return images
if __name__ == "__main__":
load_dotenv()
data_file = os.getenv('DATA_FILE')
out_file = os.getenv('OUT_FILE')
with open(data_file) as f:
content = json.load(f)
annotated = filter(lambda x: x["best_index"], content)
relative_focus = map(to_relative_focus, annotated)
flattened = chain(*map(flatten_stack,relative_focus))
dataframe = pd.DataFrame(flattened)
dataframe.to_csv(out_file)
|