Method for list of all model files #1637
-
Hi, Is there a method to obtain a list of all model files required to execute a simulation? For example, I have a simulation that includes parent and child models, both with external arrays, time series files, observation files, advanced stress package input files, exchange files plus the standard package input files. When writing the simulation flopy is aware of all the filenames used in the simulation so I assume it must be accessible, but I am too stoopid :) Cheers, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@laat0003, there is unfortunately no single method that returns a list of all files in a simulation. However, by iterating through a tree of objects you should be able to do this. I can add a method to flopy that does this, but I may not get to it for a little while. If you would like to try to do this yourself, below I describe the tree structure you will need to traverse to get the filenames. The objects are in bold and the methods/attributes used to access those objects are in italics.
At the top level, the simulation object can contain both model and package objects. Use the model_dict property to get all of the simulation's model objects in a dictionary. You can get all the simulation's package objects by calling the get_package method (without parameters). Once you have model and package objects, you can get any packages in the model or sub-packages in the package with the same get_package call. Use the filename property to access each package's filename. In order to get the files of external datasets you will need to iterate further down the tree into the package's blocks and data. The package's blocks attribute is a dictionary of the package's blocks. Similarly, each block has a datasets property. Dataset's that can be stored externally have a get_record method that returns a dictionary. Note that datasets that can not be stored externally do not have the get_record method, so you will need to check for this "hasattr(obj, 'get_record')". Since some datasets can be divided up by layer and by stress period and each part of the dataset can be stored separately, the dictionary returned may be a dictionary of dictionaries, with the first dictionary pointing to each layer or stress period of the data. Iterate through the dictionary tree searching for "filename" keys, whose value will be the filename of the stored data. Lastly, the simulation and model name files will not be returned with the other packages. This in intentional since, in general, it is a bad idea to mess with these. Flopy builds these and keeps them updated for you. The name files can be accessed from the simulation and model objects with the name_file attribute. The name file objects have the same filename attribute as the other packages. |
Beta Was this translation helpful? Give feedback.
@laat0003, there is unfortunately no single method that returns a list of all files in a simulation. However, by iterating through a tree of objects you should be able to do this. I can add a method to flopy that does this, but I may not get to it for a little while. If you would like to try to do this yourself, below I describe the tree structure you will need to traverse to get the filenames. The objects are in bold and the methods/attributes used to access those objects are in italics.