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

Cant write Galaxy to / from json #26

Open
Jammy2211 opened this issue May 21, 2022 · 0 comments
Open

Cant write Galaxy to / from json #26

Jammy2211 opened this issue May 21, 2022 · 0 comments
Assignees

Comments

@Jammy2211
Copy link
Owner

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'
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