danforthcenter / plantcv

Plant phenotyping with image analysis
Mozilla Public License 2.0
661 stars 264 forks source link

Question about coverting outputs json to csv after following multi plant image processing tutorial #1459

Open tatum-milana opened 8 months ago

tatum-milana commented 8 months ago

Good afternoon everyone, I followed the tutorial for multi plant image processing located at this link (https://plantcv.readthedocs.io/en/stable/tutorials/multi-plant_tutorial/) .

At the end of the code, it runs analysis_image = pcv.analyze.size(img=rotate_img, labeled_mask=labeled_objects2, n_labels=n_obj2) pcv.outputs.save_results(filename=args.result)

From here, I want to save the resulting json file as a csv file, but I have been running into many issues. I have tried running plantcv.utils.json2csv; but was met with an error saying that the json was not properly formatted , so I tried running plantcv.parallel.process_results before the conversion command and I got errors saying the json file was missing a metadata key. Any ideas on the best way to convert to CSV file after following the multi plant image processing tutorial?

thank you in advance!

nfahlgren commented 8 months ago

Hi @tatum-milana, in principle the process_results approach should have worked, I am not certain why it produced an error about a metadata key. The intermediate JSON files (produced by pcv.outputs.save_results are not compatible with json2csv because it works on the JSON file produced at the end of a batch analysis using the tool plantcv-run-workflow.

What could work for you instead is to directly output CSV, which can only be done in Jupyter or a single script analysis (not in batch/parallel). To do that you would change the save results command to:

pcv.outputs.save_results(filename=args.result, outformat="csv")