# 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


    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)
            # See notes.rst: DESPOTIC must have a different dVdR to get the
            # same results as RADEX
            # 1.0645 / sqrt(8*log(2)) = sqrt(2 * pi) / (8*log(2))
            self.cloud.dVdr = (uvalue(united(deltav,u.km/u.s/u.pc),u.s**-1) *
                               np.sqrt(8*np.log(2))*2)
            # (2*np.pi)**0.5/(8*np.log(2))

        else:
            self._dv = united(self.cloud.sigmaNT,u.km/u.s)


# 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



    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)
            # See notes.rst: DESPOTIC must have a different dVdR to get the
            # same results as RADEX
            # 1.0645 / sqrt(8*log(2)) = sqrt(2 * pi) / (8*log(2))
            self.cloud.dVdr = (uvalue(united(deltav,u.km/u.s/u.pc),u.s**-1) *
                               np.sqrt(8*np.log(2))*2)
            # (2*np.pi)**0.5/(8*np.log(2))

        else:
            self._dv = united(self.cloud.sigmaNT,u.km/u.s)


            FWHM = united(deltav,u.km/u.s)