mesaport.Access.mesa_access

  1from .support import *
  2from .envhandler import MesaEnvironmentHandler
  3from .access_helper import *
  4from . import loader
  5
  6"""
  7This module defines the `MesaAccess` class, which handles MESA project access.
  8
  9Attributes:
 10    project (str): Name of the project.
 11    binary (bool): True for a binary star system.
 12    astero (bool): True for an asteroseismic project.
 13    target (str): If the project is a binary system, specify the star or binary.
 14
 15Methods:
 16    set(key, value, default=False, force=False): Sets a value in the full dictionary.
 17    get(key): Gets a value from the full dictionary.
 18    delete(key): Deletes a value from the full dictionary.
 19    setDefault(keys): Sets all values to default.
 20    getDefault(keys): Gets default value from the full dictionary.
 21    load_InlistProject(inlistPath): Loads the inlist file.
 22    load_InlistAsteroSearch(inlistPath): Loads the astero_search_controls inlist file.
 23    load_InlistPG(inlistPath): Loads the inlist file.
 24    load_HistoryColumns(HistoryColumns): Loads the history columns.
 25    load_ProfileColumns(ProfileColumns): Loads the profile columns.
 26    load_Extras(extras_path): Loads the run_star_extras file.
 27"""
 28
 29class MesaAccess:
 30    def __init__(self, project, astero=False, binary=False, target=''):
 31        """Initializes the MesaAccess class.
 32
 33        Args:
 34            project (str): _description_.
 35            binary (bool, optional): If the project is a binary. Defaults to False.
 36            target (str, optional): If the project is a binary, which star to access. Defaults to ''.
 37        """        
 38        if binary and target not in [None, 'primary', 'secondary', 'binary']:
 39            raise ValueError("Invalid input for argument 'target'")
 40        self.project = project
 41        self.astero = astero
 42        self.binary = binary
 43        self.target = target
 44        if os.path.isabs(project):
 45            self.projectDir = project
 46        else:
 47            self.projectDir = os.path.join(os.getcwd(), project)
 48        envObj = MesaEnvironmentHandler(astero, binary, target)
 49        if binary and target == 'binary':
 50            self.mesaDir, self.defaultsDir = envObj.mesaDir, envObj.defaultsDir
 51            self.sections, self.defaultsFileNames = sections_binary, defaultsFileNames_binary
 52            self.inlist_filenames = ["inlist_project"]
 53        elif binary and target != 'binary':
 54            self.mesaDir, self.defaultsDir = envObj.mesaDir, envObj.defaultsDir
 55            self.sections, self.defaultsFileNames = sections_star, defaultsFileNames_star
 56            if self.target == 'primary':
 57                self.inlist_filenames = ["inlist1"]
 58            elif self.target == 'secondary':
 59                self.inlist_filenames = ["inlist2"]
 60        elif astero:
 61            self.mesaDir, self.defaultsDir = envObj.mesaDir, envObj.defaultsDir
 62            self.sections, self.defaultsFileNames = sections_astero, defaultsFileNames_astero
 63            self.inlist_filenames = ["inlist_project", "inlist_pgstar", "inlist_astero_search_controls"]
 64        else:
 65            self.mesaDir, self.defaultsDir = envObj.mesaDir, envObj.defaultsDir
 66            self.sections, self.defaultsFileNames = sections_star, defaultsFileNames_star
 67            self.inlist_filenames = ["inlist_project", "inlist_pgstar"]
 68        self.defaultsDict = {}
 69        for section in self.sections:
 70            self.defaultsDict[section] = readDefaults(self.defaultsFileNames[section], self.defaultsDir)
 71        
 72        
 73    def generateDicts(self):
 74        """Generates the dictionaries for the inlist files.
 75        """        
 76        self.inlistDict = {}
 77        self.inlistSections = {}
 78        for filename in self.inlist_filenames:
 79            self.inlistSections[filename], self.inlistDict[filename] = readFile(filename, self.projectDir)
 80        # pprint(self.inlistDict)
 81
 82
 83    
 84    def setitem(self, key, value, default=False, force=False):
 85        """Sets a value in the full dictionary.
 86
 87        Args:
 88            key (str): Key of the value to set.
 89            value (str): Value to set.
 90
 91        Raises:
 92            TypeError: Value is not of default type
 93        """        
 94        default_section, default_val, default_type = matchtoDefaults(key, self.defaultsDict, self.sections)
 95        if default:
 96            value = default_val
 97        filename = getFilename(self.astero, self.binary, default_section, self.inlist_filenames)
 98        exists, _ = matchtoFile(key, self.inlistDict[filename], self.inlistSections[filename], default_section)
 99        if not force:
100            if not matchTypes(type(value), default_type):
101                raise TypeError(f"Value {value} is not of default type {default_type}")
102        writetoFile(self.projectDir, filename, key, value, exists, default_section, delete=False)
103            
104
105
106    def getitem(self, item):
107        """Gets a value from the full dictionary.
108
109        Args:
110            item (str): Key of the value to get.
111
112        Returns:
113            str: Value of the key
114        """        
115        default_section, default_val, default_type = matchtoDefaults(item, self.defaultsDict, self.sections)
116        filename = getFilename(self.astero, self.binary, default_section, self.inlist_filenames)
117        return matchtoFile(item, self.inlistDict[filename], self.inlistSections[filename], default_section)[1]
118    
119
120
121    def delitem(self, key):
122        """Deletes a value from the full dictionary.
123
124        Args:
125            key (str): Key of the value to delete.
126
127        Raises:
128            KeyError: Parameter does not exist in inlist file
129        """        
130        default_section, default_val, default_type = matchtoDefaults(key, self.defaultsDict, self.sections)
131        filename = getFilename(self.astero, self.binary, default_section, self.inlist_filenames)
132        exists, _ = matchtoFile(key, self.inlistDict[filename], self.inlistSections[filename], default_section)
133        if exists:
134            writetoFile(self.projectDir, filename, key, _, exists, default_section, delete=True)
135        else:
136            raise KeyError(f"Parameter {key} does not exist in {filename}")
137
138    def set(self, *arg, force=False):
139        """Sets a value in the full dictionary.
140
141        Args:
142            arg (dict or list of dicts): A dict with the keys and values to set or a list of dicts with the keys and values to set.
143        Raises:
144            ValueError: Length of keys does not match length of values
145            TypeError: Input parameter name(s) must be of type string or list of strings.
146        """    
147        self.generateDicts() 
148        if len(arg) == 1:
149            if isinstance(arg[0], dict):
150                for key, value in arg[0].items():
151                    self.setitem(key, value, force=force)
152            elif isinstance(arg[0], list):
153                for dict_ in arg[0]:
154                    for key, value in dict_.items():
155                        self.setitem(key, value, force=force)
156            else:
157                raise TypeError("Input parameter name(s) must be of type dict or list of dicts.")
158        elif len(arg) == 2:
159            keys, values = arg[0], arg[1]  
160            if isinstance(keys, list):
161                if len(keys) == len(values):
162                    for i in range(len(keys)):
163                        self.setitem(keys[i], values[i], force=force)
164                else:
165                    raise ValueError(f"Length of keys {keys} does not match length of {values}")
166            elif isinstance(keys, str):
167                self.setitem(keys, values, force=force)
168            else:
169                raise TypeError("Input parameter name(s) must be of type string or list of strings.")
170    
171    def setDefault(self, keys):
172        """Sets all values to default.
173        """        
174        self.generateDicts()
175        if isinstance(keys, list):
176            for key in keys:
177                self.setitem(key, '', default=True)
178        elif isinstance(keys, str):
179            self.setitem(keys, '', default=True)
180
181
182    def getDefault(self, keys):
183        """Gets default value from the full dictionary.
184
185        Args:
186            keys (str or list): Key of the value to get.
187
188        Raises:
189            TypeError: Input parameter name(s) must be of type string or list of strings.
190
191        Returns:
192            str or list: Value or list of values.
193        """        
194        self.generateDicts()
195        if isinstance(keys, list):
196            got = []
197            for key in keys:
198                default_section, default_val, default_type = matchtoDefaults(key, self.defaultsDict, self.sections)
199                got.append(default_val)
200            return got
201        elif isinstance(keys, str):
202            default_section, default_val, default_type = matchtoDefaults(keys, self.defaultsDict, self.sections)
203            return default_val
204        else:
205            raise TypeError("Input parameter name(s) must be of type string or list of strings.")
206        
207
208
209
210    def get(self, items):
211        """Gets a value from the full dictionary.
212
213        Args:
214            items (str or list): Key of the value to get.
215
216        Raises:
217            TypeError: Input parameter name(s) must be of type string or list of strings.
218
219        Returns:
220            str or list: Value or list of values.
221        """        
222        self.generateDicts()
223        if isinstance(items, list):
224            got = []
225            for item in items:
226                got.append(self.getitem(item))
227            return got
228        elif isinstance(items, str):
229            return self.getitem(items)
230        else:
231            raise TypeError("Input parameter name(s) must be of type string or list of strings.")
232        
233
234
235    def delete(self, keys):
236        """Deletes a value from the full dictionary.
237
238        Args:
239            keys (str or list): Key of the value to delete.
240
241        Raises:
242            TypeError: Input parameter name(s) must be of type string or list of strings.
243        """       
244        self.generateDicts() 
245        if isinstance(keys, list):
246            for key in keys:
247                self.delitem(key)
248        elif isinstance(keys, str):
249            self.delitem(keys)
250        else:
251            raise TypeError("Input parameter name(s) must be of type string or list of strings.")
252
253
254    def check_exists(self):
255        """Checks if the project directory exists.
256        """        
257        if not os.path.exists(self.projectDir):
258            raise FileNotFoundError(f"Project directory {self.projectDir} does not exist.")
259
260    
261    def load_InlistProject(self, inlistPath):
262        """Loads the inlist file.
263
264        Args:
265            inlistPath (str): Path to the inlist file.
266            target (str, optional): If the project is a binary system, specify the star 
267                                    or binary. Defaults to None.
268                                    Input can be 'primary', 'secondary' or 'binary'.
269
270        Raises:
271            ValueError: If the input for argument 'target' is invalid.
272        """        
273        self.check_exists()
274        loader.load(inlistPath, self.projectDir, "inlist_project", binary=self.binary, target=self.target)
275
276    def load_InlistAsteroSearch(self, inlistPath):
277        """Loads the astero_search_controls inlist file.
278
279        Args:
280            inlistPath (str): Path to the inlist file.
281        """        
282        self.check_exists()
283        loader.load(inlistPath, self.projectDir, "inlist_astero_search_controls")
284            
285    
286    def load_InlistPG(self, inlistPath):
287        """Loads the inlist file.
288
289        Args:
290            inlistPath (str): Path to the inlist file.
291
292        Raises:
293            ValueError: If the input for argument 'typeof' is invalid.
294        """        
295        self.check_exists()
296        loader.load(inlistPath, self.projectDir, "inlist_pgstar")
297        
298
299    def load_HistoryColumns(self, HistoryColumns):
300        """Loads the history columns.
301
302        Args:
303            HistoryColumns (str): Path to the history columns file.
304            target (str, optional): If the project is a binary system, specify the star or binary.
305                                    Input 'primary', 'secondary' or 'binary'. Defaults to None.
306        """        
307        self.check_exists()
308        loader.load(HistoryColumns, self.projectDir, "history_columns", binary=self.binary, target=self.target)
309
310
311    def load_ProfileColumns(self, ProfileColumns):
312        """Loads the profile columns.
313
314        Args:
315            ProfileColumns (str): Path to the profile columns file.
316        """  
317        self.check_exists()      
318        loader.load(ProfileColumns, self.projectDir, "profile_columns")
319
320
321    def load_Extras(self, extras_path):
322        """Loads the extras file.
323
324        Args:
325            extras_path (str): Path to the extras file.
326        """  
327        self.check_exists()
328        loader.load(extras_path, self.projectDir, "extras", binary=self.binary, target=self.target)
class MesaAccess:
 30class MesaAccess:
 31    def __init__(self, project, astero=False, binary=False, target=''):
 32        """Initializes the MesaAccess class.
 33
 34        Args:
 35            project (str): _description_.
 36            binary (bool, optional): If the project is a binary. Defaults to False.
 37            target (str, optional): If the project is a binary, which star to access. Defaults to ''.
 38        """        
 39        if binary and target not in [None, 'primary', 'secondary', 'binary']:
 40            raise ValueError("Invalid input for argument 'target'")
 41        self.project = project
 42        self.astero = astero
 43        self.binary = binary
 44        self.target = target
 45        if os.path.isabs(project):
 46            self.projectDir = project
 47        else:
 48            self.projectDir = os.path.join(os.getcwd(), project)
 49        envObj = MesaEnvironmentHandler(astero, binary, target)
 50        if binary and target == 'binary':
 51            self.mesaDir, self.defaultsDir = envObj.mesaDir, envObj.defaultsDir
 52            self.sections, self.defaultsFileNames = sections_binary, defaultsFileNames_binary
 53            self.inlist_filenames = ["inlist_project"]
 54        elif binary and target != 'binary':
 55            self.mesaDir, self.defaultsDir = envObj.mesaDir, envObj.defaultsDir
 56            self.sections, self.defaultsFileNames = sections_star, defaultsFileNames_star
 57            if self.target == 'primary':
 58                self.inlist_filenames = ["inlist1"]
 59            elif self.target == 'secondary':
 60                self.inlist_filenames = ["inlist2"]
 61        elif astero:
 62            self.mesaDir, self.defaultsDir = envObj.mesaDir, envObj.defaultsDir
 63            self.sections, self.defaultsFileNames = sections_astero, defaultsFileNames_astero
 64            self.inlist_filenames = ["inlist_project", "inlist_pgstar", "inlist_astero_search_controls"]
 65        else:
 66            self.mesaDir, self.defaultsDir = envObj.mesaDir, envObj.defaultsDir
 67            self.sections, self.defaultsFileNames = sections_star, defaultsFileNames_star
 68            self.inlist_filenames = ["inlist_project", "inlist_pgstar"]
 69        self.defaultsDict = {}
 70        for section in self.sections:
 71            self.defaultsDict[section] = readDefaults(self.defaultsFileNames[section], self.defaultsDir)
 72        
 73        
 74    def generateDicts(self):
 75        """Generates the dictionaries for the inlist files.
 76        """        
 77        self.inlistDict = {}
 78        self.inlistSections = {}
 79        for filename in self.inlist_filenames:
 80            self.inlistSections[filename], self.inlistDict[filename] = readFile(filename, self.projectDir)
 81        # pprint(self.inlistDict)
 82
 83
 84    
 85    def setitem(self, key, value, default=False, force=False):
 86        """Sets a value in the full dictionary.
 87
 88        Args:
 89            key (str): Key of the value to set.
 90            value (str): Value to set.
 91
 92        Raises:
 93            TypeError: Value is not of default type
 94        """        
 95        default_section, default_val, default_type = matchtoDefaults(key, self.defaultsDict, self.sections)
 96        if default:
 97            value = default_val
 98        filename = getFilename(self.astero, self.binary, default_section, self.inlist_filenames)
 99        exists, _ = matchtoFile(key, self.inlistDict[filename], self.inlistSections[filename], default_section)
100        if not force:
101            if not matchTypes(type(value), default_type):
102                raise TypeError(f"Value {value} is not of default type {default_type}")
103        writetoFile(self.projectDir, filename, key, value, exists, default_section, delete=False)
104            
105
106
107    def getitem(self, item):
108        """Gets a value from the full dictionary.
109
110        Args:
111            item (str): Key of the value to get.
112
113        Returns:
114            str: Value of the key
115        """        
116        default_section, default_val, default_type = matchtoDefaults(item, self.defaultsDict, self.sections)
117        filename = getFilename(self.astero, self.binary, default_section, self.inlist_filenames)
118        return matchtoFile(item, self.inlistDict[filename], self.inlistSections[filename], default_section)[1]
119    
120
121
122    def delitem(self, key):
123        """Deletes a value from the full dictionary.
124
125        Args:
126            key (str): Key of the value to delete.
127
128        Raises:
129            KeyError: Parameter does not exist in inlist file
130        """        
131        default_section, default_val, default_type = matchtoDefaults(key, self.defaultsDict, self.sections)
132        filename = getFilename(self.astero, self.binary, default_section, self.inlist_filenames)
133        exists, _ = matchtoFile(key, self.inlistDict[filename], self.inlistSections[filename], default_section)
134        if exists:
135            writetoFile(self.projectDir, filename, key, _, exists, default_section, delete=True)
136        else:
137            raise KeyError(f"Parameter {key} does not exist in {filename}")
138
139    def set(self, *arg, force=False):
140        """Sets a value in the full dictionary.
141
142        Args:
143            arg (dict or list of dicts): A dict with the keys and values to set or a list of dicts with the keys and values to set.
144        Raises:
145            ValueError: Length of keys does not match length of values
146            TypeError: Input parameter name(s) must be of type string or list of strings.
147        """    
148        self.generateDicts() 
149        if len(arg) == 1:
150            if isinstance(arg[0], dict):
151                for key, value in arg[0].items():
152                    self.setitem(key, value, force=force)
153            elif isinstance(arg[0], list):
154                for dict_ in arg[0]:
155                    for key, value in dict_.items():
156                        self.setitem(key, value, force=force)
157            else:
158                raise TypeError("Input parameter name(s) must be of type dict or list of dicts.")
159        elif len(arg) == 2:
160            keys, values = arg[0], arg[1]  
161            if isinstance(keys, list):
162                if len(keys) == len(values):
163                    for i in range(len(keys)):
164                        self.setitem(keys[i], values[i], force=force)
165                else:
166                    raise ValueError(f"Length of keys {keys} does not match length of {values}")
167            elif isinstance(keys, str):
168                self.setitem(keys, values, force=force)
169            else:
170                raise TypeError("Input parameter name(s) must be of type string or list of strings.")
171    
172    def setDefault(self, keys):
173        """Sets all values to default.
174        """        
175        self.generateDicts()
176        if isinstance(keys, list):
177            for key in keys:
178                self.setitem(key, '', default=True)
179        elif isinstance(keys, str):
180            self.setitem(keys, '', default=True)
181
182
183    def getDefault(self, keys):
184        """Gets default value from the full dictionary.
185
186        Args:
187            keys (str or list): Key of the value to get.
188
189        Raises:
190            TypeError: Input parameter name(s) must be of type string or list of strings.
191
192        Returns:
193            str or list: Value or list of values.
194        """        
195        self.generateDicts()
196        if isinstance(keys, list):
197            got = []
198            for key in keys:
199                default_section, default_val, default_type = matchtoDefaults(key, self.defaultsDict, self.sections)
200                got.append(default_val)
201            return got
202        elif isinstance(keys, str):
203            default_section, default_val, default_type = matchtoDefaults(keys, self.defaultsDict, self.sections)
204            return default_val
205        else:
206            raise TypeError("Input parameter name(s) must be of type string or list of strings.")
207        
208
209
210
211    def get(self, items):
212        """Gets a value from the full dictionary.
213
214        Args:
215            items (str or list): Key of the value to get.
216
217        Raises:
218            TypeError: Input parameter name(s) must be of type string or list of strings.
219
220        Returns:
221            str or list: Value or list of values.
222        """        
223        self.generateDicts()
224        if isinstance(items, list):
225            got = []
226            for item in items:
227                got.append(self.getitem(item))
228            return got
229        elif isinstance(items, str):
230            return self.getitem(items)
231        else:
232            raise TypeError("Input parameter name(s) must be of type string or list of strings.")
233        
234
235
236    def delete(self, keys):
237        """Deletes a value from the full dictionary.
238
239        Args:
240            keys (str or list): Key of the value to delete.
241
242        Raises:
243            TypeError: Input parameter name(s) must be of type string or list of strings.
244        """       
245        self.generateDicts() 
246        if isinstance(keys, list):
247            for key in keys:
248                self.delitem(key)
249        elif isinstance(keys, str):
250            self.delitem(keys)
251        else:
252            raise TypeError("Input parameter name(s) must be of type string or list of strings.")
253
254
255    def check_exists(self):
256        """Checks if the project directory exists.
257        """        
258        if not os.path.exists(self.projectDir):
259            raise FileNotFoundError(f"Project directory {self.projectDir} does not exist.")
260
261    
262    def load_InlistProject(self, inlistPath):
263        """Loads the inlist file.
264
265        Args:
266            inlistPath (str): Path to the inlist file.
267            target (str, optional): If the project is a binary system, specify the star 
268                                    or binary. Defaults to None.
269                                    Input can be 'primary', 'secondary' or 'binary'.
270
271        Raises:
272            ValueError: If the input for argument 'target' is invalid.
273        """        
274        self.check_exists()
275        loader.load(inlistPath, self.projectDir, "inlist_project", binary=self.binary, target=self.target)
276
277    def load_InlistAsteroSearch(self, inlistPath):
278        """Loads the astero_search_controls inlist file.
279
280        Args:
281            inlistPath (str): Path to the inlist file.
282        """        
283        self.check_exists()
284        loader.load(inlistPath, self.projectDir, "inlist_astero_search_controls")
285            
286    
287    def load_InlistPG(self, inlistPath):
288        """Loads the inlist file.
289
290        Args:
291            inlistPath (str): Path to the inlist file.
292
293        Raises:
294            ValueError: If the input for argument 'typeof' is invalid.
295        """        
296        self.check_exists()
297        loader.load(inlistPath, self.projectDir, "inlist_pgstar")
298        
299
300    def load_HistoryColumns(self, HistoryColumns):
301        """Loads the history columns.
302
303        Args:
304            HistoryColumns (str): Path to the history columns file.
305            target (str, optional): If the project is a binary system, specify the star or binary.
306                                    Input 'primary', 'secondary' or 'binary'. Defaults to None.
307        """        
308        self.check_exists()
309        loader.load(HistoryColumns, self.projectDir, "history_columns", binary=self.binary, target=self.target)
310
311
312    def load_ProfileColumns(self, ProfileColumns):
313        """Loads the profile columns.
314
315        Args:
316            ProfileColumns (str): Path to the profile columns file.
317        """  
318        self.check_exists()      
319        loader.load(ProfileColumns, self.projectDir, "profile_columns")
320
321
322    def load_Extras(self, extras_path):
323        """Loads the extras file.
324
325        Args:
326            extras_path (str): Path to the extras file.
327        """  
328        self.check_exists()
329        loader.load(extras_path, self.projectDir, "extras", binary=self.binary, target=self.target)
MesaAccess(project, astero=False, binary=False, target='')
31    def __init__(self, project, astero=False, binary=False, target=''):
32        """Initializes the MesaAccess class.
33
34        Args:
35            project (str): _description_.
36            binary (bool, optional): If the project is a binary. Defaults to False.
37            target (str, optional): If the project is a binary, which star to access. Defaults to ''.
38        """        
39        if binary and target not in [None, 'primary', 'secondary', 'binary']:
40            raise ValueError("Invalid input for argument 'target'")
41        self.project = project
42        self.astero = astero
43        self.binary = binary
44        self.target = target
45        if os.path.isabs(project):
46            self.projectDir = project
47        else:
48            self.projectDir = os.path.join(os.getcwd(), project)
49        envObj = MesaEnvironmentHandler(astero, binary, target)
50        if binary and target == 'binary':
51            self.mesaDir, self.defaultsDir = envObj.mesaDir, envObj.defaultsDir
52            self.sections, self.defaultsFileNames = sections_binary, defaultsFileNames_binary
53            self.inlist_filenames = ["inlist_project"]
54        elif binary and target != 'binary':
55            self.mesaDir, self.defaultsDir = envObj.mesaDir, envObj.defaultsDir
56            self.sections, self.defaultsFileNames = sections_star, defaultsFileNames_star
57            if self.target == 'primary':
58                self.inlist_filenames = ["inlist1"]
59            elif self.target == 'secondary':
60                self.inlist_filenames = ["inlist2"]
61        elif astero:
62            self.mesaDir, self.defaultsDir = envObj.mesaDir, envObj.defaultsDir
63            self.sections, self.defaultsFileNames = sections_astero, defaultsFileNames_astero
64            self.inlist_filenames = ["inlist_project", "inlist_pgstar", "inlist_astero_search_controls"]
65        else:
66            self.mesaDir, self.defaultsDir = envObj.mesaDir, envObj.defaultsDir
67            self.sections, self.defaultsFileNames = sections_star, defaultsFileNames_star
68            self.inlist_filenames = ["inlist_project", "inlist_pgstar"]
69        self.defaultsDict = {}
70        for section in self.sections:
71            self.defaultsDict[section] = readDefaults(self.defaultsFileNames[section], self.defaultsDir)

Initializes the MesaAccess class.

Arguments:
  • project (str): _description_.
  • binary (bool, optional): If the project is a binary. Defaults to False.
  • target (str, optional): If the project is a binary, which star to access. Defaults to ''.
project
astero
binary
target
defaultsDict
def generateDicts(self):
74    def generateDicts(self):
75        """Generates the dictionaries for the inlist files.
76        """        
77        self.inlistDict = {}
78        self.inlistSections = {}
79        for filename in self.inlist_filenames:
80            self.inlistSections[filename], self.inlistDict[filename] = readFile(filename, self.projectDir)
81        # pprint(self.inlistDict)

Generates the dictionaries for the inlist files.

def setitem(self, key, value, default=False, force=False):
 85    def setitem(self, key, value, default=False, force=False):
 86        """Sets a value in the full dictionary.
 87
 88        Args:
 89            key (str): Key of the value to set.
 90            value (str): Value to set.
 91
 92        Raises:
 93            TypeError: Value is not of default type
 94        """        
 95        default_section, default_val, default_type = matchtoDefaults(key, self.defaultsDict, self.sections)
 96        if default:
 97            value = default_val
 98        filename = getFilename(self.astero, self.binary, default_section, self.inlist_filenames)
 99        exists, _ = matchtoFile(key, self.inlistDict[filename], self.inlistSections[filename], default_section)
100        if not force:
101            if not matchTypes(type(value), default_type):
102                raise TypeError(f"Value {value} is not of default type {default_type}")
103        writetoFile(self.projectDir, filename, key, value, exists, default_section, delete=False)

Sets a value in the full dictionary.

Arguments:
  • key (str): Key of the value to set.
  • value (str): Value to set.
Raises:
  • TypeError: Value is not of default type
def getitem(self, item):
107    def getitem(self, item):
108        """Gets a value from the full dictionary.
109
110        Args:
111            item (str): Key of the value to get.
112
113        Returns:
114            str: Value of the key
115        """        
116        default_section, default_val, default_type = matchtoDefaults(item, self.defaultsDict, self.sections)
117        filename = getFilename(self.astero, self.binary, default_section, self.inlist_filenames)
118        return matchtoFile(item, self.inlistDict[filename], self.inlistSections[filename], default_section)[1]

Gets a value from the full dictionary.

Arguments:
  • item (str): Key of the value to get.
Returns:

str: Value of the key

def delitem(self, key):
122    def delitem(self, key):
123        """Deletes a value from the full dictionary.
124
125        Args:
126            key (str): Key of the value to delete.
127
128        Raises:
129            KeyError: Parameter does not exist in inlist file
130        """        
131        default_section, default_val, default_type = matchtoDefaults(key, self.defaultsDict, self.sections)
132        filename = getFilename(self.astero, self.binary, default_section, self.inlist_filenames)
133        exists, _ = matchtoFile(key, self.inlistDict[filename], self.inlistSections[filename], default_section)
134        if exists:
135            writetoFile(self.projectDir, filename, key, _, exists, default_section, delete=True)
136        else:
137            raise KeyError(f"Parameter {key} does not exist in {filename}")

Deletes a value from the full dictionary.

Arguments:
  • key (str): Key of the value to delete.
Raises:
  • KeyError: Parameter does not exist in inlist file
def set(self, *arg, force=False):
139    def set(self, *arg, force=False):
140        """Sets a value in the full dictionary.
141
142        Args:
143            arg (dict or list of dicts): A dict with the keys and values to set or a list of dicts with the keys and values to set.
144        Raises:
145            ValueError: Length of keys does not match length of values
146            TypeError: Input parameter name(s) must be of type string or list of strings.
147        """    
148        self.generateDicts() 
149        if len(arg) == 1:
150            if isinstance(arg[0], dict):
151                for key, value in arg[0].items():
152                    self.setitem(key, value, force=force)
153            elif isinstance(arg[0], list):
154                for dict_ in arg[0]:
155                    for key, value in dict_.items():
156                        self.setitem(key, value, force=force)
157            else:
158                raise TypeError("Input parameter name(s) must be of type dict or list of dicts.")
159        elif len(arg) == 2:
160            keys, values = arg[0], arg[1]  
161            if isinstance(keys, list):
162                if len(keys) == len(values):
163                    for i in range(len(keys)):
164                        self.setitem(keys[i], values[i], force=force)
165                else:
166                    raise ValueError(f"Length of keys {keys} does not match length of {values}")
167            elif isinstance(keys, str):
168                self.setitem(keys, values, force=force)
169            else:
170                raise TypeError("Input parameter name(s) must be of type string or list of strings.")

Sets a value in the full dictionary.

Arguments:
  • arg (dict or list of dicts): A dict with the keys and values to set or a list of dicts with the keys and values to set.
Raises:
  • ValueError: Length of keys does not match length of values
  • TypeError: Input parameter name(s) must be of type string or list of strings.
def setDefault(self, keys):
172    def setDefault(self, keys):
173        """Sets all values to default.
174        """        
175        self.generateDicts()
176        if isinstance(keys, list):
177            for key in keys:
178                self.setitem(key, '', default=True)
179        elif isinstance(keys, str):
180            self.setitem(keys, '', default=True)

Sets all values to default.

def getDefault(self, keys):
183    def getDefault(self, keys):
184        """Gets default value from the full dictionary.
185
186        Args:
187            keys (str or list): Key of the value to get.
188
189        Raises:
190            TypeError: Input parameter name(s) must be of type string or list of strings.
191
192        Returns:
193            str or list: Value or list of values.
194        """        
195        self.generateDicts()
196        if isinstance(keys, list):
197            got = []
198            for key in keys:
199                default_section, default_val, default_type = matchtoDefaults(key, self.defaultsDict, self.sections)
200                got.append(default_val)
201            return got
202        elif isinstance(keys, str):
203            default_section, default_val, default_type = matchtoDefaults(keys, self.defaultsDict, self.sections)
204            return default_val
205        else:
206            raise TypeError("Input parameter name(s) must be of type string or list of strings.")

Gets default value from the full dictionary.

Arguments:
  • keys (str or list): Key of the value to get.
Raises:
  • TypeError: Input parameter name(s) must be of type string or list of strings.
Returns:

str or list: Value or list of values.

def get(self, items):
211    def get(self, items):
212        """Gets a value from the full dictionary.
213
214        Args:
215            items (str or list): Key of the value to get.
216
217        Raises:
218            TypeError: Input parameter name(s) must be of type string or list of strings.
219
220        Returns:
221            str or list: Value or list of values.
222        """        
223        self.generateDicts()
224        if isinstance(items, list):
225            got = []
226            for item in items:
227                got.append(self.getitem(item))
228            return got
229        elif isinstance(items, str):
230            return self.getitem(items)
231        else:
232            raise TypeError("Input parameter name(s) must be of type string or list of strings.")

Gets a value from the full dictionary.

Arguments:
  • items (str or list): Key of the value to get.
Raises:
  • TypeError: Input parameter name(s) must be of type string or list of strings.
Returns:

str or list: Value or list of values.

def delete(self, keys):
236    def delete(self, keys):
237        """Deletes a value from the full dictionary.
238
239        Args:
240            keys (str or list): Key of the value to delete.
241
242        Raises:
243            TypeError: Input parameter name(s) must be of type string or list of strings.
244        """       
245        self.generateDicts() 
246        if isinstance(keys, list):
247            for key in keys:
248                self.delitem(key)
249        elif isinstance(keys, str):
250            self.delitem(keys)
251        else:
252            raise TypeError("Input parameter name(s) must be of type string or list of strings.")

Deletes a value from the full dictionary.

Arguments:
  • keys (str or list): Key of the value to delete.
Raises:
  • TypeError: Input parameter name(s) must be of type string or list of strings.
def check_exists(self):
255    def check_exists(self):
256        """Checks if the project directory exists.
257        """        
258        if not os.path.exists(self.projectDir):
259            raise FileNotFoundError(f"Project directory {self.projectDir} does not exist.")

Checks if the project directory exists.

def load_InlistProject(self, inlistPath):
262    def load_InlistProject(self, inlistPath):
263        """Loads the inlist file.
264
265        Args:
266            inlistPath (str): Path to the inlist file.
267            target (str, optional): If the project is a binary system, specify the star 
268                                    or binary. Defaults to None.
269                                    Input can be 'primary', 'secondary' or 'binary'.
270
271        Raises:
272            ValueError: If the input for argument 'target' is invalid.
273        """        
274        self.check_exists()
275        loader.load(inlistPath, self.projectDir, "inlist_project", binary=self.binary, target=self.target)

Loads the inlist file.

Arguments:
  • inlistPath (str): Path to the inlist file.
  • target (str, optional): If the project is a binary system, specify the star or binary. Defaults to None. Input can be 'primary', 'secondary' or 'binary'.
Raises:
  • ValueError: If the input for argument 'target' is invalid.
def load_InlistAsteroSearch(self, inlistPath):
277    def load_InlistAsteroSearch(self, inlistPath):
278        """Loads the astero_search_controls inlist file.
279
280        Args:
281            inlistPath (str): Path to the inlist file.
282        """        
283        self.check_exists()
284        loader.load(inlistPath, self.projectDir, "inlist_astero_search_controls")

Loads the astero_search_controls inlist file.

Arguments:
  • inlistPath (str): Path to the inlist file.
def load_InlistPG(self, inlistPath):
287    def load_InlistPG(self, inlistPath):
288        """Loads the inlist file.
289
290        Args:
291            inlistPath (str): Path to the inlist file.
292
293        Raises:
294            ValueError: If the input for argument 'typeof' is invalid.
295        """        
296        self.check_exists()
297        loader.load(inlistPath, self.projectDir, "inlist_pgstar")

Loads the inlist file.

Arguments:
  • inlistPath (str): Path to the inlist file.
Raises:
  • ValueError: If the input for argument 'typeof' is invalid.
def load_HistoryColumns(self, HistoryColumns):
300    def load_HistoryColumns(self, HistoryColumns):
301        """Loads the history columns.
302
303        Args:
304            HistoryColumns (str): Path to the history columns file.
305            target (str, optional): If the project is a binary system, specify the star or binary.
306                                    Input 'primary', 'secondary' or 'binary'. Defaults to None.
307        """        
308        self.check_exists()
309        loader.load(HistoryColumns, self.projectDir, "history_columns", binary=self.binary, target=self.target)

Loads the history columns.

Arguments:
  • HistoryColumns (str): Path to the history columns file.
  • target (str, optional): If the project is a binary system, specify the star or binary. Input 'primary', 'secondary' or 'binary'. Defaults to None.
def load_ProfileColumns(self, ProfileColumns):
312    def load_ProfileColumns(self, ProfileColumns):
313        """Loads the profile columns.
314
315        Args:
316            ProfileColumns (str): Path to the profile columns file.
317        """  
318        self.check_exists()      
319        loader.load(ProfileColumns, self.projectDir, "profile_columns")

Loads the profile columns.

Arguments:
  • ProfileColumns (str): Path to the profile columns file.
def load_Extras(self, extras_path):
322    def load_Extras(self, extras_path):
323        """Loads the extras file.
324
325        Args:
326            extras_path (str): Path to the extras file.
327        """  
328        self.check_exists()
329        loader.load(extras_path, self.projectDir, "extras", binary=self.binary, target=self.target)

Loads the extras file.

Arguments:
  • extras_path (str): Path to the extras file.