# Path: pyradex/utils.py
# def united(qty, unit):
#     if isinstance(qty,u.Quantity):
#         return qty.to(unit)
#     else:
#         return qty*u.Unit(unit)
# 
# def uvalue(qty, unit):
#     return united(qty, unit).value
# 
# def get_datafile(species, savedir='./'):
#     """
#     Load a molecular data file and save it into the specified directory
#     """
#     from astroquery.lamda import Lamda
# 
#     datapath = os.path.join(savedir,species)
# 
#     species,suffix = os.path.splitext(species)
#     if suffix == "":
#         datapath += ".dat"
#     elif suffix != ".dat":
#         raise ValueError("Molecular data file must either be a species name or species.dat")
# 
#     if not os.path.isdir(savedir):
#         mkdir_p(savedir)
# 
#     if not os.path.isfile(datapath):
#         data = Lamda.query(species, return_datafile=True)
#         with open(datapath,'w') as out:
#             out.writelines([d+"\n" for d in data])
# 
#     return os.path.split(datapath)


import pyradex
import pylab as pl
import numpy as np
import os
from astropy import units as u
from pyradex.utils import united,uvalue,get_datafile

def test_co():
    mydir = os.path.dirname(os.path.realpath(__file__))

    print mydir
    datapath,speciesdat = get_datafile('co', savedir=os.path.join(mydir,'data/'))
    print datapath,speciesdat

    R = pyradex.Radex(species='co', abundance=1e-4, column=None,
                      temperature=10,
                      collider_densities={'ph2':990,'oh2':10}, deltav=2.0,
                      datapath=datapath, escapeProbGeom='lvg')
    D = pyradex.despotic_interface.Despotic(hcolumn=2e21, species='co',
                                            temperature=10,
                                            abundance=1e-4,
                                            collider_densities={'ph2':990,'oh2':10},
                                            deltav=2.0,
                                            datapath=datapath,
                                            escapeProbGeom='lvg')

    # make sure we're dealing with identical qtys

# Path: pyradex/utils.py
# def united(qty, unit):
#     if isinstance(qty,u.Quantity):
#         return qty.to(unit)
#     else:
#         return qty*u.Unit(unit)
# 
# def uvalue(qty, unit):
#     return united(qty, unit).value
# 
# def get_datafile(species, savedir='./'):
#     """
#     Load a molecular data file and save it into the specified directory
#     """
#     from astroquery.lamda import Lamda
# 
#     datapath = os.path.join(savedir,species)
# 
#     species,suffix = os.path.splitext(species)
#     if suffix == "":
#         datapath += ".dat"
#     elif suffix != ".dat":
#         raise ValueError("Molecular data file must either be a species name or species.dat")
# 
#     if not os.path.isdir(savedir):
#         mkdir_p(savedir)
# 
#     if not os.path.isfile(datapath):
#         data = Lamda.query(species, return_datafile=True)
#         with open(datapath,'w') as out:
#             out.writelines([d+"\n" for d in data])
# 
#     return os.path.split(datapath)


# Path: examples/compare_co_radex_despotic.py
import pyradex
import pylab as pl
import numpy as np
import os
from astropy import units as u
from pyradex.utils import united,uvalue,get_datafile


def test_co():
    mydir = os.path.dirname(os.path.realpath(__file__))

    print mydir
    datapath,speciesdat = get_datafile('co', savedir=os.path.join(mydir,'data/'))
    print datapath,speciesdat

    R = pyradex.Radex(species='co', abundance=1e-4, column=None,
                      temperature=10,
                      collider_densities={'ph2':990,'oh2':10}, deltav=2.0,
                      datapath=datapath, escapeProbGeom='lvg')
    D = pyradex.despotic_interface.Despotic(hcolumn=2e21, species='co',
                                            temperature=10,
                                            abundance=1e-4,
                                            collider_densities={'ph2':990,'oh2':10},
                                            deltav=2.0,
                                            datapath=datapath,
                                            escapeProbGeom='lvg')

    # make sure we're dealing with identical qtys

    assert uvalue(D.temperature,u.K) == uvalue(R.temperature,u.K)