Giter Club home page Giter Club logo

Comments (3)

Jammy2211 avatar Jammy2211 commented on July 23, 2024

The type instance is saved as a string rather than a callable to the function (same for individual mass/light profiles)

Digging deep into the code, I think this is the intended behavior.

To load a Galaxy (or any Dictable object, e.g. a Plane or Tracer) from a .json file you should be able to do the following:

import json

from autoconf.dictable import Dictable
import autogalaxy as ag

json_file = "galaxy.json"

galaxy = ag.Galaxy(
        redshift=1.0, pixelization=ag.pix.VoronoiMagnification(), regularization=ag.reg.AdaptiveBrightness()
    )

with open(json_file, "w+") as f:
    json.dump(galaxy.dict(), f, indent=4)

with open(json_file, "r+") as f:
    galaxy_dict = json.load(f)

galaxy_from_dict = Dictable.from_dict(galaxy_dict)

print(galaxy_from_dict)

It is a bit odd that doing the following:

galaxy_from_dict = ag.Galaxy.from_dict(galaxy_dict)

Raises the following exception:

<autoarray.inversion.regularization.adaptive_brightness.AdaptiveBrightness object at 0x0000021B2F377BB0>
Traceback (most recent call last):
  File "C:/Users/Jammy/Code/PyAuto/autolens_workspace_test/galaxy_dict.py", line 22, in <module>
    galaxy_from_dict = ag.Galaxy.from_dict(galaxy_dict)
  File "C:\Users\Jammy\Code\PyAuto\PyAutoFit\autofit\mapper\model_object.py", line 80, in from_dict
    type_ = d["type"]
KeyError: 'type'

@rhayes777 I guess this is because it is expecting that the Galaxy was output as a Model object, as opposed to an instance of a Galaxy?

from pyautolens.

Jammy2211 avatar Jammy2211 commented on July 23, 2024

If a parameter is drawn from a numpy array (e.g. when randomising and drawing), the dict returns the type rather than the value of the parameter.

I didn't clock before that you were inputting parameters as a value of a NumPy array.

I would simply convert these to floats before inputting them, as things like a Galaxy are not inspecting numpy array inputs:

lens = al.Galaxy(redshift=1.,
                 light = al.lp.EllSersic(intensity = float(np.array([0.1])[0])),
                 mass=al.mp.EllIsothermal())

from pyautolens.

Jammy2211 avatar Jammy2211 commented on July 23, 2024

I have put up the following PR which will allow the following API to work:

rhayes777/PyAutoConf#18

        tracer.output_to_json(file_path=json_file)

        tracer_from_json = al.Tracer.from_json(file_path=json_file)
        galaxy.output_to_json(file_path=json_file)

        galaxy_from_json = al.Galaxy.from_json(file_path=json_file)

from pyautolens.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.