Skip to content

Commit

Permalink
implement datacollection.detector
Browse files Browse the repository at this point in the history
and datacollection.detector_id
  • Loading branch information
Anthchirp committed May 18, 2020
1 parent 4cfa959 commit 7efb18c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
28 changes: 0 additions & 28 deletions ispyb/model/__future__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ def __exit__(cm, *args):
import ispyb.model.detector

ispyb.model.detector.Detector.reload = _get_detector
ispyb.model.datacollection.DataCollection.detector = (
_get_linked_detector_for_data_collection
)


def _get_autoprocprogram(self):
Expand Down Expand Up @@ -366,31 +363,6 @@ def _get_linked_image_quality_indicators_for_data_collection(self):
)


@property
def _get_linked_detector_for_data_collection(self):
with _db_cc() as cursor:
cursor.run(
"SELECT d.detectorId, d.detectorType, "
"d.detectorManufacturer, d.detectorModel, "
"d.detectorPixelSizeHorizontal, d.detectorPixelSizeVertical, "
"d.detectorSerialNumber, d.detectorDistanceMin, d.detectorDistanceMax, "
"d.sensorThickness, d.numberOfPixelsX, d.numberOfPixelsY "
"FROM Detector d "
"INNER JOIN DataCollection dc on dc.detectorId = d.detectorId "
"WHERE dc.dataCollectionId = %s;",
self._dcid,
)

detector_data = cursor.fetchone()
if not detector_data:
return None
import ispyb.model.detector

return ispyb.model.detector.Detector(
detector_data["detectorId"], self._db, preload=detector_data
)


def _get_screening(self):
with _db_cc() as cursor:
cursor.run(
Expand Down
16 changes: 15 additions & 1 deletion ispyb/model/datacollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import ispyb.model
import ispyb.model.container
import ispyb.model.detector
import ispyb.model.gridinfo


Expand All @@ -23,6 +24,7 @@ def __init__(self, dcid, db_area, preload=None):
:return: A DataCollection object representing the database entry for
the specified DataCollectionID
"""
self._cache_detector = None
self._cache_group = None
self._db = db_area
self._dcid = int(dcid)
Expand Down Expand Up @@ -64,7 +66,13 @@ def image_quality(self):
@property
def detector(self):
"""Returns the Detector object associated with this DC."""
raise NotImplementedError("TODO: Not implemented yet")
if not self.detector_id:
return None
if self._cache_detector is None:
self._cache_detector = ispyb.model.detector.Detector(
self.detector_id, self._db.conn
)
return self._cache_detector

@property
def file_template_full(self):
Expand Down Expand Up @@ -135,6 +143,12 @@ def __str__(self):
"detectorDistance",
"Distance from the sample to the detector in mm",
),
(
"detector_id",
"detectorId",
"A unique identifier for the detector used in this acquisition. You can access the "
"detector model object via .detector directly.",
),
(
"detector_2theta",
"detector2Theta",
Expand Down

0 comments on commit 7efb18c

Please sign in to comment.