@@ -88,7 +88,13 @@ def register_field_properties(self):
8888 return
8989
9090
91- def generate_getter (filename , name : str , field : str , full_name : str , unit ):
91+ def generate_getter (
92+ filename ,
93+ name : str ,
94+ field : str ,
95+ full_name : str ,
96+ unit
97+ ):
9298 """
9399 Generates a function that:
94100
@@ -115,7 +121,8 @@ def getter(self):
115121 else :
116122 with h5py .File (filename , "r" ) as handle :
117123 try :
118- setattr (self , f"_{ name } " , unyt .unyt_array (handle [field ][...], unit ))
124+ mask = getattr (self , "mask" )
125+ setattr (self , f"_{ name } " , unyt .unyt_array (handle [field ][mask ], unit ))
119126 getattr (self , f"_{ name } " ).name = full_name
120127 getattr (self , f"_{ name } " ).file = filename
121128 except KeyError :
@@ -161,6 +168,7 @@ def generate_sub_catalogue(
161168 registration_function : Callable ,
162169 units : VelociraptorUnits ,
163170 field_metadata : List [VelociraptorFieldMetadata ],
171+ mask : slice = Ellipsis
164172):
165173 """
166174 Generates a sub-catalogue object with the correct properties set.
@@ -190,7 +198,7 @@ def generate_sub_catalogue(
190198 metadata .snake_case ,
191199 metadata .path ,
192200 metadata .name ,
193- metadata .unit ,
201+ metadata .unit
194202 ),
195203 generate_setter (metadata .snake_case ),
196204 generate_deleter (metadata .snake_case ),
@@ -205,7 +213,7 @@ def generate_sub_catalogue(
205213 )
206214
207215 # Finally, we can actually create an instance of our new class.
208- catalogue = ThisSubCatalogue (filename = filename )
216+ catalogue = ThisSubCatalogue (filename = filename , mask = mask )
209217 catalogue .valid_sub_paths = valid_sub_paths
210218
211219 return catalogue
@@ -224,8 +232,9 @@ class __VelociraptorSubCatalogue(object):
224232 # The valid paths contained within
225233 valid_sub_paths : List [str ]
226234
227- def __init__ (self , filename ):
235+ def __init__ (self , filename , mask = Ellipsis ):
228236 self .filename = filename
237+ self .mask = mask
229238
230239 return
231240
@@ -250,6 +259,7 @@ def __init__(
250259 filename : str ,
251260 disregard_units : bool = False ,
252261 extra_registration_functions : Union [None , Dict [str , Callable ]] = None ,
262+ mask : slice = Ellipsis ,
253263 ):
254264 """
255265 Initialise the velociraptor catalogue with all of the available
@@ -276,10 +286,16 @@ def __init__(
276286 should be a dictionary of strings pointing to callables, which
277287 conform to the registration function API. This is an advanced
278288 feature.
289+
290+ mask: slice, optional
291+ If a boolean array is provided, it is used to mask all catalogue
292+ arrays. If an int is provided, catalogue arrays are masked to the
293+ single corresponding element. Default: Ellipsis (``...``).
279294 """
280295 self .filename = filename
281296 self .disregard_units = disregard_units
282297 self .extra_registration_functions = extra_registration_functions
298+ self .mask = mask
283299
284300 self .get_units ()
285301 self .extract_properties_from_units ()
@@ -296,11 +312,18 @@ def __str__(self):
296312 the memory location.
297313 """
298314
299- return (
300- f"Velociraptor catalogue at { self .filename } . "
301- "Contains the following field collections: "
302- f"{ ', ' .join (self .valid_field_metadata .keys ())} "
303- )
315+ if self .mask is Ellipsis :
316+ return (
317+ f"Velociraptor catalogue at { self .filename } . "
318+ "Contains the following field collections: "
319+ f"{ ', ' .join (self .valid_field_metadata .keys ())} "
320+ )
321+ else :
322+ return (
323+ f"Masked velociraptor catalogue at { self .filename } . "
324+ "Contains the following field collections: "
325+ f"{ ', ' .join (self .valid_field_metadata .keys ())} "
326+ )
304327
305328 def __repr__ (self ):
306329 return str (self )
@@ -388,6 +411,7 @@ def __create_sub_catalogues(self):
388411 registration_function = self .registration_functions [attribute_name ],
389412 units = self .units ,
390413 field_metadata = field_metadata ,
414+ mask = self .mask
391415 ),
392416 )
393417
0 commit comments