# 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


import numpy as np
import warnings
import os
        import despotic
from collections import defaultdict
from .utils import united,uvalue
from astropy import units as u
from astropy import constants
from astropy.table import Table,Column
        if datapath is None:
            emitterFile = species+'.dat'
        else:
            emitterFile = os.path.expanduser(os.path.join(datapath, species+'.dat'))
        self.cloud.addEmitter(species, abundance, emitterFile=emitterFile)

        self.cloud.comp.computeDerived(self.cloud.nH)

        self.escapeProbGeom = escapeProbGeom

        self.deltav = deltav


    def recompute(self):
        self.cloud.comp.computeDerived(self.cloud.nH)
        self.lineLum()

    @property
    def deltav(self):
        if self.cloud.sigmaNT > 0:
            return (self.cloud.sigmaNT*u.cm/u.s).to(u.km/u.s)
        elif self.cloud.dVdr > 0:
            return (self.cloud.dVdr*u.s**-1).to(u.km/u.s/u.pc)
        else:
            raise ValueError("The velocity gradient is zero")

    @deltav.setter
    def deltav(self, deltav):

        if self.escapeProbGeom == 'LVG':

# 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


# Path: pyradex/despotic_interface.py
import numpy as np
import warnings
import os
        import despotic
from collections import defaultdict
from .utils import united,uvalue
from astropy import units as u
from astropy import constants
from astropy.table import Table,Column

        if datapath is None:
            emitterFile = species+'.dat'
        else:
            emitterFile = os.path.expanduser(os.path.join(datapath, species+'.dat'))
        self.cloud.addEmitter(species, abundance, emitterFile=emitterFile)

        self.cloud.comp.computeDerived(self.cloud.nH)

        self.escapeProbGeom = escapeProbGeom

        self.deltav = deltav


    def recompute(self):
        self.cloud.comp.computeDerived(self.cloud.nH)
        self.lineLum()

    @property
    def deltav(self):
        if self.cloud.sigmaNT > 0:
            return (self.cloud.sigmaNT*u.cm/u.s).to(u.km/u.s)
        elif self.cloud.dVdr > 0:
            return (self.cloud.dVdr*u.s**-1).to(u.km/u.s/u.pc)
        else:
            raise ValueError("The velocity gradient is zero")

    @deltav.setter
    def deltav(self, deltav):

        if self.escapeProbGeom == 'LVG':

            self._dv = united(self.cloud.dVdr,u.s**-1)