Returns a conversion factor between this unit and a new unit.
        Compound units are supported, but must have the same powers in each
        unit type.

        Args:
            new_unit: The new unit.
558411
def get_conversion_factor(self, new_unit):
        
        uo_base, ofactor = self.as_base_units
        un_base, nfactor = Unit(new_unit).as_base_units
        units_new = sorted(un_base.items(),
                           key=lambda d: _UNAME2UTYPE[d[0]])
        units_old = sorted(uo_base.items(),
                           key=lambda d: _UNAME2UTYPE[d[0]])
        factor = ofactor / nfactor
        for uo, un in zip(units_old, units_new):
            if uo[1] != un[1]:
                raise UnitError("Units %s and %s are not compatible!" % (uo, un))
            c = ALL_UNITS[_UNAME2UTYPE[uo[0]]]
            factor *= (c[uo[0]] / c[un[0]]) ** uo[1]
        return factor
724560
def new_param(name, type, value, start = None, scale = None, unit = None, dataunit = None, comment = None):
	
	elem = Param()
	elem.Name = name
	elem.Type = type
	elem.pcdata = value
	# FIXME:  I have no idea how most of the attributes should be
	# encoded, I don't even know what they're supposed to be.
	if dataunit is not None:
		elem.DataUnit = dataunit
	if scale is not None:
		elem.Scale = scale
	if start is not None:
		elem.Start = start
	if unit is not None:
		elem.Unit = unit
	if comment is not None:
		elem.appendChild(ligolw.Comment())
		elem.childNodes[-1].pcdata = comment
	return elem
944301
def get_units(**kwargs):
    
    units_list = db.DBSession.query(Unit).all()
    units = []
    for unit in units_list:
        new_unit = JSONObject(unit)
        units.append(new_unit)

    return units
719102
def count_base_units(units):
    
    ret = {}
    for unit in units:
        factor, base_unit = get_conversion_factor(unit)

        ret.setdefault(base_unit, 0)
        ret[base_unit] += 1

    return ret
1013205
protected UnitFactor resolve(Unit from, Unit to) {
    if (from == to) {
      return new UnitFactor(Rational.ONE, to);
    }

    List<UnitFactor> path = getPath(from, to);
    if (path.isEmpty()) {
      throw new IllegalStateException("Can't find a path to convert " + from + " units into " + to);
    }
    UnitFactor factor = path.get(0);
    int size = path.size();
    for (int i = 1; i < size; i++) {
      factor = factor.multiply(path.get(i));
    }
    return factor;
  }
921757
def coerce(other)
      return [other.to_unit, self] if other.respond_to? :to_unit
      case other
      when Unit
        [other, self]
      else
        [RubyUnits::Unit.new(other), self]
      end
    end
719633
def set_unit(self, unit):
        
        # accept all core time units
        if unit is None or (isinstance(unit, units.NamedUnit) and
                            unit.physical_type == 'time'):
            self._unit = unit
            return
        # convert float to custom unit in seconds
        if isinstance(unit, Number):
            unit = units.Unit(unit * units.second)
        # otherwise, should be able to convert to a time unit
        try:
            unit = units.Unit(unit)
        except ValueError as exc:
            # catch annoying plurals
            try:
                unit = units.Unit(str(unit).rstrip('s'))
            except ValueError:
                raise exc
        # decompose and check that it's actually a time unit
        dec = unit.decompose()
        if dec.bases != [units.second]:
            raise ValueError("Cannot set GPS unit to %s" % unit)
        # check equivalent units
        for other in TIME_UNITS:
            if other.decompose().scale == dec.scale:
                self._unit = other
                return
        raise ValueError("Unrecognised unit: %s" % unit)
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]
1188924
def reduce_to_unit(divider):
    
    for unit_size in range(1, len(divider) // 2 + 1):
        length = len(divider)
        unit = divider[:unit_size]

        # Ignores mismatches in final characters:
        divider_item = divider[:unit_size * (length // unit_size)]
        if unit * (length // unit_size) == divider_item:
            return unit
    return divider
967263
def conversions(self):
        
        return "\n".join(str(self.to(unit)) for unit in self.supported_units)
1264008
def bulk_add_units(unit_list, **kwargs):
    
    # for unit in unit_list:
    #     add_unit(unit, **kwargs)

    added_units = []
    for unit in unit_list:
        added_units.append(add_unit(unit, **kwargs))

    return JSONObject({"units": added_units})
533742
def getValue(self, unit=None):
        

        if unit or self.unit:
            r = float(self.value * UnitToValue(self.unit)) / UnitToValue(unit)
            return int(round(r)) if isinstance(self.value, int) else r
        return self.value
361988
def multi_new(rhs)
      if(rhs.kind_of?(Vector3))
        ans = self.multi_inner(rhs.to_column_vector)
      return Vector3.new(ans[0,0], ans[1,0], ans[2,0])
      end
      multi_inner(rhs)
    end
437205
def relation_for_unit(unit=None, rid=None):
    """"""
    unit = unit or remote_unit()
    relation = relation_get(unit=unit, rid=rid)
    for key in relation:
        if key.endswith('-list'):
            relation[key] = relation[key].split()
    relation['__unit__'] = unit
    return relation
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
196524
public double factorOf(TimeUnit unit) {
        if (unit == TimeUnit.NanoSeconds) {
            return 1.0;
        } else if (unit == TimeUnit.MicroSeconds) {
            return 1.0e-3;
        } else if (unit == TimeUnit.MilliSeconds) {
            return 1.0e-6;
        } else if (unit == TimeUnit.Seconds) {
            return 1.0e-9;
        } else if (unit == TimeUnit.Minutes) {
            return 1.0e-9 / 60;
        } else if (unit == TimeUnit.Hours) {
            return 1.0e-9 / 3600;
        }
        return Double.NaN;
    }
600003
def convert(cls, value, from_unit, to_unit):
        
        value_ms = value * cls.UNITS_IN_MILLISECONDS[from_unit]
        return value_ms / cls.UNITS_IN_MILLISECONDS[to_unit]