hyperion-rt / hyperion

Hyperion Radiative Transfer Code
http://www.hyperion-rt.org
BSD 2-Clause "Simplified" License
52 stars 26 forks source link

distances in Model get_sed attribute #95

Open dnarayanan opened 10 years ago

dnarayanan commented 10 years ago

The distances don't allow for using quantities with astropy units. For example, the following works:

>wav,flux = m.get_sed(inclination='all',distance=2.e9*pc,units='Jy')

but the following does not

>from astropy import cosmology
>from astropy import units as u
>z = 2 #set redshift
>cosmology.set_current(cosmology.WMAP9)
>dl = cosmology.luminosity_distance(z)
>dl.to(u.cm)
>wav,flux = m.get_sed(inclination='all',distance=dl,units='Jy')

and gives the following traceback:

In [15]: run model_sed_plot.py
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/desika/yt-x86_64/lib/python2.7/site-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    202             else:
    203                 filename = fname
--> 204             __builtin__.execfile(filename, *where)

/Users/desika/Dropbox/FIRE/DSFGs/model_sed_plot.py in <module>()
     21 
     22 m = ModelOutput(model)
---> 23 wav,flux = m.get_sed(inclination='all',distance=dl,units='Jy')
     24 
     25 

/Users/desika/yt-x86_64/lib/python2.7/site-packages/hyperion/model/model_output.pyc in get_sed(self, stokes, group, technique, distance, component, inclination, aperture, uncertainties, units, source_id, dust_id)

/Users/desika/yt-x86_64/lib/python2.7/site-packages/hyperion/model/model_output.pyc in _on_the_fly_hdf5(f, *args, **kwargs)
     87     if not preset:
     88         args[0].file = h5py.File(args[0].filename, 'r')
---> 89     results = f(*args, **kwargs)
     90     if not preset:
     91         args[0].file.close()

/Users/desika/yt-x86_64/lib/python2.7/site-packages/hyperion/model/model_output.pyc in get_sed(self, stokes, group, technique, distance, component, inclination, aperture, uncertainties, units, source_id, dust_id)
    455 
    456         # Add distance
--> 457         sed.distance = distance
    458 
    459         # Save whether the SED was from an inside observer

/Users/desika/yt-x86_64/lib/python2.7/site-packages/hyperion/util/functions.pyc in __setattr__(self, key, value)
     97             raise AttributeError("Attribute %s does not exist" % key)
     98         self._attributes.append(key)
---> 99         object.__setattr__(self, key, value)
    100 
    101 

/Users/desika/yt-x86_64/lib/python2.7/site-packages/hyperion/model/sed.pyc in distance(self, value)
    172             self._distance = value
    173         else:
--> 174             raise ValueError("distance should be a real scalar value")
    175 
    176     @property

ValueError: distance should be a real scalar value
dnarayanan commented 10 years ago

(for posterity:


>cosmology.set_current(cosmology.WMAP9)
>da =  cosmology.angular_diameter_distance(z)
>da.to(u.cm)
>wav,flux = m.get_sed(inclination='all',distance=da,units='Jy')
astrofrog commented 10 years ago

@dnarayanan - yes, we still need to get astropy quantities working in Hyperion, but it's definitely a top priority!