Comments (3)
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.
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.
I have put up the following PR which will allow the following API to work:
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)
- Delaunay Interpolation HOT 7
- Delaunay Implementation HOT 9
- W Tilde Imaging With Interpolation
- Create Tracer from result with same API as instance
- How to handle memory error while modeling a dataset? HOT 2
- Unit test failing due to from_dict HOT 1
- Multiprocessing RuntimeError HOT 13
- API consistency issues? HOT 1
- Multicore task in a cluster HOT 10
- Autoconf conf.py - Key error HOT 5
- Fix Aggregator Tests
- Database session support for all new types of output
- can't install autolens via pip using jupiter notebook HOT 20
- pylops/scipy.sparse.linalg import does not exist
- Slam script incorrect ResultInterferometer and ResultImaging adapt_image calls HOT 58
- JAX on older HPC issues HOT 2
- Pixelization interferometer search reconstructs negative fluxes HOT 4
- Slam pipeline positions not able to update from previous search HOT 6
- Slam pipeline chaining using mass_total tracer; PowerLaw not working with chaining_util HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyautolens.