Skip to content

Wrong datatype assumed for sqgrids.py - blackbody_lambda function #34

@HojinCho

Description

@HojinCho

Hi, I'm new to this package and trying to replicate the examples. I'm running astropy v5.0.4.

The example I'm following is this: https://github.com/imcgreer/simqso/blob/master/examples/SimpleSpecExample.ipynb
I haven't tried other examples yet. Also, I didn't do the %pylab inline in the beginning as I usually don't use pylab at all, and hence I imported numpy and matplotlib by myself and edited some parts of the example to correctly refer to intended numpy/matplotlib functions, which shouldn't be causing the problem I experienced.

Upon calling the 9th cell in the example;

# ready to generate spectra
_,spectra = buildSpectraBulk(wave,qsos,saveSpectra=True)

I get the error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-8d131b44e14a> in <module>
      1 # ready to generate spectra
----> 2 _,spectra = buildSpectraBulk(wave,qsos,saveSpectra=True)

/opt/miniconda3/lib/python3.8/site-packages/simqso/sqrun.py in buildSpectraBulk(wave, qsoGrid, procMap, maxIter, verbose, saveSpectra)
    431         if verbose > 1:
    432             print('buildSpectra iteration ',iterNum,' out of ',nIter)
--> 433         specOut = list(procMap(build_one_spec,qsoGrid))
    434         specOut = _regroup(specOut)
    435         synMag,synFlux,spectra = specOut

/opt/miniconda3/lib/python3.8/site-packages/simqso/sqrun.py in buildSpecWithPhot(wave, cosmo, specFeatures, photoCache, objData, iterNum, saveSpectra)
    386 def buildSpecWithPhot(wave,cosmo,specFeatures,photoCache,
    387                       objData,iterNum=None,saveSpectra=False):
--> 388     sp = buildQsoSpectrum(wave,cosmo,specFeatures,objData,
    389                           iterNum=iterNum)
    390     if photoCache is None:

/opt/miniconda3/lib/python3.8/site-packages/simqso/sqrun.py in buildQsoSpectrum(wave, cosmo, specFeatures, obj, iterNum, save_components)
    250         if isinstance(feature,grids.ContinuumVar):
    251             assocvals = _getpar(feature.get_associated_var(),obj)
--> 252             spec = feature.add_to_spec(spec,_getpar(feature,obj),
    253                                        assocvals=assocvals,
    254                                        fluxNorm=fluxNorm)

/opt/miniconda3/lib/python3.8/site-packages/simqso/sqgrids.py in add_to_spec(self, spec, par, **kwargs)
    472         par : sampled values of the variable that are passed to render()
    473         '''
--> 474         spec.f_lambda[:] += self.render(spec.wave,spec.z,par,**kwargs)
    475         return spec
    476 

/opt/miniconda3/lib/python3.8/site-packages/simqso/sqgrids.py in render(self, wave, z, par, fluxNorm, assocvals)
    755         fdisk = self.assocVar.total_flux(assocvals,fluxNorm,z)
    756         flux_bb = fracdust * fdisk
--> 757         Blam = self._calc_bb(Tdust,wave,z)
    758         return flux_bb * np.pi * Blam / L_bb
    759 

/opt/miniconda3/lib/python3.8/site-packages/simqso/sqgrids.py in _calc_bb(self, Tdust, wave, z)
    740             rfwave = np.concatenate([ (lampeak-dwv1)[::-1], rfwv2 ])
    741             self.rfwave[Tdust] = rfwave
--> 742             bvals = blackbody_lambda(self.rfwave[Tdust],Tdust).value
    743             self.Blam[Tdust] = interp1d(self.rfwave[Tdust],bvals,
    744                                         kind='cubic')

/opt/miniconda3/lib/python3.8/site-packages/simqso/sqgrids.py in blackbody_lambda(in_x, temperature)
     44             return flux / u.sr  # Add per steradian to output flux unit
     45         bb_nu = blackbody_nu(in_x, temperature) * u.sr  # Remove sr for conversion
---> 46         flux = bb_nu.to(FLAM, u.spectral_density(in_x))
     47         return flux / u.sr  # Add per steradian to output flux unit
     48 

/opt/miniconda3/lib/python3.8/site-packages/astropy/units/quantity.py in to(self, unit, equivalencies, copy)
    846             # Avoid using to_value to ensure that we make a copy. We also
    847             # don't want to slow down this method (esp. the scalar case).
--> 848             value = self._to_value(unit, equivalencies)
    849         else:
    850             # to_value only copies if necessary

/opt/miniconda3/lib/python3.8/site-packages/astropy/units/quantity.py in _to_value(self, unit, equivalencies)
    800         if not self.dtype.names or isinstance(self.unit, StructuredUnit):
    801             # Standard path, let unit to do work.
--> 802             return self.unit.to(unit, self.view(np.ndarray),
    803                                 equivalencies=equivalencies)
    804 

/opt/miniconda3/lib/python3.8/site-packages/astropy/units/core.py in to(self, other, value, equivalencies)
   1133             return UNITY
   1134         else:
-> 1135             return self._get_converter(Unit(other),
   1136                                        equivalencies=equivalencies)(value)
   1137 

/opt/miniconda3/lib/python3.8/site-packages/astropy/units/core.py in convert(v)
    988         def make_converter(scale1, func, scale2):
    989             def convert(v):
--> 990                 return func(_condition_arg(v) / scale1) * scale2
    991             return convert
    992 

/opt/miniconda3/lib/python3.8/site-packages/astropy/units/equivalencies.py in iconverter(x)
    205 
    206     def iconverter(x):
--> 207         return x / (wav.to_value(si.AA, spectral()) ** 2 / c_Aps)
    208 
    209     def converter_f_nu_to_nu_f_nu(x):

AttributeError: 'numpy.ndarray' object has no attribute 'to_value'

I think this concerns one of the functions that is added recently ( #33 ). Could you check this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions