5
5
6
6
import numpy as np
7
7
import unyt
8
+ from typing import Union , List
8
9
9
10
10
11
class DerivedQuantities (object ):
11
12
"""
12
- Derived quantities class. Contains methods to open a python
13
- source file that creates derived quantities as follows:
13
+ Derived quantities class. Contains methods to open (a) python
14
+ source file(s) that create(s) derived quantities as follows:
14
15
15
16
The source file will have access to:
16
17
17
18
+ numpy (imported as np)
18
19
+ unyt (imported as unyt)
19
20
20
21
You should write your derived quantities as follows:
21
-
22
+
22
23
.. code-block:: python
23
24
24
25
self.derived_quantitiy_name = catalogue.type.field_name * 0.5
@@ -49,9 +50,9 @@ class DerivedQuantities(object):
49
50
setattr(
50
51
self, f"specific_sfr_gas_{aperture_size}_kpc", ssfr
51
52
)
52
-
53
53
54
- The path to this file should be passed to the __init__ method
54
+
55
+ The path to this file(s) should be passed to the __init__ method
55
56
of this class. Note that you should only register quantities that
56
57
you do in fact intend to use, as these are not lazily loaded
57
58
in the same way as the properties that are built into catalogues.
@@ -61,36 +62,39 @@ class DerivedQuantities(object):
61
62
62
63
"""
63
64
64
- def __init__ (self , registration_file_path : str , catalogue ):
65
+ def __init__ (self , registration_file_path : Union [ List [ str ], str ] , catalogue ):
65
66
"""
66
- Registers additional (derived) quantities from the
67
+ Registers additional (derived) quantities from the
67
68
VelociraptorCatalogue to itself, using a python
68
69
source file that does this registration inside
69
70
the private _register_quantities() method.
70
71
71
72
Parameters
72
73
----------
73
74
74
- registration_file_path: str
75
- Path to the python source file. For more information
76
- on the contents of this file, check out the information
75
+ registration_file_path: Union[List[ str], str]
76
+ Path to the python source file(s) . For more information
77
+ on the contents of this file/these files , check out the information
77
78
of this object.
78
79
79
80
catalogue: VelociraptorCatalogue
80
81
The catalogue to derive the quantities from.
81
82
82
-
83
+
83
84
Returns
84
85
-------
85
-
86
+
86
87
DerivedQuantities
87
88
An instance of the DerivedQuantities class with
88
89
the properties defined in registration_file_path
89
90
available as attributes.
90
-
91
+
91
92
"""
92
93
93
- self .registration_file_path = registration_file_path
94
+ if isinstance (registration_file_path , list ):
95
+ self .registration_file_paths = list (registration_file_path )
96
+ else :
97
+ self .registration_file_paths = [registration_file_path ]
94
98
self .catalogue = catalogue
95
99
96
100
self ._register_quantities ()
@@ -105,8 +109,8 @@ def _register_quantities(self):
105
109
"""
106
110
107
111
catalogue = self .catalogue
108
-
109
- with open (self . registration_file_path , "r" ) as handle :
110
- exec (handle .read ())
112
+ for file_path in self . registration_file_paths :
113
+ with open (file_path , "r" ) as handle :
114
+ exec (handle .read ())
111
115
112
116
return
0 commit comments