Jammy2211 / PyAutoGalaxy

PyAutoGalaxy: Open-Source Multiwavelength Galaxy Structure & Morphology
https://pyautogalaxy.readthedocs.io/
MIT License
28 stars 14 forks source link

Cant write Galaxy to / from json #26

Open Jammy2211 opened 2 years ago

Jammy2211 commented 2 years ago

The following simple unit test:

def test__to_and_from_dict():

    galaxy = ag.lp.EllSersic(centre=(0.0, 0.0))

    galaxy.output_to_json(file_path="mge.json")

    galaxy = ag.Galaxy.from_json(file_path="mge.json")

Gives the following exception:

cls = <class 'autofit.mapper.prior.abstract.Prior'>
prior_dict = {'centre': [0.0, 0.0], 'effective_radius': 0.6, 'elliptical_comps': [0.0, 0.0], 'intensity': 0.1, ...}

    @classmethod
    def from_dict(cls, prior_dict: dict) -> Union["Prior", DeferredArgument]:
        """
        Returns a prior from a JSON representation.

        Parameters
        ----------
        prior_dict : dict
            A dictionary representation of a prior including a type (e.g. Uniform) and all constructor arguments.

        Returns
        -------
        An instance of a child of this class.
        """
        if prior_dict["type"] == "Constant":
            return prior_dict["value"]
        if prior_dict["type"] == "Deferred":
            return DeferredArgument()

        from .prior import UniformPrior
        from .prior import LogUniformPrior
        from .prior import GaussianPrior

        prior_type_dict = {
            "Uniform": UniformPrior,
            "LogUniform": LogUniformPrior,
            "Gaussian": GaussianPrior,
        }

        # noinspection PyProtectedMember
>       return prior_type_dict[prior_dict["type"]](
            **{
                key: value
                for key, value in prior_dict.items()
                if key not in ("type", "width_modifier", "gaussian_limits")
            }
        )
E       KeyError: 'autogalaxy.profiles.light_profiles.light_profiles.EllSersic'