-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from danforthcenter/18-napari-import-data
napari read coor
- Loading branch information
Showing
8 changed files
with
109 additions
and
3 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
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,30 @@ | ||
## Read point data into Napari Format | ||
|
||
Save Points Labeled in Napari to a File | ||
|
||
**plantcv.napari_read_coor**(*coor, dataformat = 'yx'*) | ||
|
||
**returns** dictionary of points labeled by class | ||
|
||
- **Parameters:** | ||
- coor - dictionary object of coordinates, or a path to json datafile with dictionary of point coordinates | ||
- dataformat - either 'yx' or 'xy', Napari takes data as y,x format. If data is 'xy' data is converted from x,y to y,x | ||
|
||
- **Context:** | ||
- Import previously labeled points, or points from other functions (e.g. [`pcvan.napari_read_coor`](napari_read_coor.md)) | ||
|
||
- **Example use:** | ||
- Below | ||
|
||
|
||
```python | ||
import plantcv.plantcv as pcv | ||
import plantcv.annotate as pcvan | ||
|
||
# read in data | ||
|
||
data = pcvan.napari_read_points(coor ='coor.json', dataformat = 'xy') | ||
|
||
``` | ||
|
||
**Source Code:** [Here](https://github.com/danforthcenter/plantcv-annotate/blob/main/plantcv/annotate/napari_read_coor.py) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Import points from json file | ||
|
||
import json | ||
|
||
|
||
def napari_read_coor(coor, dataformat='yx'): | ||
""" | ||
open img in napari and label classes | ||
Inputs: | ||
coor = either a dictionary of data or a path to a json file | ||
with dictionary of point coordinates | ||
dataformat = either 'yx' or 'xy'. Output of points function is in | ||
x,y format and Napari is in y,x format. | ||
Returns: | ||
data = dictionary of data | ||
:param coor: dict or str | ||
:param dataformat: str | ||
:return data: dictionary of data in y,x format for napari | ||
""" | ||
if isinstance(coor, dict): | ||
data = coor | ||
else: | ||
with open(coor) as json_file: | ||
data = json.load(json_file) | ||
data1 = {} | ||
if dataformat != 'yx': | ||
keys = list(data.keys()) | ||
for key in keys: | ||
data2 = [(sub[1], sub[0]) for sub in data[key]] | ||
data1.update({key: data2}) | ||
data = data1 | ||
|
||
return data |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from plantcv.annotate import napari_read_coor | ||
|
||
|
||
def test_napari_read_coor_napari(test_data): | ||
"""Test for PlantCV.Annotate""" | ||
# Read in test data | ||
data = napari_read_coor(test_data.coor_data, 'yx') | ||
|
||
assert isinstance(data, dict) | ||
|
||
|
||
def test_napari_read_coor_other(test_data): | ||
"""Test for PlantCV.Annotate""" | ||
# Read in test data | ||
data = napari_read_coor(test_data.coor_data, 'xy') | ||
|
||
assert data['germinated'][0] == (10, 25) | ||
|
||
|
||
def test_napari_read_coor_flip(): | ||
"""Test for PlantCV.Annotate""" | ||
# Read in test data | ||
coor = {"germinated": [[25, 10]]} | ||
data = napari_read_coor(coor, 'xy') | ||
|
||
assert data['germinated'][0] == (10, 25) |
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 @@ | ||
{"germinated": [[25, 10]]} |