Convert the Data Collection to SI units.
172632
def convert_to_si(self):
        """"""
        self._values, self._header._unit = self._header.data_type.to_si(
                self._values, self._header.unit)
205660
def convert(self):
        """"""

        from pyspectral.utils import (convert2wavenumber, get_central_wave)
        if self._wavespace == WAVE_LENGTH:
            rsr, info = convert2wavenumber(self.rsr)
            for band in rsr.keys():
                for det in rsr[band].keys():
                    self.rsr[band][det][WAVE_NUMBER] = rsr[
                        band][det][WAVE_NUMBER]
                    self.rsr[band][det]['response'] = rsr[
                        band][det]['response']
                    self.unit = info['unit']
                    self.si_scale = info['si_scale']
            self._wavespace = WAVE_NUMBER
            for band in rsr.keys():
                for det in rsr[band].keys():
                    self.rsr[band][det]['central_wavenumber'] = \
                        get_central_wave(self.rsr[band][det][WAVE_NUMBER], self.rsr[band][det]['response'])
                    del self.rsr[band][det][WAVE_LENGTH]
        else:
            errmsg = "Conversion from {wn} to {wl} not supported yet".format(wn=WAVE_NUMBER, wl=WAVE_LENGTH)
            raise NotImplementedError(errmsg)
967263
def conversions(self):
        
        return "\n".join(str(self.to(unit)) for unit in self.supported_units)
652379
def units(self, value):
        
        for m in self.geometry.values():
            m.units = value
1153475
def as(quantity, unit)
      begin
        convert(quantity, unit)
      rescue MeasurementError => e
        raise MeasurementError.new("No conversion path from #{self} to #{unit} - #{e}")
      end
    end
1028208
def _convert_units(self):
        
        self.m1 = self.m1*M_sun*ct.G/ct.c**2
        self.m2 = self.m2*M_sun*ct.G/ct.c**2
        initial_cond_type_conversion = {
            'time': ct.c*ct.Julian_year,
            'frequency': 1./ct.c,
            'separation': ct.parsec,
        }

        self.initial_point = self.initial_point*initial_cond_type_conversion[self.initial_cond_type]

        self.t_obs = self.t_obs*ct.c*ct.Julian_year
        return
966679
def units(self) -> typing.Iterator['BaseUnit']:
        
        for group in self.groups:
            for unit in group.units:

                yield unit
949071
def format_units(v, step=None, system="si", units=None):
    
    if v is None:
        return 0, ''

    for prefix, size in UnitSystems[system]:
        if condition(v, size, step):
            v2 = v / size
            if v2 - math.floor(v2) < 0.00000000001 and v > 1:
                v2 = float(math.floor(v2))
            if units:
                prefix = "%s%s" % (prefix, units)
            return v2, prefix

    if v - math.floor(v) < 0.00000000001 and v > 1:
        v = float(math.floor(v))
    if units:
        prefix = units
    else:
        prefix = ''
    return v, prefix
1303489
def to_float(unit):
    
    def converter(x):
        """Convert the input to a `float` in %s
        """
        return Quantity(x, unit).value

    converter.__doc__ %= str(unit)  # pylint: disable=no-member
    return converter
398796
def get_unit(a):
    """"""
    typestr = a.dtype.str
    i = typestr.find('[')
    if i == -1:
        raise TypeError("Expected a datetime64 array, not %s", a.dtype)
    return typestr[i + 1: -1]
1100381
def physical_conversion(quantity,pop=False):
    """"""
    def wrapper(method):
        @wraps(method)
        def wrapped(*args,**kwargs):
            use_physical= kwargs.get('use_physical',True) and \
                not kwargs.get('log',False)
            # Parse whether ro or vo should be considered to be set, because 
            # the return value will have units anyway
            # (like in Orbit methods that return numbers with units, like ra)
            roSet= '_' in quantity # _ in quantity name means always units
            voSet= '_' in quantity # _ in quantity name means always units
            use_physical= use_physical or '_' in quantity # _ in quantity name means always units
            ro= kwargs.get('ro',None)
            if ro is None and \
                    (roSet or (hasattr(args[0],'_roSet') and args[0]._roSet)):
                ro= args[0]._ro
            if ro is None and isinstance(args[0],list) \
                    and hasattr(args[0][0],'_roSet') and args[0][0]._roSet:
                # For lists of Potentials
                ro= args[0][0]._ro
            if _APY_LOADED and isinstance(ro,units.Quantity):
                ro= ro.to(units.kpc).value
            vo= kwargs.get('vo',None)
            if vo is None and \
                    (voSet or (hasattr(args[0],'_voSet') and args[0]._voSet)):
                vo= args[0]._vo
            if vo is None and isinstance(args[0],list) \
                    and hasattr(args[0][0],'_voSet') and args[0][0]._voSet:
                # For lists of Potentials
                vo= args[0][0]._vo
            if _APY_LOADED and isinstance(vo,units.Quantity):
                vo= vo.to(units.km/units.s).value
            # Override Quantity output?
            _apy_units= kwargs.get('quantity',_APY_UNITS)
            #Remove ro and vo kwargs if necessary
            if pop and 'use_physical' in kwargs: kwargs.pop('use_physical')
            if pop and 'ro' in kwargs: kwargs.pop('ro')
            if pop and 'vo' in kwargs: kwargs.pop('vo')
            if use_physical and \
                    not (_voNecessary[quantity.lower()] and vo is None) and \
                    not (_roNecessary[quantity.lower()] and ro is None):
                from galpy.orbit import Orbit
                if isinstance(args[0],Orbit): print_physical_warning()
                if quantity.lower() == 'time':
                    fac= time_in_Gyr(vo,ro)
                    if _apy_units:
                        u= units.Gyr
                elif quantity.lower() == 'position':
                    fac= ro
                    if _apy_units:
                        u= units.kpc
                elif quantity.lower() == 'position_kpc': # already in kpc
                    fac= 1.
                    if _apy_units:
                        u= units.kpc
                elif quantity.lower() == 'velocity':
                    fac= vo
                    if _apy_units:
                        u= units.km/units.s
                elif quantity.lower() == 'velocity2':
                    fac= vo**2.
                    if _apy_units:
                        u= (units.km/units.s)**2
                elif quantity.lower() == 'velocity_kms': # already in km/s
                    fac= 1.
                    if _apy_units:
                        u= units.km/units.s
                elif quantity.lower() == 'frequency':
                    if kwargs.get('kmskpc',False) and not _apy_units:
                        fac= freq_in_kmskpc(vo,ro)
                    else:
                        fac= freq_in_Gyr(vo,ro)
                        if _apy_units:
                            u= units.Gyr**-1.
                elif quantity.lower() == 'frequency-kmskpc':
                    fac= freq_in_kmskpc(vo,ro)
                    if _apy_units:
                        u= units.km/units.s/units.kpc
                elif quantity.lower() == 'action':
                    fac= ro*vo
                    if _apy_units:
                        u= units.kpc*units.km/units.s
                elif quantity.lower() == 'energy':
                    fac= vo**2.
                    if _apy_units:
                        u= units.km**2./units.s**2.
                elif quantity.lower() == 'angle': # in rad
                    fac= 1.
                    if _apy_units:
                        u= units.rad
                elif quantity.lower() == 'angle_deg': # already in deg
                    fac= 1.
                    if _apy_units:
                        u= units.deg
                elif quantity.lower() == 'proper-motion_masyr': # already in mas/yr
                    fac= 1.
                    if _apy_units:
                        u= units.mas/units.yr
                elif quantity.lower() == 'force':
                    fac= force_in_kmsMyr(vo,ro)
                    if _apy_units:
                        u= units.km/units.s/units.Myr
                elif quantity.lower() == 'density':
                    fac= dens_in_msolpc3(vo,ro)
                    if _apy_units:
                        u= units.Msun/units.pc**3
                elif quantity.lower() == 'numberdensity':
                    fac= 1/ro**3.
                    if _apy_units:
                        u= 1/units.kpc**3
                elif quantity.lower() == 'velocity2surfacedensity':
                    fac= surfdens_in_msolpc2(vo,ro)*vo**2
                    if _apy_units:
                        u= units.Msun/units.pc**2*(units.km/units.s)**2
                elif quantity.lower() == 'surfacedensity':
                    fac= surfdens_in_msolpc2(vo,ro)
                    if _apy_units:
                        u= units.Msun/units.pc**2
                elif quantity.lower() == 'numbersurfacedensity':
                    fac= 1./ro**2.
                    if _apy_units:
                        u= 1/units.kpc**2
                elif quantity.lower() == 'surfacedensitydistance':
                    fac= surfdens_in_msolpc2(vo,ro)*ro*1000.
                    if _apy_units:
                        u= units.Msun/units.pc
                elif quantity.lower() == 'mass':
                    fac= mass_in_msol(vo,ro)
                    if _apy_units:
                        u= units.Msun
                elif quantity.lower() == 'forcederivative':
                    fac= freq_in_Gyr(vo,ro)**2.
                    if _apy_units:
                        u= units.Gyr**-2.
                elif quantity.lower() == 'phasespacedensity':
                    fac= 1./vo**3./ro**3.
                    if _apy_units:
                        u= 1/(units.km/units.s)**3/units.kpc**3
                elif quantity.lower() == 'phasespacedensity2d':
                    fac= 1./vo**2./ro**2.
                    if _apy_units:
                        u= 1/(units.km/units.s)**2/units.kpc**2
                elif quantity.lower() == 'phasespacedensityvelocity':
                    fac= 1./vo**2./ro**3.
                    if _apy_units:
                        u= 1/(units.km/units.s)**2/units.kpc**3
                elif quantity.lower() == 'phasespacedensityvelocity2':
                    fac= 1./vo/ro**3.
                    if _apy_units:
                        u= 1/(units.km/units.s)/units.kpc**3
                elif quantity.lower() == 'dimensionless':
                    fac= 1.
                    if _apy_units:
                        u= units.dimensionless_unscaled
                out= method(*args,**kwargs)
                if out is None:
                    return out
                if _apy_units:
                    return units.Quantity(out*fac,unit=u)
                else:
                    return out*fac
            else:
                return method(*args,**kwargs)
        return wrapped
    return wrapper
460895
def unit_conversion(thing, units, length=False):
    """"""
    if 'n/a' == thing:
        return 'n/a'
    try:
        thing = round(thing * CONVERSION[units][0 + length], 2)
    except TypeError:
        thing = 'fubar'
    return thing, CONVERSION[units][2 + length]
270946
def serialize(data, measurement=None, tag_columns=None, **extra_tags):
    """"""
    if isinstance(data, bytes):
        return data
    elif isinstance(data, str):
        return data.encode('utf-8')
    elif hasattr(data, 'to_lineprotocol'):
        return data.to_lineprotocol()
    elif pd is not None and isinstance(data, pd.DataFrame):
        return dataframe.serialize(data, measurement, tag_columns, **extra_tags)
    elif isinstance(data, dict):
        return mapping.serialize(data, measurement, **extra_tags)
    elif hasattr(data, '__iter__'):
        return b'\n'.join([serialize(i, measurement, tag_columns, **extra_tags) for i in data])
    else:
        raise ValueError('Invalid input', data)
492467
def to(self, unit):
        """"""
        from astropy.units import au, d
        return (self.au_per_d * au / d).to(unit)
1046295
def apply_units_to_cache(self, data):
        
        for k, val in self.parameters.iteritems():
            if 'units' in val:
                data[k] = Q_(data[k], val.get('units'))
        return data
1111140
def unit(self):
        """"""
        return Vector(
            (self.x / self.magnitude()),
            (self.y / self.magnitude()),
            (self.z / self.magnitude())
        )
442853
def from_inches(value, units):
    
    lookup = {'in': lambda x: x,
              'cm': lambda x: x*2.54,
              'mm': lambda x: x*2.54*10}
    try:
        return lookup[units](value)
    except KeyError:
        raise PlotnineError("Unknown units '{}'".format(units))