Comments (2)
Hi,
Could you send the full script you are usingt o model lenses?
I suspect the solution is to simply run the script for each lens one at a time, as opposed to to modeling all lenses in the same script (I assume you have a for loop in your script cycling over the data).
So, something like:
from os import path
import sys
import json
workspace_path = path.join(path.sep, "your", "workspace", "path")
"""
__AUTOLENS + DATA__
"""
import autofit as af
import autolens as al
dataset_name = [
"lens_0",
"lens_1",
"lens_2",
]
dataset_name = dataset_name[int(sys.argv[1])] # sys.argv[1] loads the first value passwed in from when Python is run
dataset_path = path.join(cosma_dataset_path, dataset_label, dataset_name)
imaging = al.Imaging.from_fits(
image_path=f"{dataset_path}/image_lens_light_scaled.fits",
psf_path=f"{dataset_path}/psf.fits",
noise_map_path=f"{dataset_path}/noise_map_scaled.fits",
pixel_scales=pixel_scales,
name=dataset_name,
)
If the above script is called model.py
and you run python3 model.py 0
, the 0
is passed to int(sys.argv[1])
such that the lens_0
string and dataset is loaded and used.
You can then simply run python3 model.py 1
and so on to model all lenses.
from pyautolens.
Thanks for your answer!
Could you send the full script you are usingt o model lenses?
Sure, here is the class that manages the fit process:
class pipeline:
def __init__(self, system_identifier_name, lens_redshift, source_redshift, pixel_scales, core_usage=5, session=None, dataset_name=None):
self.system_identifier_name = system_identifier_name
self.lens_redshift = lens_redshift
self.source_redshift = source_redshift
self.pixel_scales = pixel_scales
self.core_usage = core_usage
self.session = session
self.dataset_name = dataset_name
def fit_system_autolens(self, residual_image, original_noise_map, original_psf, nlive, fit_mcmc=True, system_radius=8.0):
image_object = al.Imaging(al.Array2D.manual(np.array(residual_image, dtype=float), pixel_scales=self.pixel_scales), # cutout
al.Array2D.manual(np.array(original_noise_map, dtype=float), pixel_scales=self.pixel_scales), # noise_map
al.Kernel2D.manual(np.array(original_psf, dtype=float), pixel_scales=self.pixel_scales, shape_native=(100, 100))) # psf
mask = al.Mask2D.circular(shape_native=image_object.shape_native, pixel_scales=image_object.pixel_scales, radius=system_radius)
masked_object = image_object.apply_mask(mask=mask)
# source galaxy model
bulge = af.Model(al.lmp.EllSersic)
source_galaxy_model = af.Model(al.Galaxy,
redshift=self.source_redshift,
bulge=bulge)
# lens galaxy model
lens_galaxy_model = af.Model(al.Galaxy,
redshift=self.lens_redshift ,
mass=al.mp.EllIsothermal)
autolens_model = af.Collection(galaxies=af.Collection(lens=lens_galaxy_model, source=source_galaxy_model))
# autolens fit full bright distribution
if fit_mcmc:
search = af.Emcee(
path_prefix='./',
name=str(self.system_identifier_name)+'_source_light',
unique_tag = self.dataset_name,
session=self.session)
else:
print(str(self.system_identifier_name) + '_source_light', self.dataset_name)
search = af.DynestyStatic(path_prefix = './',
name = str(self.system_identifier_name) + '_source_light',
unique_tag = self.dataset_name,
nlive = nlive,
number_of_cores = self.core_usage, # be carefull here! verify your core numbers
session=self.session)
analysis = al.AnalysisImaging(dataset=masked_object)
result = search.fit(model=autolens_model, analysis=analysis)
return result
But, I agree, running a script should be a better solution to this problem. Thank you!
from pyautolens.
Related Issues (20)
- Self interacting dark matter profile deflections
- Hernquist Light Profile
- Decide how to pass size of projected grid and whether to remove its centre through code
- Getting an AttributeError in the mass fitting code given on the GitHub page. HOT 6
- Dude about how to translate the results from pyautolens to lenstronomy for basic modeling. HOT 4
- Saving / Loading a Tracer to .json format
- Source Plane Interpolation Mapping
- Voronoi Interpolation HOT 4
- Delaunay Interpolation HOT 7
- Delaunay Implementation HOT 9
- W Tilde Imaging With Interpolation
- Create Tracer from result with same API as instance
- Galaxy.dict() not returning parameters correctly HOT 3
- 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
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.