10
10
11
11
from .image import reconstruct_image , reconstruct_image_sum
12
12
from .mixin import PhotonCounts , ExcitationLaserPower
13
+ from .caching import method_cache
13
14
from .plotting import parse_color_channel
14
- from .utilities import method_cache , could_sum_overflow
15
+ from .utilities import could_sum_overflow
15
16
from ..adjustments import no_adjustment
16
17
from .imaging_mixins import TiffExport
17
18
@@ -208,9 +209,11 @@ class BaseScan(PhotonCounts, ExcitationLaserPower):
208
209
End point in the relevant info wave.
209
210
metadata : ScanMetaData
210
211
Metadata.
212
+ location : str | None
213
+ Path of the confocal object.
211
214
"""
212
215
213
- def __init__ (self , name , file , start , stop , metadata ):
216
+ def __init__ (self , name , file , start , stop , metadata , location ):
214
217
self .start = start
215
218
self .stop = stop
216
219
self .name = name
@@ -220,6 +223,7 @@ def __init__(self, name, file, start, stop, metadata):
220
223
self ._timestamp_factory = _default_timestamp_factory
221
224
self ._pixelsize_factory = _default_pixelsize_factory
222
225
self ._pixelcount_factory = _default_pixelcount_factory
226
+ self ._location = location
223
227
self ._cache = {}
224
228
225
229
def _has_default_factories (self ):
@@ -243,12 +247,13 @@ def from_dataset(cls, h5py_dset, file):
243
247
start = h5py_dset .attrs ["Start time (ns)" ]
244
248
stop = h5py_dset .attrs ["Stop time (ns)" ]
245
249
name = h5py_dset .name .split ("/" )[- 1 ]
250
+ location = file .h5 .filename + h5py_dset .name
246
251
try :
247
252
metadata = ScanMetaData .from_json (h5py_dset [()])
248
253
except KeyError :
249
254
raise KeyError (f"{ cls .__name__ } '{ name } ' is missing metadata and cannot be loaded" )
250
255
251
- return cls (name , file , start , stop , metadata )
256
+ return cls (name , file , start , stop , metadata , location )
252
257
253
258
@property
254
259
def file (self ):
@@ -269,6 +274,9 @@ def __copy__(self):
269
274
start = self .start ,
270
275
stop = self .stop ,
271
276
metadata = self ._metadata ,
277
+ # If it has no location, it will be cached only locally. This is safer than implicitly
278
+ # caching it under the same location as the parent.
279
+ location = None ,
272
280
)
273
281
274
282
# Preserve custom factories
@@ -512,5 +520,4 @@ def get_image(self, channel="rgb") -> np.ndarray:
512
520
if channel not in ("red" , "green" , "blue" ):
513
521
return np .stack ([self .get_image (color ) for color in ("red" , "green" , "blue" )], axis = - 1 )
514
522
else :
515
- # Make sure we don't return a reference to our cache
516
523
return self ._image (channel )
0 commit comments