autofit.DirectoryPaths#
- class autofit.DirectoryPaths(name: str | None = None, path_prefix: PathLike | None = None, is_identifier_in_paths=True, parent: AbstractPaths | None = None, unique_tag: str | None = None, identifier: str = None, image_path_suffix: str = '')[source]#
Bases:
AbstractPathsManages the path structure for NonLinearSearch output, for analyses both not using and using the search API. Use via non-linear searches requires manual input of paths, whereas the search API manages this using the search attributes.
The output path within which the Paths objects path structure is contained is set via PyAutoConf, using the command:
from autoconf import conf conf.instance = conf.Config(output_path=”path/to/output”)
If we assume all the input strings above are used with the following example names:
name = “name” path_prefix = “folder_0/folder_1”
The output path of the NonLinearSearch results will be:
/path/to/output/folder_0/folder_1/name
- Parameters:
name – The name of the non-linear search, which is used as a folder name after the
path_prefix. For searchs this name is thename.path_prefix – A prefixed path that appears after the output_path but before the name variable.
is_identifier_in_paths – If True output path and symlink path terminate with an identifier generated from the search and model
parent – The parent paths object of this paths object.
unique_tag – A unique tag for the search, used to differentiate between searches with the same name.
identifier – A custom identifier for the search, if this is not None it will be used instead of the automatically generated identifier
image_path_suffix – A suffix which is appended to the image path. This is used to differentiate between different image outputs, for example the image of the starting point of an MLE.
Methods
Mark the search as complete by saving a file
Create a paths object which is the child of some parent paths object.
Paths for an analysis which is a child of another analysis.
Is there a file pickles/{name}.pickle?
load_arrayLoad an HDU from a fits file in the fits directory of the search.
load_jsonload_latent_samplesLoad a serialised object with the given name.
Load samples from the database
load_samples_infoLoad samples summary from the database.
Load the internal representation of a non-linear search from a pickle or dill file.
output_model_resultsRemove the object with the given name from the pickles folder.
Remove the internal representation of a non-linear search.
restoreCopy files from the
.zipfile to the samples folder.save_allSave a numpy array as a csv file in the csvs directory of the search.
Save an HDU as a fits file in the fits directory of the search.
save_identifierSave a dictionary as a json file in the jsons directory of the search.
Write out the latent variables of the model to a file.
Serialise an object using dill and save it to the pickles directory of the search.
save_parent_identifierSave the final-result samples associated with the phase as a pickle
Save samples summary to the database.
Save the internal representation of a non-linear search as dill file.
save_summarysave_unique_tagzip_removeCopy files from the sym linked search folder then remove the sym linked folder.
Attributes
identifierimage_pathThe path to the image folder.
Has the search been completed?
Is this a grid search which comprises a number of child searches?
non_linear_nameoutput_pathThe path to the output information for a search.
The search performed before this search.
profile_pathThe path to the profile folder.
Load the samples associated with the search from the output directory.
search_internal_pathThe path to the samples folder.
- save_object(name: str, obj: object, prefix: str = '')[source]#
Serialise an object using dill and save it to the pickles directory of the search.
- Parameters:
name – The name of the object
obj – A serialisable object
prefix – A prefix to add to the path which is the name of the folder the file is saved in.
- save_json(name, object_dict: dict | list, prefix: str = '')[source]#
Save a dictionary as a json file in the jsons directory of the search.
- Parameters:
name – The name of the json file
object_dict – The dictionary to save
prefix – A prefix to add to the path which is the name of the folder the file is saved in.
- save_array(name: str, array: ndarray)[source]#
Save a numpy array as a csv file in the csvs directory of the search.
- Parameters:
name – The name of the csv file
array – The numpy array to save
- save_fits(name: str, fits, prefix: str = '')[source]#
Save an HDU as a fits file in the fits directory of the search.
- Parameters:
name – The name of the fits file
fits – The HDUList to save
prefix – A prefix to add to the path which is the name of the folder the file is saved in.
- load_fits(name: str, prefix: str = '')[source]#
Load an HDU from a fits file in the fits directory of the search.
- Parameters:
name – The name of the fits file
prefix – A prefix to add to the path which is the name of the folder the file is saved in.
- Return type:
The loaded HDU.
- load_object(name: str, prefix: str = '')[source]#
Load a serialised object with the given name.
e.g. if the name is ‘model’ then pickles/model.pickle is loaded.
- Parameters:
name – The name of a serialised object
prefix – A prefix to add to the path which is the name of the folder the file is saved in.
- Return type:
The deserialised object
- remove_object(name: str)[source]#
Remove the object with the given name from the pickles folder.
- Parameters:
name – The name of a pickle file excluding .pickle
- save_search_internal(obj)[source]#
Save the internal representation of a non-linear search as dill file.
The results in this representation are required to use a search’s in-built tools for visualization, analysing samples and other tasks.
- load_search_internal()[source]#
Load the internal representation of a non-linear search from a pickle or dill file.
The results in this representation are required to use a search’s in-built tools for visualization, analysing samples and other tasks.
- Return type:
The results of the non-linear search in its internal representation.
- remove_search_internal()[source]#
Remove the internal representation of a non-linear search.
This deletes the entire search_internal folder, including a .pickle / .dill file containing the interal results and files with the timer values.
This folder can often have a large filesize, thus deleting it can reduce hard-disk use of the model-fit.
- property samples#
Load the samples associated with the search from the output directory.
- save_latent_samples(latent_samples)[source]#
Write out the latent variables of the model to a file.
- Parameters:
latent_samples – Samples describing the latent variables of the model
- save_samples_summary(samples_summary: SamplesSummary, name='samples_summary')[source]#
Save samples summary to the database.
- property parent: AbstractPaths#
The search performed before this search. For example, a search that is then compared to searches during a grid search.
- create_child(name: str | None = None, path_prefix: str | None = None, is_identifier_in_paths: bool | None = None, identifier: str | None = None) AbstractPaths[source]#
Create a paths object which is the child of some parent paths object. This is done during a GridSearch so that results can be stored in the correct directory.
- Parameters:
name
path_prefix
is_identifier_in_paths – If False then this path’s identifier will not be added to its output path.
identifier
- Return type:
A new paths object