@@ -105,7 +105,7 @@ class KeyData:
105105 """
106106 def __init__ (
107107 self , source , key , * , train_ids , files , section , dtype , eshape ,
108- inc_suspect_trains = True ,
108+ is_single_run , inc_suspect_trains = True ,
109109 ):
110110 self .source = source
111111 self .key = key
@@ -115,6 +115,7 @@ def __init__(
115115 self .dtype = dtype
116116 self .entry_shape = eshape
117117 self .ndim = len (eshape ) + 1
118+ self .is_single_run = is_single_run
118119 self .inc_suspect_trains = inc_suspect_trains
119120
120121 def _find_chunks (self ):
@@ -343,6 +344,7 @@ def _only_tids(self, tids, files=None):
343344 section = self .section ,
344345 dtype = self .dtype ,
345346 eshape = self .entry_shape ,
347+ is_single_run = self .is_single_run ,
346348 inc_suspect_trains = self .inc_suspect_trains ,
347349 )
348350
@@ -472,6 +474,29 @@ def as_single_value(self, rtol=1e-5, atol=0.0, reduce_by=None):
472474
473475 return value
474476
477+ def run_value (self , allow_multi_run = False ):
478+ """Get the RUN value for this key if it exists.
479+
480+ This method is intended for use with data from a single run. If you
481+ combine data from multiple runs, it will raise MultiRunError.
482+
483+ Returns the RUN parameter value corresponding to this key.
484+ """
485+
486+ from .sourcedata import SourceData # Prevent cyclic import.
487+
488+ # Construct minimal SourceData object to obtain RUN value.
489+ return SourceData (
490+ self .source ,
491+ sel_keys = None ,
492+ train_ids = self .train_ids ,
493+ files = self .files ,
494+ section = self .section ,
495+ canonical_name = self .source ,
496+ is_single_run = self .is_single_run ,
497+ inc_suspect_trains = self .inc_suspect_trains
498+ ).run_value (self .key , allow_multi_run = allow_multi_run )
499+
475500 # Getting data as different kinds of array: -------------------------------
476501
477502 def ndarray (self , roi = (), out = None ):
0 commit comments