cristobal-sifon / profiley

Profile calculations for galaxies and clusters
MIT License
5 stars 2 forks source link

shape issue in cumulative #44

Closed cristobal-sifon closed 10 months ago

cristobal-sifon commented 10 months ago
nfw.cumulative(R)

produces:

File ~/anaconda3/envs/kidsggl/lib/python3.11/site-packages/profiley/core.py:298, in Profile.cumulative(self, r, log_rmin, integral_samples)
    288 @inMpc
    289 def cumulative(
    290     self, r: np.ndarray, *, log_rmin: float = -10, integral_samples: int = 1000
    291 ) -> np.ndarray:
    292     """Mean value of the profile within a radius r,
    293 
    294     .. math::
    295 
    296         \\bar\\rho(R) = \\frac3{R^3} \\int_0^R r^2 \\rho(r)\\,dr
    297     """
--> 298     return self.mass_cumulative(
    299         r, log_rmin=log_rmin, integral_samples=integral_samples
    300     ) / (4 / 3 * np.pi * r**3)

File ~/anaconda3/envs/kidsggl/lib/python3.11/site-packages/profiley/helpers/decorators/base.py:90, in inMpc.<locals>.decorated(*args, **kwargs)
     88     args = list(args)
     89     args[1] = args[1].to(u.Mpc).value
---> 90 return f(*args, **kwargs)

File ~/anaconda3/envs/kidsggl/lib/python3.11/site-packages/profiley/core.py:325, in Profile.mass_cumulative(self, r, log_rmin, integral_samples)
    306 """Spherical integral within a radius r,
    307 
    308 .. math::
   (...)
    322     number of samples to generate for Simpson-rule integration
    323 """
    324 R_int = np.logspace(log_rmin, np.log10(r), integral_samples)
--> 325 return 4 * np.pi * simps(R_int**2 * self.profile(R_int), R_int, axis=0)

ValueError: operands could not be broadcast together with shapes (1000,79) (1000,79,1) 

This happens no matter the shape of R nor of the profile object. For instance, for a Profile object with shape (5,2,3):

ValueError: operands could not be broadcast together with shapes (1000,79) (1000,79,5,2,3)