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

Make Cosmology JSonable #112

Open
Jammy2211 opened this issue Jul 24, 2023 · 0 comments
Open

Make Cosmology JSonable #112

Jammy2211 opened this issue Jul 24, 2023 · 0 comments
Assignees

Comments

@Jammy2211
Copy link
Owner

The following classes are also pickled in the Analysis:

https://github.com/Jammy2211/PyAutoGalaxy/tree/feature/autofit_outputs/autogalaxy/cosmology

The pickling is here:

https://github.com/Jammy2211/PyAutoGalaxy/blob/feature/autofit_outputs/autogalaxy/analysis/analysis.py

  def save_attributes(self, paths: af.DirectoryPaths):
        """
        Before the model-fit via the non-linear search begins, this routine saves attributes of the `Analysis` object
        to the `pickles` folder such that they can be loaded after the analysis using PyAutoFit's database and aggregator
        tools.

        For this analysis the following are output:

        - The dataset's data.
        - The dataset's noise-map.
        - The settings associated with the dataset.
        - The settings associated with the inversion.
        - The settings associated with the pixelization.
        - The Cosmology.
        - The adapt dataset's model image and galaxy images, if used.

        It is common for these attributes to be loaded by many of the template aggregator functions given in the
        `aggregator` modules. For example, when using the database tools to reperform a fit, this will by default
        load the dataset, settings and other attributes necessary to perform a fit using the attributes output by
        this function.

        Parameters
        ----------
        paths
            The PyAutoFit paths object which manages all paths, e.g. where the non-linear search outputs are stored, visualization,
            and the pickled objects used by the aggregator output by this function.
        """
        dataset_path = paths._files_path / "dataset"

        self.dataset.output_to_fits(
            data_path=dataset_path / "data.fits",
            noise_map_path=dataset_path / "noise_map.fits",
            overwrite=True,
        )
        self.dataset.settings.output_to_json(file_path=dataset_path / "settings.json")

        self.settings_inversion.output_to_json(
            file_path=paths._files_path / "settings_inversion.json"
        )
        self.settings_pixelization.output_to_json(
            file_path=paths._files_path / "settings_pixelization.json"
        )
        paths.save_object("cosmology", self.cosmology)

        with open(paths._files_path / "cosmology.pickle", "wb") as f:
            pickle.dump(self.cosmology, f)

        adapt_path = paths._files_path / "adapt"

        if self.adapt_model_image is not None:
            self.adapt_model_image.output_to_fits(
                file_path=adapt_path / "adapt_model_image.fits", overwrite=True
            )

        if self.adapt_galaxy_image_path_dict is not None:
            for key, value in self.adapt_galaxy_image_path_dict.items():
                value.output_to_fits(
                    file_path=adapt_path / f"{key}.fits",
                    overwrite=True,
                )

Note these are on the feature/autofit_outputs/ branch.

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