Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 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
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,69 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
from ispyb.interface.dataarea import DataArea | ||
|
||
|
||
class XtalImaging(DataArea): | ||
"""provides methods for accessing crystal imaging tables.""" | ||
|
||
def upsert_sample_image( | ||
self, | ||
id=None, | ||
sample_id=None, | ||
inspection_id=None, | ||
microns_per_pixel_x=None, | ||
microns_per_pixel_y=None, | ||
image_full_path=None, | ||
comments=None, | ||
): | ||
"""Store new or update existing sample image. | ||
:param image_full_path: The full path to the sample image | ||
:return: The sample_image_id. | ||
""" | ||
return self.get_connection().call_sp_write( | ||
procname="upsert_sample_image", | ||
args=[ | ||
id, | ||
sample_id, | ||
inspection_id, | ||
microns_per_pixel_x, | ||
microns_per_pixel_y, | ||
image_full_path, | ||
comments, | ||
], | ||
) | ||
|
||
def upsert_sample_image_auto_score( | ||
self, image_full_path, schema_name, score_class, probability | ||
): | ||
"""Store new or update existing automatic score for a sample image. | ||
:param image_full_path: The full path to the sample image | ||
:param schema_name: The name of the scoring schema, e.g. MARCO | ||
:param score_class: A string that describes the thing we're scoring, e.g. crystal, clear, precipitant, other | ||
:param probability: A float indicating the probability that the image contains the score_class | ||
""" | ||
self.get_connection().call_sp_write( | ||
procname="upsert_sample_image_auto_score", | ||
args=[image_full_path, schema_name, score_class, probability], | ||
) | ||
|
||
def retrieve_container_for_barcode(self, barcode): | ||
"""Retrieve info about the container indetified by the give barcode.""" | ||
return self.get_connection().call_sp_retrieve( | ||
procname="retrieve_container_for_barcode", args=[barcode] | ||
) | ||
|
||
def retrieve_container_for_inspection_id(self, inspection_id): | ||
"""Retrieve info about the container identified by container inspection ID""" | ||
return self.get_connection().call_sp_retrieve( | ||
procname="retrieve_container_for_inspection_id", args=[inspection_id] | ||
) | ||
|
||
def retrieve_sample_for_container_id_and_location(self, container_id, location): | ||
"""Retrieve info about the sample identified by the given container ID and its location.""" | ||
return self.get_connection().call_sp_retrieve( | ||
procname="retrieve_sample_for_container_id_and_location", | ||
args=[container_id, location], | ||
) |
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,39 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
|
||
def test_xtal_imaging(testdb): | ||
testdb.set_role("ispyb_import") | ||
xtalimaging = testdb.xtal_imaging | ||
|
||
container = xtalimaging.retrieve_container_for_barcode("test_plate2") | ||
cid = container[0]["containerId"] | ||
|
||
assert cid is not None | ||
assert cid > 0 | ||
|
||
sample = xtalimaging.retrieve_sample_for_container_id_and_location( | ||
container_id=cid, location=1 | ||
) | ||
sid = sample[0]["sampleId"] | ||
|
||
assert sid is not None | ||
assert sid > 0 | ||
|
||
si_full_path = "/dls/i03/data/2018/cm14451-99/something_new.jpg" | ||
siid = xtalimaging.upsert_sample_image( | ||
sample_id=sid, | ||
microns_per_pixel_x=12.03, | ||
microns_per_pixel_y=12.04, | ||
image_full_path=si_full_path, | ||
) | ||
|
||
assert siid is not None | ||
assert siid > 0 | ||
|
||
xtalimaging.upsert_sample_image_auto_score(si_full_path, "MARCO", "crystal", 0.65) | ||
|
||
container = xtalimaging.retrieve_container_for_inspection_id(4) | ||
cid2 = container[0]["containerId"] | ||
|
||
assert cid2 is not None | ||
assert cid2 == 34874 |