eblur / newdust

Holding place for major rewrite of eblur/dust code
BSD 2-Clause "Simplified" License
5 stars 5 forks source link

Differential scattering cross-section array sizes bug #28

Closed eblur closed 2 years ago

eblur commented 2 years ago

When I attempted to calculate the differential scattering cross-section from the Mie scattering model:

titan_scattering = nd.scatmodels.Mie()
titan_scattering.calculate(wl_keV.value, particle_sizes.to('micron').value, cm_titan, unit='kev', theta=theta_arcsec)

I got the following error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-9-ef875d9b3aec> in <module>
      1 titan_scattering = nd.scatmodels.Mie()
----> 2 titan_scattering.calculate(wl_keV.value, particle_sizes.to('micron').value, cm_titan, unit='kev', theta=theta_arcsec)
      3 titan_ext = np.pi * particle_sizes**2 * titan_scattering.qext
      4 titan_sca = np.pi * particle_sizes**2 * titan_scattering.qsca
      5 titan_abs = np.pi * particle_sizes**2 * titan_scattering.qabs

/usr/local/anaconda/envs/newdust-dev/lib/python3.8/site-packages/newdust/scatmodels/miescat.py in calculate(self, lam, a, cm, unit, theta, memlim)
     71         x      = 2.0 * np.pi * a_cm / lam_cm
     72 
---> 73         qsca, qext, qback, gsca, Cdiff = _mie_helper(x, refrel, theta=th_1d, memlim=memlim)
     74 
     75         # Assumes spherical grains (implicit in Mie)

/usr/local/anaconda/envs/newdust-dev/lib/python3.8/site-packages/newdust/scatmodels/miescat.py in _mie_helper(x, refrel, theta, memlim)
    309     Cdiff = 0.0
    310     bad_theta = np.where(np.abs(theta_rad) > np.pi)  # Set to 0 values where theta > !pi
--> 311     s1[...,bad_theta] = 0
    312     s2[...,bad_theta] = 0
    313     Cdiff = 0.5 * (np.power(np.abs(s1), 2) + np.power(np.abs(s2), 2)) / (np.pi * np.power(x_3d,2))

IndexError: index 10 is out of bounds for axis 2 with size 10
eblur commented 2 years ago

Fixed with PR #29