plantcv: invalid json

Finally catching up to development. I initialized a test project to get pipelines going. I can run a PSII pipeline with one image pair. I ran

scripts/psii.py -i1 "data\psII\A1-SILK_dark-2018-12-10 20_01_50-PSII0_1_0_0.tif" -i2 "data\psII\A1-SILK_dark-2018-12-10 20_01_50-PSII0_2_0_0.tif" -o debug -D print -writeimg True -r results.json

which spit out results.json, but when i try to convert it to a csv i get an error:

(test-environment) 
Dominik Schneider@CPPC1 MINGW64 ~/Documents/phenomics/testpipeline (master)
$ plantcv-utils.py json2csv -j results.json -c result-table
Traceback (most recent call last):
  File "C:/Users/dominikschneider/Miniconda3/envs/test-environment/Scripts/plantcv-utils.py", line 4, in <module>
    __import__('pkg_resources').run_script('plantcv==3.5.0+16.g5b9908c.dirty', 'plantcv-utils.py')
  File "C:\Users\dominikschneider\Miniconda3\envs\test-environment\lib\site-packages\pkg_resources\__init__.py", line 666, in run_script    
    self.require(requires)[0].run_script(script_name, ns)
  File "C:\Users\dominikschneider\Miniconda3\envs\test-environment\lib\site-packages\pkg_resources\__init__.py", line 1453, in run_script   
    exec(code, namespace, namespace)
  File "c:\users\dominikschneider\miniconda3\envs\test-environment\lib\site-packages\plantcv-3.5.0+16.g5b9908c.dirty-py3.7.egg\EGG-INFO\scripts\plantcv-utils.py", line 74, in <module>
    main()
  File "c:\users\dominikschneider\miniconda3\envs\test-environment\lib\site-packages\plantcv-3.5.0+16.g5b9908c.dirty-py3.7.egg\EGG-INFO\scripts\plantcv-utils.py", line 69, in main
    options()
  File "c:\users\dominikschneider\miniconda3\envs\test-environment\lib\site-packages\plantcv-3.5.0+16.g5b9908c.dirty-py3.7.egg\EGG-INFO\scripts\plantcv-utils.py", line 44, in options
    args.func(args)
  File "c:\users\dominikschneider\miniconda3\envs\test-environment\lib\site-packages\plantcv-3.5.0+16.g5b9908c.dirty-py3.7.egg\EGG-INFO\scripts\plantcv-utils.py", line 52, in run_json2csv    plantcv.utils.json2csv(json_file=args.json, csv_file=args.csv)
  File "C:\Users\dominikschneider\Miniconda3\envs\test-environment\lib\site-packages\plantcv-3.5.0+16.g5b9908c.dirty-py3.7.egg\plantcv\utils\converters.py", line 12, in json2csv    raise ValueError("Invalid JSON file: {0}".format(json_file))ValueError: Invalid JSON file: results.json

I took a look at the parallel version for flat files and of course I’ve been labeling my files from lemnabase differently from you. I am using format code {0}-{3}-{1}-{6} which corresponds to plantid-measurement label-timestamp-camera label whereas you have it setup with measurement label and timestamp flipped. Anyway to work on making this more flexible?
Is this going to iterate through every timestamp?

here is my repo: https://github.com/dschneiderch/testpipeline

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (11 by maintainers)

Most upvoted comments

I agree, it would be easier to have temp files saved as .json during parallelization. On my branch I’m working on I had if 'text/plain' in mimetypes.guess_type(filename) or 'application/json' in mimetypes.guess_type(filename): but this can certainly be simplified and ensure that .py scripts, git files, or anything else gets identified as plain text.

Looks like we should name the files with the .json extension so that we can do:

if 'application/json' in mimetypes.guess_type(filename):

That should avoid the overlap with other text files at least.

Ok I figured it out. I had results.txt in the top directory. os.walk() returns everything under job_dir. in my case my .py scripts and git files identified as plaintext and the script was trying to process them. I placed results.txt into output/ and it worked as expected.

Would it be a good idea to add a header line to the json files so they are easy to identify by their first line? Alternatively, you could just check that they are a valid json file.

Hm my presults.json file is as follows:

{"variables": {"in_bounds": {"category": "observations", "datatype": "<class 'bool'>"}, "area": {"category": "observations", "datatype": "<class 'int'>"}, "convex_hull_area": {"category": "observations", "datatype": "<class 'int'>"}, "solidity": {"category": "observations", "datatype": "<class 'float'>"}, "perimeter": {"category": "observations", "datatype": "<class 'int'>"}, "width": {"category": "observations", "datatype": "<class 'int'>"}, "height": {"category": "observations", "datatype": "<class 'int'>"}, "longest_path": {"category": "observations", "datatype": "<class 'int'>"}, "center_of_mass": {"category": "observations", "datatype": "<class 'tuple'>"}, "convex_hull_vertices": {"category": "observations", "datatype": "<class 'int'>"}, "object_in_frame": {"category": "observations", "datatype": "<class 'bool'>"}, "ellipse_center": {"category": "observations", "datatype": "<class 'tuple'>"}, "ellipse_major_axis": {"category": "observations", "datatype": "<class 'int'>"}, "ellipse_minor_axis": {"category": "observations", "datatype": "<class 'int'>"}, "ellipse_angle": {"category": "observations", "datatype": "<class 'float'>"}, "ellipse_eccentricity": {"category": "observations", "datatype": "<class 'float'>"}, "fvfm_hist": {"category": "observations", "datatype": "<class 'list'>"}, "fvfm_hist_peak": {"category": "observations", "datatype": "<class 'float'>"}, "fvfm_median": {"category": "observations", "datatype": "<class 'float'>"}, "fdark_passed_qc": {"category": "observations", "datatype": "<class 'bool'>"}}, "entities": [{"metadata": {}, "observations": {"in_bounds": {"trait": "whether the plant goes out of bounds ", "method": "plantcv.plantcv.within_frame", "scale": "none", "datatype": "<class 'bool'>", "value": true, "label": "none"}, "area": {"trait": "area", "method": "plantcv.plantcv.analyze_object", "scale": "pixels", "datatype": "<class 'int'>", "value": 3949.0, "label": "pixels"}, "convex_hull_area": {"trait": "convex hull area", "method": "plantcv.plantcv.analyze_object", "scale": "pixels", "datatype": "<class 'int'>", "value": 9288.5, "label": "pixels"}, "solidity": {"trait": "solidity", "method": "plantcv.plantcv.analyze_object", "scale": "none", "datatype": "<class 'float'>", "value": 0.42514937826344407, "label": "none"}, "perimeter": {"trait": "perimeter", "method": "plantcv.plantcv.analyze_object", "scale": "pixels", "datatype": "<class 'int'>", "value": 673.7543950080872, "label": "pixels"}, "width": {"trait": "width", "method": "plantcv.plantcv.analyze_object", "scale": "pixels", "datatype": "<class 'int'>", "value": 104, "label": "pixels"}, "height": {"trait": "height", "method": "plantcv.plantcv.analyze_object", "scale": "pixels", "datatype": "<class 'int'>", "value": 155, "label": "pixels"}, "longest_path": {"trait": "longest path", "method": "plantcv.plantcv.analyze_object", "scale": "pixels", "datatype": "<class 'int'>", "value": 972, "label": "pixels"}, "center_of_mass": {"trait": "center of mass", "method": "plantcv.plantcv.analyze_object", "scale": "none", "datatype": "<class 'tuple'>", "value": [282.00936946062296, 220.4937958976956], "label": "none"}, "convex_hull_vertices": {"trait": "convex hull vertices", "method": "plantcv.plantcv.analyze_object", "scale": "none", "datatype": "<class 'int'>", "value": 24, "label": "none"}, "object_in_frame": {"trait": "object in frame", "method": "plantcv.plantcv.analyze_object", "scale": "none", "datatype": "<class 'bool'>", "value": true, "label": "none"}, "ellipse_center": {"trait": "ellipse center", "method": "plantcv.plantcv.analyze_object", "scale": "none", "datatype": "<class 'tuple'>", "value": [281.7710266113281, 222.56179809570312], "label": "none"}, "ellipse_major_axis": {"trait": "ellipse major axis length", "method": "plantcv.plantcv.analyze_object", "scale": "pixels", "datatype": "<class 'int'>", "value": 140.3796844482422, "label": "pixels"}, "ellipse_minor_axis": {"trait": "ellipse minor axis length", "method": "plantcv.plantcv.analyze_object", "scale": "pixels", "datatype": "<class 'int'>", "value": 88.0254135131836, "label": "pixels"}, "ellipse_angle": {"trait": "ellipse major axis angle", "method": "plantcv.plantcv.analyze_object", "scale": "degrees", "datatype": "<class 'float'>", "value": 10.134217262268066, "label": "degrees"}, "ellipse_eccentricity": {"trait": "ellipse eccentricity", "method": "plantcv.plantcv.analyze_object", "scale": "none", "datatype": "<class 'float'>", "value": 0.7789771037300188, "label": "none"}, "fvfm_hist": {"trait": "Fv/Fm frequencies", "method": "plantcv.plantcv.fluor_fvfm", "scale": "none", "datatype": "<class 'list'>", "value": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "label": [0.002, 0.006, 0.01, 0.014, 0.018, 0.021, 0.025, 0.029, 0.033, 0.037, 0.041, 0.045, 0.049, 0.053, 0.057, 0.061, 0.064, 0.068, 0.072, 0.076, 0.08, 0.084, 0.088, 0.092, 0.096, 0.1, 0.104, 0.107, 0.111, 0.115, 0.119, 0.123, 0.127, 0.131, 0.135, 0.139, 0.143, 0.146, 0.15, 0.154, 0.158, 0.162, 0.166, 0.17, 0.174, 0.178, 0.182, 0.186, 0.189, 0.193, 0.197, 0.201, 0.205, 0.209, 0.213, 0.217, 0.221, 0.225, 0.229, 0.232, 0.236, 0.24, 0.244, 0.248, 0.252, 0.256, 0.26, 0.264, 0.268, 0.271, 0.275, 0.279, 0.283, 0.287, 0.291, 0.295, 0.299, 0.303, 0.307, 0.311, 0.314, 0.318, 0.322, 0.326, 0.33, 0.334, 0.338, 0.342, 0.346, 0.35, 0.354, 0.357, 0.361, 0.365, 0.369, 0.373, 0.377, 0.381, 0.385, 0.389, 0.393, 0.396, 0.4, 0.404, 0.408, 0.412, 0.416, 0.42, 0.424, 0.428, 0.432, 0.436, 0.439, 0.443, 0.447, 0.451, 0.455, 0.459, 0.463, 0.467, 0.471, 0.475, 0.479, 0.482, 0.486, 0.49, 0.494, 0.498, 0.502, 0.506, 0.51, 0.514, 0.518, 0.521, 0.525, 0.529, 0.533, 0.537, 0.541, 0.545, 0.549, 0.553, 0.557, 0.561, 0.564, 0.568, 0.572, 0.576, 0.58, 0.584, 0.588, 0.592, 0.596, 0.6, 0.604, 0.607, 0.611, 0.615, 0.619, 0.623, 0.627, 0.631, 0.635, 0.639, 0.643, 0.646, 0.65, 0.654, 0.658, 0.662, 0.666, 0.67, 0.674, 0.678, 0.682, 0.686, 0.689, 0.693, 0.697, 0.701, 0.705, 0.709, 0.713, 0.717, 0.721, 0.725, 0.729, 0.732, 0.736, 0.74, 0.744, 0.748, 0.752, 0.756, 0.76, 0.764, 0.768, 0.771, 0.775, 0.779, 0.783, 0.787, 0.791, 0.795, 0.799, 0.803, 0.807, 0.811, 0.814, 0.818, 0.822, 0.826, 0.83, 0.834, 0.838, 0.842, 0.846, 0.85, 0.854, 0.857, 0.861, 0.865, 0.869, 0.873, 0.877, 0.881, 0.885, 0.889, 0.893, 0.896, 0.9, 0.904, 0.908, 0.912, 0.916, 0.92, 0.924, 0.928, 0.932, 0.936, 0.939, 0.943, 0.947, 0.951, 0.955, 0.959, 0.963, 0.967, 0.971, 0.975, 0.979, 0.982, 0.986, 0.99, 0.994, 0.998]}, "fvfm_hist_peak": {"trait": "peak Fv/Fm value", "method": "plantcv.plantcv.fluor_fvfm", "scale": "none", "datatype": "<class 'float'>", "value": 0.001953125, "label": "none"}, "fvfm_median": {"trait": "Fv/Fm median", "method": "plantcv.plantcv.fluor_fvfm", "scale": "none", "datatype": "<class 'float'>", "value": NaN, "label": "none"}, "fdark_passed_qc": {"trait": "Fdark passed QC", "method": "plantcv.plantcv.fluor_fvfm", "scale": "none", "datatype": "<class 'bool'>", "value": true, "label": "none"}}}]}

I got {"variables": {}, "entities": []} before renaming the file with a .txt file extension but after renaming I got the above output so I’m not sure if it’s a Windows thing or what. This reformatted file works with json2csv.