-
Notifications
You must be signed in to change notification settings - Fork 95
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
Not able to add NFW_MC lens to a mock image #528
Comments
@PrayaagKatta is this still relevant? Just checking. What astropy version are you using? |
Hey @sibirrer, yes I am still facing this issue. If it helps, I can also give the function I am using to make the mock, let me know! The astropy version is 5.3.1 |
is the input mass a float and the redshift as well? Please state the entire function and input that leads to this error message |
The function is -
And the input is -
|
hmm, unclear what's happening here. Perhaps @dangilman knows? |
Hey, I was trying to create a mock image with the ImageModel class. It does work with a Pseudo Jaffe profile, but I am getting this error when I try with a NFW_MC profile -
`
File ~/.local/lib/python3.10/site-packages/lenstronomy/ImSim/image_model.py:333, in ImageModel.image(self, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, kwargs_extinction, kwargs_special, unconvolved, source_add, lens_light_add, point_source_add)
316 def image(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None,
317 kwargs_extinction=None, kwargs_special=None, unconvolved=False, source_add=True, lens_light_add=True,
318 point_source_add=True):
319 """
320
321 make an image with a realisation of linear parameter values "param"
(...)
331 :return: 2d array of surface brightness pixels of the simulation
332 """
--> 333 return self._image(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, kwargs_extinction, kwargs_special,
334 unconvolved, source_add, lens_light_add, point_source_add)
File ~/.local/lib/python3.10/site-packages/lenstronomy/ImSim/image_model.py:355, in ImageModel._image(self, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, kwargs_extinction, kwargs_special, unconvolved, source_add, lens_light_add, point_source_add)
353 model = np.zeros(self.Data.num_pixel_axes)
354 if source_add is True:
--> 355 model += self._source_surface_brightness(kwargs_source, kwargs_lens, kwargs_extinction=kwargs_extinction,
356 kwargs_special=kwargs_special, unconvolved=unconvolved)
357 if lens_light_add is True:
358 model += self._lens_surface_brightness(kwargs_lens_light, unconvolved=unconvolved)
File ~/.local/lib/python3.10/site-packages/lenstronomy/ImSim/image_model.py:157, in ImageModel._source_surface_brightness(self, kwargs_source, kwargs_lens, kwargs_extinction, kwargs_special, unconvolved, de_lensed, k, update_pixelbased_mapping)
151 return self._source_surface_brightness_pixelbased(kwargs_source, kwargs_lens=kwargs_lens,
152 kwargs_extinction=kwargs_extinction,
153 kwargs_special=kwargs_special,
154 unconvolved=unconvolved, de_lensed=de_lensed, k=k,
155 update_mapping=update_pixelbased_mapping)
156 else:
--> 157 return self._source_surface_brightness_analytical(kwargs_source, kwargs_lens=kwargs_lens,
158 kwargs_extinction=kwargs_extinction,
159 kwargs_special=kwargs_special,
160 unconvolved=unconvolved, de_lensed=de_lensed, k=k)
File ~/.local/lib/python3.10/site-packages/lenstronomy/ImSim/image_model.py:180, in ImageModel._source_surface_brightness_analytical(self, kwargs_source, kwargs_lens, kwargs_extinction, kwargs_special, unconvolved, de_lensed, k)
178 source_light = self.SourceModel.surface_brightness(ra_grid, dec_grid, kwargs_source, k=k)
179 else:
--> 180 source_light = self.source_mapping.image_flux_joint(ra_grid, dec_grid, kwargs_lens, kwargs_source, k=k)
181 source_light *= self._extinction.extinction(ra_grid, dec_grid, kwargs_extinction=kwargs_extinction,
182 kwargs_special=kwargs_special)
184 # multiply with primary beam before convolution
File ~/.local/lib/python3.10/site-packages/lenstronomy/ImSim/image2source_mapping.py:120, in Image2SourceMapping.image_flux_joint(self, x, y, kwargs_lens, kwargs_source, k)
110 """
111
112 :param x: coordinate in image plane
(...)
117 :return: surface brightness of all joint light components at image position (x, y)
118 """
119 if self._multi_source_plane is False:
--> 120 x_source, y_source = self._lensModel.ray_shooting(x, y, kwargs_lens)
121 return self._lightModel.surface_brightness(x_source, y_source, kwargs_source, k=k)
122 else:
File ~/.local/lib/python3.10/site-packages/lenstronomy/LensModel/lens_model.py:117, in LensModel.ray_shooting(self, x, y, kwargs, k)
105 def ray_shooting(self, x, y, kwargs, k=None):
106 """
107 maps image to source position (inverse deflection)
108
(...)
115 :return: source plane positions corresponding to (x, y) in the image plane
116 """
--> 117 return self.lens_model.ray_shooting(x, y, kwargs, k=k)
File ~/.local/lib/python3.10/site-packages/lenstronomy/LensModel/single_plane.py:26, in SinglePlane.ray_shooting(self, x, y, kwargs, k)
14 def ray_shooting(self, x, y, kwargs, k=None):
15 """
16 maps image to source position (inverse deflection)
17 :param x: x-position (preferentially arcsec)
(...)
23 :return: source plane positions corresponding to (x, y) in the image plane
24 """
---> 26 dx, dy = self.alpha(x, y, kwargs, k=k)
27 return x - dx, y - dy
File ~/.local/lib/python3.10/site-packages/lenstronomy/LensModel/single_plane.py:92, in SinglePlane.alpha(self, x, y, kwargs, k)
90 for i, func in enumerate(self.func_list):
91 if bool_list[i] is True:
---> 92 f_x_i, f_y_i = func.derivatives(x, y, **kwargs[i])
93 f_x += f_x_i
94 f_y += f_y_i
File ~/.local/lib/python3.10/site-packages/lenstronomy/LensModel/Profiles/nfw_mass_concentration.py:99, in NFWMC.derivatives(self, x, y, logM, concentration, center_x, center_y)
95 def derivatives(self, x, y, logM, concentration, center_x=0, center_y=0):
96 """
97 returns df/dx and df/dy of the function (integral of NFW)
98 """
---> 99 Rs, alpha_Rs = self._m_c2deflections(logM, concentration)
100 return self._nfw.derivatives(x, y, Rs, alpha_Rs, center_x, center_y)
File ~/.local/lib/python3.10/site-packages/lenstronomy/LensModel/Profiles/nfw_mass_concentration.py:54, in NFWMC._m_c2deflections(self, logM, concentration)
52 return self._Rs_static, self._alpha_Rs_static
53 M = 10 ** logM
---> 54 Rs, alpha_Rs = self._lens_cosmo.nfw_physical2angle(M, concentration)
55 return Rs, alpha_Rs
File ~/.local/lib/python3.10/site-packages/lenstronomy/Cosmo/lens_cosmo.py:195, in LensCosmo.nfw_physical2angle(self, M, c)
187 def nfw_physical2angle(self, M, c):
188 """
189 converts the physical mass and concentration parameter of an NFW profile into the lensing quantities
190
(...)
193 :return: Rs_angle (angle at scale radius) (in units of arcsec), alpha_Rs (observed bending angle at the scale radius
194 """
--> 195 rho0, Rs, r200 = self.nfwParam_physical(M, c)
196 Rs_angle = Rs / self.dd / const.arcsec # Rs in arcsec
197 alpha_Rs = rho0 * (4 * Rs ** 2 * (1 + np.log(1. / 2.)))
File ~/.local/lib/python3.10/site-packages/lenstronomy/Cosmo/lens_cosmo.py:208, in LensCosmo.nfwParam_physical(self, M, c)
200 def nfwParam_physical(self, M, c):
201 """
202 returns the NFW parameters in physical units
203
(...)
206 :return: rho0 [Msun/Mpc^3], Rs [Mpc], r200 [Mpc]
207 """
--> 208 r200 = self.nfw_param.r200_M(M * self.h, self.z_lens) / self.h # physical radius r200
209 rho0 = self.nfw_param.rho0_c(c, self.z_lens) * self.h2 # physical density in M_sun/Mpc3
210 Rs = r200/c
File ~/.local/lib/python3.10/site-packages/lenstronomy/Cosmo/nfw_param.py:64, in NFWParam.r200_M(self, M, z)
54 def r200_M(self, M, z):
55 """
56 computes the radius R_200 crit of a halo of mass M in physical mass M/h
57
(...)
62 :return: radius R_200 in physical Mpc/h
63 """
---> 64 return (3M/(4np.pi*self.rhoc_z(z)*200))**(1./3.)
File ~/.local/lib/python3.10/site-packages/lenstronomy/Cosmo/nfw_param.py:33, in NFWParam.rhoc_z(self, z)
27 def rhoc_z(self, z):
28 """
29
30 :param z: redshift
31 :return: critical density of the universe at redshift z in physical units [h^2 M_sun Mpc^-3]
32 """
---> 33 return self.rhoc * (self.cosmo.efunc(z)) ** 2
File ~/.local/lib/python3.10/site-packages/astropy/cosmology/flrw/lambdacdm.py:734, in FlatLambdaCDM.efunc(self, z)
727 # We override this because it takes a particularly simple
728 # form for a cosmological constant
729 Or = self._Ogamma0 + (
730 self._Onu0
731 if not self._massivenu
732 else self._Ogamma0 * self.nu_relative_density(z)
733 )
--> 734 zp1 = aszarr(z) + 1.0 # (converts z [unit] -> z [dimensionless])
736 return np.sqrt(zp1**3 * (Or * zp1 + self._Om0) + self._Ode0)
File ~/.local/lib/python3.10/site-packages/astropy/cosmology/utils.py:149, in aszarr(z)
147 return z
148 # not one of the preferred types: Number / array ducktype
--> 149 return Quantity(z, cu.redshift).value
File ~/.local/lib/python3.10/site-packages/astropy/units/quantity.py:552, in Quantity.new(cls, value, unit, dtype, copy, order, subok, ndmin)
548 # check that array contains numbers or long int objects
549 if value.dtype.kind in "OSU" and not (
550 value.dtype.kind == "O" and isinstance(value.item(0), numbers.Number)
551 ):
--> 552 raise TypeError("The value must be a valid Python or Numpy numeric type.")
554 # by default, cast any integer, boolean, etc., to float
555 if float_default and value.dtype.kind in "iuO":
TypeError: The value must be a valid Python or Numpy numeric type.
`
Thanks in advance for your help!
The text was updated successfully, but these errors were encountered: