Return the density of water at a given temperature.

    If given units, the function will automatically convert to Kelvin.
    If not given units, the function will assume Kelvin.
426831
def density_water(temp):
    
    ut.check_range([temp, ">0", "Temperature in Kelvin"])
    rhointerpolated = interpolate.CubicSpline(WATER_DENSITY_TABLE[0],
                                                    WATER_DENSITY_TABLE[1])
    return np.asscalar(rhointerpolated(temp))
796406
def valid_daily_mean_temperature(comp, units='K'):
    """

    @wraps(comp)
    def func(tas, *args, **kwds):
        check_valid_temperature(tas, units)
        check_valid(tas, 'cell_methods', 'time: mean within days')
        return comp(tas, *args, **kwds)

    return func
1369823
def to_si(self, values, from_unit):
        """"""
        if from_unit == 'W/m2-K':
            return values, from_unit
        else:
            return self.to_unit(values, 'W/m2-K', from_unit), 'W/m2-K'
637195
def temperature(self):
        
        with io.open(self.sensor_file, 'r') as f:
            return float(f.readline().strip()) / 1000
588263
def density_2d(self, x, y, rho0, Rs, center_x=0, center_y=0):
        
        x_ = x - center_x
        y_ = y - center_y
        r = np.sqrt(x_**2 + y_**2)
        X = r/Rs
        sigma0 = self.rho2sigma(rho0, Rs)
        if isinstance(X, int) or isinstance(X, float):
            if X == 1:
                X = 1.000001
        else:
            X[X == 1] = 1.000001
        sigma = sigma0 / (X**2-1)**2 * (-3 + (2+X**2)*self._F(X))
        return sigma
979638
def pressure(self):
        
        ut = self.get_raw_temp()
        up = self.get_raw_pressure()
        x1 = ((ut - self.cal['AC6']) * self.cal['AC5']) >> 15
        x2 = (self.cal['MC'] << 11) // (x1 + self.cal['MD'])
        b5 = x1 + x2
        b6 = b5 - 4000
        x1 = (self.cal['B2'] * (b6 * b6) >> 12) >> 11
        x2 = (self.cal['AC2'] * b6) >> 11
        x3 = x1 + x2
        b3 = (((self.cal['AC1'] * 4 + x3) << self.mode) + 2) // 4
        x1 = (self.cal['AC3'] * b6) >> 13
        x2 = (self.cal['B1'] * ((b6 * b6) >> 12)) >> 16
        x3 = ((x1 + x2) + 2) >> 2
        b4 = (self.cal['AC4'] * (x3 + 32768)) >> 15
        b7 = (up - b3) * (50000 >> self.mode)
        if b7 < 0x80000000:
            p = (b7 * 2) // b4
        else:
            p = (b7 // b4) * 2
        x1 = (p >> 8) * (p >> 8)
        x1 = (x1 * 3038) >> 16
        x2 = (-7357 * p) >> 16
        p += (x1 + x2 + 3791) >> 4
        return p
476042
def read_pressure(self):
        """"""
        UT = self.read_raw_temp()
        UP = self.read_raw_pressure()
        # Datasheet values for debugging:
        #UT = 27898
        #UP = 23843
        # Calculations below are taken straight from section 3.5 of the datasheet.
        # Calculate true temperature coefficient B5.
        X1 = ((UT - self.cal_AC6) * self.cal_AC5) >> 15
        X2 = (self.cal_MC << 11) // (X1 + self.cal_MD)
        B5 = X1 + X2
        self.logger.debug('B5 = {0}', B5)
        # Pressure Calculations
        B6 = B5 - 4000
        self.logger.debug('B6 = {0}', B6)
        X1 = (self.cal_B2 * (B6 * B6) >> 12) >> 11
        X2 = (self.cal_AC2 * B6) >> 11
        X3 = X1 + X2
        B3 = (((self.cal_AC1 * 4 + X3) << self._mode) + 2) // 4
        self.logger.debug('B3 = {0}', B3)
        X1 = (self.cal_AC3 * B6) >> 13
        X2 = (self.cal_B1 * ((B6 * B6) >> 12)) >> 16
        X3 = ((X1 + X2) + 2) >> 2
        B4 = (self.cal_AC4 * (X3 + 32768)) >> 15
        self.logger.debug('B4 = {0}', B4)
        B7 = (UP - B3) * (50000 >> self._mode)
        self.logger.debug('B7 = {0}', B7)
        if B7 < 0x80000000:
            p = (B7 * 2) // B4
        else:
            p = (B7 // B4) * 2
        X1 = (p >> 8) * (p >> 8)
        X1 = (X1 * 3038) >> 16
        X2 = (-7357 * p) >> 16
        p = p + ((X1 + X2 + 3791) >> 4)
        self.logger.debug('Pressure {0} Pa', p)
        return p/100
1302506
def density(self, r, rho0, Ra, Rs):
        
        Ra, Rs = self._sort_ra_rs(Ra, Rs)
        rho = rho0 / ((1 + (r / Ra) ** 2) * (1 + (r / Rs) ** 2))
        return rho
1373503
def _get_temperature(self, decoded):
        ''''''
        temp = (decoded[2] & 127) + decoded[3] / 100
        sign = (decoded[2] >> 7) & 1
        if sign == 0:
            return round(temp, 2)
        return round(-1 * temp, 2)
10100
def decode_temperature(packet, channel=1):
    """"""
    val = str(packet.get(QSDATA, ''))
    if len(val) == 12 and val.startswith('34') and channel == 1:
        temperature = int(val[-4:], 16)
        return round(float((-46.85 + (175.72 * (temperature / pow(2, 16))))))
    return None
971852
private static UnitValue temperature(UnitValue value, Unit target) {
    BigDecimal n = value.amount();
    if (target == Unit.TEMPERATURE_GENERIC) {
      return new UnitValue(n, Unit.TEMPERATURE_GENERIC);
    }

    switch (value.unit()) {
      case FAHRENHEIT:
        if (target == Unit.CELSIUS) {
            n = n.subtract(THIRTY_TWO);
            n = new Rational(n, BigDecimal.ONE).multiply(FIVE_NINTHS).compute(RoundingMode.HALF_EVEN);
        } else if (target == Unit.KELVIN) {
            n = n.add(KELVIN_FAHRENHEIT);
            n = new Rational(n, BigDecimal.ONE).multiply(FIVE_NINTHS).compute(RoundingMode.HALF_EVEN);
        }
        break;
        
      case CELSIUS:
        if (target == Unit.FAHRENHEIT) {
          Rational r = new Rational(n, BigDecimal.ONE);
          n = r.multiply(NINE_FIFTHS).compute(RoundingMode.HALF_EVEN).add(THIRTY_TWO);
        } else if (target == Unit.KELVIN) {
          n = n.add(KELVIN_CELSIUS);
        }
        break;
        
      case KELVIN:
        if (target == Unit.CELSIUS) {
          n = n.subtract(KELVIN_CELSIUS);
        } else if (target == Unit.FAHRENHEIT) {
          Rational r = new Rational(n, BigDecimal.ONE).multiply(NINE_FIFTHS);
          n = r.compute(RoundingMode.HALF_EVEN).subtract(KELVIN_FAHRENHEIT);
        }
        break;
        
      default:
        return new UnitValue(n, Unit.TEMPERATURE_GENERIC);
    }

    return new UnitValue(n.stripTrailingZeros(), target);
  }
69150
public MDecimal getKelvin() {
		MDecimal result = new MDecimal(currentUnit.getConverterTo(KELVIN)
				.convert(doubleValue()));
		logger.trace(MMarker.GETTER, "Converting from {} to Fahrenheit : {}",
				currentUnit, result);
		return result;
	}
1354738
def want(unit=nil)
      case unit
      when Unit
        expr = unit.expr
      when Quantity
        expr = unit.expr
        unit = unit.unit
      when String,Symbol
        expr = unit
        unit = Unit.parse(expr)
      when Numeric
        unit = Unit.cast(unit)
      when NilClass
        unit = Unit.cast(1)
      else
        raise TypeError, "invalid argument: #{unit.inspect}"
      end
      val = unit.convert(self)
      self.class.new( val, expr, unit )
    end
81036
def F(self, **kwargs):
        '''
        
        '''
        Eg = self.Eg_Gamma_0(**kwargs)
        Delta_SO = self.Delta_SO(**kwargs)
        Ep = self.Ep(**kwargs)
        meff = self.meff_e_Gamma_0(**kwargs)
        return (1./meff-1-(Ep*(Eg+2.*Delta_SO/3.))/(Eg*(Eg+Delta_SO)))/2
795722
public static double convertFromFarenheit (TemperatureScale to, double temperature) {

        switch(to) {

            case FARENHEIT:
                return temperature;
            case CELSIUS:
                return convertFarenheitToCelsius(temperature);
            case KELVIN:
                return convertFarenheitToKelvin(temperature);
            case RANKINE:
                return convertFarenheitToRankine(temperature);
            default:
                throw(new RuntimeException("Invalid termpature conversion"));
        }
    }
1354427
def _saturation(self, T):
        """"""
        rhoc = self._constants.get("rhoref", self.rhoc)
        Tc = self._constants.get("Tref", self.Tc)

        if T > Tc:
            T = Tc
        tau = Tc/T

        rhoLo = self._Liquid_Density(T)
        rhoGo = self._Vapor_Density(T)

        def f(parr):
            rhol, rhog = parr
            deltaL = rhol/rhoc
            deltaG = rhog/rhoc
            phirL = _phir(tau, deltaL, self._constants)
            phirG = _phir(tau, deltaG, self._constants)
            phirdL = _phird(tau, deltaL, self._constants)
            phirdG = _phird(tau, deltaG, self._constants)
            Jl = deltaL*(1+deltaL*phirdL)
            Jv = deltaG*(1+deltaG*phirdG)
            Kl = deltaL*phirdL+phirL+log(deltaL)
            Kv = deltaG*phirdG+phirG+log(deltaG)
            return Kv-Kl, Jv-Jl

        rhoL, rhoG = fsolve(f, [rhoLo, rhoGo])
        if rhoL == rhoG:
            Ps = self.Pc
        else:
            deltaL = rhoL/self.rhoc
            deltaG = rhoG/self.rhoc
            firL = _phir(tau, deltaL, self._constants)
            firG = _phir(tau, deltaG, self._constants)

            Ps = self.R*T*rhoL*rhoG/(rhoL-rhoG)*(firL-firG+log(deltaL/deltaG))
        return rhoL, rhoG, Ps
67728
def density(self, r, rho0, Rs):
        
        rho = rho0 / (r/Rs * (1 + (r/Rs))**3)
        return rho