@@ -1638,7 +1638,7 @@ def test_patch_pred_store() -> None:
16381638 "other" : "other" ,
16391639 }
16401640
1641- store = misc .patch_pred_store (patch_output , (1.0 , 1.0 ))
1641+ store = misc .dict_to_store (patch_output , (1.0 , 1.0 ))
16421642
16431643 # Check that its an SQLiteStore containing the expected annotations
16441644 assert isinstance (store , SQLiteStore )
@@ -1651,7 +1651,7 @@ def test_patch_pred_store() -> None:
16511651 patch_output .pop ("coordinates" )
16521652 # check correct error is raised if coordinates are missing
16531653 with pytest .raises (ValueError , match = "coordinates" ):
1654- misc .patch_pred_store (patch_output , (1.0 , 1.0 ))
1654+ misc .dict_to_store (patch_output , (1.0 , 1.0 ))
16551655
16561656
16571657def test_patch_pred_store_cdict () -> None :
@@ -1665,7 +1665,7 @@ def test_patch_pred_store_cdict() -> None:
16651665 "other" : "other" ,
16661666 }
16671667 class_dict = {0 : "class0" , 1 : "class1" }
1668- store = misc .patch_pred_store (patch_output , (1.0 , 1.0 ), class_dict = class_dict )
1668+ store = misc .dict_to_store (patch_output , (1.0 , 1.0 ), class_dict = class_dict )
16691669
16701670 # Check that its an SQLiteStore containing the expected annotations
16711671 assert isinstance (store , SQLiteStore )
@@ -1686,10 +1686,113 @@ def test_patch_pred_store_sf() -> None:
16861686 "probabilities" : [[0.1 , 0.9 ], [0.9 , 0.1 ], [0.4 , 0.6 ]],
16871687 "labels" : [1 , 0 , 1 ],
16881688 }
1689- store = misc .patch_pred_store (patch_output , (2.0 , 2.0 ))
1689+ store = misc .dict_to_store (patch_output , (2.0 , 2.0 ))
16901690
16911691 # Check that its an SQLiteStore containing the expected annotations
16921692 assert isinstance (store , SQLiteStore )
16931693 assert len (store ) == 3
16941694 for annotation in store .values ():
16951695 assert annotation .geometry .area == 4
1696+
1697+
1698+ def test_patch_pred_store_zarr (tmp_path : pytest .TempPathFactory ) -> None :
1699+ """Test patch_pred_store_zarr."""
1700+ # Define a mock patch_output
1701+ patch_output = {
1702+ "predictions" : [1 , 0 , 1 ],
1703+ "coordinates" : [(0 , 0 , 1 , 1 ), (1 , 1 , 2 , 2 ), (2 , 2 , 3 , 3 )],
1704+ "probabilities" : [[0.1 , 0.9 ], [0.9 , 0.1 ], [0.4 , 0.6 ]],
1705+ "labels" : [1 , 0 , 1 ],
1706+ }
1707+
1708+ save_path = tmp_path / "patch_output" / "output.zarr"
1709+
1710+ store_path = misc .dict_to_zarr (patch_output , save_path = save_path )
1711+
1712+ print ("Zarr path: " , store_path )
1713+ assert Path .exists (store_path ), "Zarr output file does not exist"
1714+
1715+
1716+ def test_patch_pred_store_zarr_ext (tmp_path : pytest .TempPathFactory ) -> None :
1717+ """Test patch_pred_store_zarr and ensures the output file extension is `.zarr`."""
1718+ # Define a mock patch_output
1719+ patch_output = {
1720+ "predictions" : [1 , 0 , 1 ],
1721+ "coordinates" : [(0 , 0 , 1 , 1 ), (1 , 1 , 2 , 2 ), (2 , 2 , 3 , 3 )],
1722+ "probabilities" : [[0.1 , 0.9 ], [0.9 , 0.1 ], [0.4 , 0.6 ]],
1723+ "labels" : [1 , 0 , 1 ],
1724+ }
1725+
1726+ # sends the path of a jpeg source image, expects .zarr file in the same directory
1727+ save_path = tmp_path / "patch_output" / "patch.jpeg"
1728+
1729+ store_path = misc .dict_to_zarr (patch_output , save_path = save_path )
1730+
1731+ print ("Zarr path: " , store_path )
1732+ assert Path .exists (store_path ), "Zarr output file does not exist"
1733+
1734+
1735+ def test_patch_pred_store_persist (tmp_path : pytest .TempPathFactory ) -> None :
1736+ """Test patch_pred_store. and persists store output to a .db file."""
1737+ # Define a mock patch_output
1738+ patch_output = {
1739+ "predictions" : [1 , 0 , 1 ],
1740+ "coordinates" : [(0 , 0 , 1 , 1 ), (1 , 1 , 2 , 2 ), (2 , 2 , 3 , 3 )],
1741+ "probabilities" : [[0.1 , 0.9 ], [0.9 , 0.1 ], [0.4 , 0.6 ]],
1742+ "labels" : [1 , 0 , 1 ],
1743+ }
1744+ save_path = tmp_path / "patch_output" / "output.db"
1745+
1746+ store_path = misc .dict_to_store (patch_output , (1.0 , 1.0 ), save_path = save_path )
1747+
1748+ print ("Annotation store path: " , store_path )
1749+ assert Path .exists (store_path ), "Annotation Store output file does not exist"
1750+
1751+ store = SQLiteStore (store_path )
1752+
1753+ # Check that its an SQLiteStore containing the expected annotations
1754+ assert isinstance (store , SQLiteStore )
1755+ assert len (store ) == 3
1756+ for annotation in store .values ():
1757+ assert annotation .geometry .area == 1
1758+ assert annotation .properties ["type" ] in [0 , 1 ]
1759+ assert "other" not in annotation .properties
1760+
1761+ patch_output .pop ("coordinates" )
1762+ # check correct error is raised if coordinates are missing
1763+ with pytest .raises (ValueError , match = "coordinates" ):
1764+ misc .dict_to_store (patch_output , (1.0 , 1.0 ))
1765+
1766+
1767+ def test_patch_pred_store_persist_ext (tmp_path : pytest .TempPathFactory ) -> None :
1768+ """Test patch_pred_store and ensures the output file extension is `.db`."""
1769+ # Define a mock patch_output
1770+ patch_output = {
1771+ "predictions" : [1 , 0 , 1 ],
1772+ "coordinates" : [(0 , 0 , 1 , 1 ), (1 , 1 , 2 , 2 ), (2 , 2 , 3 , 3 )],
1773+ "probabilities" : [[0.1 , 0.9 ], [0.9 , 0.1 ], [0.4 , 0.6 ]],
1774+ "labels" : [1 , 0 , 1 ],
1775+ }
1776+
1777+ # sends the path of a jpeg source image, expects .db file in the same directory
1778+ save_path = tmp_path / "patch_output" / "output.jpeg"
1779+
1780+ store_path = misc .dict_to_store (patch_output , (1.0 , 1.0 ), save_path = save_path )
1781+
1782+ print ("Annotation store path: " , store_path )
1783+ assert Path .exists (store_path ), "Annotation Store output file does not exist"
1784+
1785+ store = SQLiteStore (store_path )
1786+
1787+ # Check that its an SQLiteStore containing the expected annotations
1788+ assert isinstance (store , SQLiteStore )
1789+ assert len (store ) == 3
1790+ for annotation in store .values ():
1791+ assert annotation .geometry .area == 1
1792+ assert annotation .properties ["type" ] in [0 , 1 ]
1793+ assert "other" not in annotation .properties
1794+
1795+ patch_output .pop ("coordinates" )
1796+ # check correct error is raised if coordinates are missing
1797+ with pytest .raises (ValueError , match = "coordinates" ):
1798+ misc .dict_to_store (patch_output , (1.0 , 1.0 ))
0 commit comments