Exemplo n.º 1
0
    def __init__(self):

        if 'CLOUDY_EXE' in os.environ:
            self.cloudy_exe = os.environ['CLOUDY_EXE']
        else:
            self.cloudy_exe = 'cloudy.exe'

        self.cloudy_dict = {
            '10.00': '/usr/local/Cloudy/c10.00/cloudy.exe',
            '13.03': '/usr/local/Cloudy/c13.03/source/cloudy.exe',
            '17.00': '/usr/local/Cloudy/c17.00/source/cloudy.exe',
            '17.01': '/usr/local/Cloudy/c17.01/source/cloudy.exe',
            '17.02': '/usr/local/Cloudy/c17.02/source/cloudy.exe'
        }

        self.INSTALLED = {}
        try:
            try:
                from matplotlib.tri.triangulation import Triangulation
            except:
                from matplotlib.delaunay import Triangulation
            self.INSTALLED['Triangulation'] = True
        except:
            self.INSTALLED['Triangulation'] = False
            _Config.log_.warn(
                'pyCloudy works better with matplotlib Triangulation',
                calling='pyCloudy config')
        try:
            import matplotlib.pyplot as plt
            self.INSTALLED['plt'] = True
        except:
            self.INSTALLED['plt'] = False
        try:
            import pyneb as pn
            self.INSTALLED['PyNeb'] = True
        except:
            self.INSTALLED['PyNeb'] = False
            _Config.log_.warn('pyCloudy works better with PyNeb',
                              calling='pyCloudy config')
        try:
            from scipy.integrate import cumtrapz
            from scipy.interpolate import interp1d
            self.INSTALLED['scipy'] = True
        except:
            self.INSTALLED['scipy'] = False
            _Config.log_.warn('pyCloudy works better with scipy',
                              calling='pyCloudy config')
        try:
            from PIL import Image
            self.INSTALLED['Image'] = True
        except:
            self.INSTALLED['Image'] = False
            _Config.log_.warn(
                'pyCloudy needs PIL or Pillow for 3 colors images',
                calling='pyCloudy config')
        try:
            import MySQLdb
            self.INSTALLED['MySQL'] = True
        except:
            self.INSTALLED['MySQL'] = False
        try:
            import pymysql
            self.INSTALLED['PyMySQL'] = True
        except:
            self.INSTALLED['PyMySQL'] = False
        try:
            import pandas
            self.INSTALLED['pandas'] = True
        except:
            self.INSTALLED['pandas'] = False
        try:
            import pyfits
            self.INSTALLED['pyfits'] = True
            self.INSTALLED['pyfits from astropy'] = False
        except:
            self.INSTALLED['pyfits'] = False
            try:
                import astropy.io.fits as pyfits
                self.INSTALLED['pyfits from astropy'] = True
            except:
                self.INSTALLED['pyfits from astropy'] = False
        try:
            from numpy.version import version as numpy_version
            if [int(n) for n in (numpy_version.split('.')[:3])] > [1, 5, 1]:
                self.INSTALLED['np.genfromtxt new'] = True
        except:
            try:
                test_str = ['#one\t two\t three', '1\t 2\t 3']
                test_res = np.genfromtxt(test_str,
                                         names=True,
                                         comments=';',
                                         delimiter='\t')
                if test_res.dtype.fields is None:
                    self.INSTALLED['np.genfromtxt new'] = False
                else:
                    self.INSTALLED['np.genfromtxt new'] = True
            except:
                self.INSTALLED['np.genfromtxt new'] = False
        if not self.INSTALLED['np.genfromtxt new']:
            _Config.log_.warn('pyCloudy works better with numpy >= 1.6.0',
                              calling='pyCloudy config')

        try:
            import multiprocessing as mp
            self.INSTALLED['mp'] = True
            self.Nprocs = mp.cpu_count()
        except:
            self.INSTALLED['mp'] = False
            self.log_.message('multiprocessing not available',
                              calling=self.calling)
            self.Nprocs = 1

        try:
            import numexpr as ne
            self.INSTALLED['numexpr'] = True
        except:
            self.INSTALLED['numexpr'] = False

        self.SAVE_LIST = [['radius', '.rad'], ['continuum', '.cont'],
                          ['physical conditions', '.phy'],
                          ['overview', '.ovr'], ['heating', '.heat'],
                          ['cooling', '.cool'], ['optical depth', '.opd']]

        self.SAVE_LIST_GRAINS = [['grain temperature', '.gtemp'],
                                 ['grain abundances', '.gabund'],
                                 ['grain D/G ratio', '.gdgrat']]

        self.SAVE_LIST_ELEMS = [['hydrogen', '.ele_H'], ['helium', '.ele_He'],
                                ['carbon', '.ele_C'], ['nitrogen', '.ele_N'],
                                ['oxygen', '.ele_O'], ['argon', '.ele_Ar'],
                                ['neon', '.ele_Ne'], ['sulphur', '.ele_S'],
                                ['chlorin', '.ele_Cl'], ['iron', '.ele_Fe'],
                                ['silicon', '.ele_Si']]

        self.def_c13c17()
Exemplo n.º 2
0
             calc_emiss_o_ii_rl, calc_emiss_ne_ii_rl, \
             calc_abund_he_i_rl, calc_abund_he_ii_rl, \
             calc_abund_c_ii_rl, calc_abund_c_iii_rl, \
             calc_abund_n_ii_rl, calc_abund_n_iii_rl, \
             calc_abund_o_ii_rl, calc_abund_ne_ii_rl, \
             redlaw, redlaw_gal, redlaw_gal2, \
             redlaw_ccm, redlaw_jbk, redlaw_fm, \
             redlaw_smc, redlaw_lmc, \
             deredden_flux, deredden_relflux

from .version import __version__

import sys
from numpy.version import version as numpy_version

if sys.version_info[0:2] < (2, 6):
    log_.warn(
        'pyequib requires Python version >= 2.6, but it is version {0}'.format(
            sys.version_info),
        calling='pyequib')
try:
    if [int(n) for n in (numpy_version.split('.')[:3])] < [1, 5, 1]:
        log_.warn(
            'pyequib Numpy version >= 1.5.1, but it is version {0}'.format(
                numpy_version),
            calling='pyequib')
except:
    log_.warn(
        'Cannot find Numpy version {0}, report the bug'.format(numpy_version),
        calling='pyemcee')
Exemplo n.º 3
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from collections import namedtuple
from enum import Enum
from abc import ABCMeta, abstractmethod
import warnings

import numpy as np
from numpy.version import version as npver


npv = tuple(int(x) for x in npver.split('.'))

class namedarray:
    """Class representing a set of field names such that any list or array of numbers can be casted into a :class:`numpy.recarray`"""

    def __init__(self, field_names):
        """:param field_names: List of field names
        :type field_names: list"""
        if isinstance(field_names, str):
            self._fields = [field_name.strip() for field_name in field_names.split(',')]
        else:
            self._fields = field_names[:]
        self._nfields = len(self._fields)
        self.dtype = np.dtype([(field_name, float) for field_name in self._fields])

    def __repr__(self):