Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use prefix for DatabasePaths #812

Open
Jammy2211 opened this issue Sep 14, 2023 · 1 comment
Open

Use prefix for DatabasePaths #812

Jammy2211 opened this issue Sep 14, 2023 · 1 comment
Assignees

Comments

@Jammy2211
Copy link
Collaborator

A prefix variable is used in DirectoryPaths to store files in sub-directories:

    def save_json(self, name, object_dict: Union[dict, list], prefix : str = ""):
        """
        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.
        """
        with open_(self._path_for_json(name, prefix), "w+") as f:
            json.dump(object_dict, f, indent=4)
    def _path_for_json(self, name, prefix : str = "") -> Path:
        return self._files_path / prefix / f"{name}.json"

This means that the files folder has a sub-folder named the prefix and when loading from the aggregator we specify this folder:

data = aa.Array2D.from_primary_hdu(primary_hdu=fit.value(name="dataset.data"))

Can we implement the prefix in all DatabasePaths functions so it is stored in a sub folder in the .sqlite database? Is this a sensible thing to do? We want the API to mimick that of DirectoryPaths so the same function:

data = aa.Array2D.from_primary_hdu(primary_hdu=fit.value(name="dataset.data"))

Can be called irrespective of whether the database was run as a session or built via scrape.

@Jammy2211
Copy link
Collaborator Author

The following example script shows this issue:

https://github.com/Jammy2211/autofit_workspace_test/blob/main/scripts/database/session/general.py

It raises the exception:

Traceback (most recent call last):
  File "/mnt/c/Users/Jammy/Code/PyAuto/autofit_workspace_test/scripts/database/session/general.py", line 170, in <module>
    for data in agg.values("dataset.data"):
  File "/mnt/c/Users/Jammy/Code/PyAuto/PyAutoFit/autofit/database/aggregator/aggregator.py", line 120, in values
    value = fit[name]
  File "/mnt/c/Users/Jammy/Code/PyAuto/PyAutoFit/autofit/database/model/fit.py", line 310, in __getitem__
    return getattr(self, item)
AttributeError: 'Fit' object has no attribute 'dataset.data'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants