Calculate cumulus cloud base in metres, using formula from
    https://en.wikipedia.org/wiki/Cloud_base or
    https://de.wikipedia.org/wiki/Kondensationsniveau#Konvektionskondensationsniveau
189791
def cloud_base(temp, hum):
    
    if temp is None or hum is None:
        return None
    dew_pt = dew_point(temp, hum)
    spread = float(temp) - dew_pt
    return spread * 125.0
1030452
function cloudSprite(contextAndRatio, d, data, di) {
  if (d.sprite) return;
  var c = contextAndRatio.context,
      ratio = contextAndRatio.ratio;

  c.clearRect(0, 0, (cw << 5) / ratio, ch / ratio);
  var x = 0,
      y = 0,
      maxh = 0,
      n = data.length,
      w, w32, h, i, j;
  --di;
  while (++di < n) {
    d = data[di];
    c.save();
    c.font = d.style + " " + d.weight + " " + ~~((d.size + 1) / ratio) + "px " + d.font;
    w = c.measureText(d.text + "m").width * ratio;
    h = d.size << 1;
    if (d.rotate) {
      var sr = Math.sin(d.rotate * cloudRadians),
          cr = Math.cos(d.rotate * cloudRadians),
          wcr = w * cr,
          wsr = w * sr,
          hcr = h * cr,
          hsr = h * sr;
      w = (Math.max(Math.abs(wcr + hsr), Math.abs(wcr - hsr)) + 0x1f) >> 5 << 5;
      h = ~~Math.max(Math.abs(wsr + hcr), Math.abs(wsr - hcr));
    } else {
      w = (w + 0x1f) >> 5 << 5;
    }
    if (h > maxh) maxh = h;
    if (x + w >= (cw << 5)) {
      x = 0;
      y += maxh;
      maxh = 0;
    }
    if (y + h >= ch) break;
    c.translate((x + (w >> 1)) / ratio, (y + (h >> 1)) / ratio);
    if (d.rotate) c.rotate(d.rotate * cloudRadians);
    c.fillText(d.text, 0, 0);
    if (d.padding) {
      c.lineWidth = 2 * d.padding;
      c.strokeText(d.text, 0, 0);
    }
    c.restore();
    d.width = w;
    d.height = h;
    d.xoff = x;
    d.yoff = y;
    d.x1 = w >> 1;
    d.y1 = h >> 1;
    d.x0 = -d.x1;
    d.y0 = -d.y1;
    d.hasText = true;
    x += w;
  }
  var pixels = c.getImageData(0, 0, (cw << 5) / ratio, ch / ratio).data,
      sprite = [];
  while (--di >= 0) {
    d = data[di];
    if (!d.hasText) continue;
    w = d.width;
    w32 = w >> 5;
    h = d.y1 - d.y0;
    // Zero the buffer
    for (i = 0; i < h * w32; i++) sprite[i] = 0;
    x = d.xoff;
    if (x == null) return;
    y = d.yoff;
    var seen = 0,
        seenRow = -1;
    for (j = 0; j < h; j++) {
      for (i = 0; i < w; i++) {
        var k = w32 * j + (i >> 5),
            m = pixels[((y + j) * (cw << 5) + (x + i)) << 2] ? 1 << (31 - (i % 32)) : 0;
        sprite[k] |= m;
        seen |= m;
      }
      if (seen) seenRow = j;
      else {
        d.y0++;
        h--;
        j--;
        y++;
      }
    }
    d.y1 = d.y0 + seenRow;
    d.sprite = sprite.slice(0, (d.y1 - d.y0) * w32);
  }
}
653079
public double[][] calculateQ() {
        double timestep = fixedParams.getTimestep();
        double area_super = fixedParams.getArea();
        double area_sub = fixedParams.getArea_sub();
        double area_tot = 0f;

        double raintimestep = jeffC.getRain_timestep();
        DateTime firstDate = jeffC.getFirstDate();

        /*
         * The maximum rain time has no sense with the real precipitations. In this case it will use
         * the rain timestep for tp.
         */
        double tcorr = ampi[ampi.length - 1][0];
        tpmax = (double) raintimestep;
        int rainLength = jeff.size();
        double[][] totalQshiftMatrix = new double[rainLength][(int) (Math.floor((tcorr + tpmax) / timestep) + 1 + rainLength
                * raintimestep / timestep)];
        double[][] Q = new double[(int) Math.floor((tcorr + tpmax) / timestep) + 1][3];

        if (area_sub != -9999.0) {
            area_tot = area_sub + area_super;
        } else {
            area_tot = area_super;
        }

        Set<DateTime> dates = jeff.keySet();
        pm.beginTask("Calculating discharge...", dates.size());
        int i = 0;
        for( DateTime dateTime : dates ) {
            double J = jeff.get(dateTime);
            /*
             * calculate the discharge for t < tcorr
             */
            int j = 0;
            for( int t = 1; t < tcorr; t += timestep ) {
                j = (int) Math.floor((t) / timestep);

                if (t <= tpmax) {
                    Q[j][0] = t;
                    double widthInterpolate = ModelsEngine.width_interpolate(ampi, t, 0, 2);
                    Q[j][1] = (double) (J * area_tot * widthInterpolate);
                    Q[j][2] = Q[j - 1][2] + Q[j][1];
                } else {
                    Q[j][0] = t;
                    Q[j][1] = (double) (J * area_tot * (ModelsEngine.width_interpolate(ampi, t, 0, 2) - ModelsEngine
                            .width_interpolate(ampi, t - tpmax, 0, 2)));
                    Q[j][2] = Q[j - 1][2] + Q[j][1];
                }
            }

            /*
             * calculate the discharge for t > tcorr
             */

            for( double t = tcorr; t < (tcorr + tpmax); t += timestep ) {
                j = (int) Math.floor(((int) t) / timestep);
                Q[j][0] = t;
                Q[j][1] = (double) (J * area_tot * (ampi[ampi.length - 1][2] - ModelsEngine.width_interpolate(ampi, t - tpmax, 0,
                        2)));
                Q[j][2] = Q[j - 1][2] + Q[j][1];
            }

            /*
             * calculate the volumes
             */
            // double vol = Q[Q.length - 2][2] * timestep;
            // double vol2 = (double) (area_tot * J * raintimestep);

            /*
             * calculate zero padding before first value Note that jeff contains already the
             * progressive time of the rainfile.
             */
            int totalshiftmatrixindex = 0;
            int initalshiftmatrixindex = 0;
            // FIXME time in ???
            Duration duration = new Duration(firstDate, dateTime);
            long intervalSeconds = duration.getStandardSeconds();

            int paddingnumber = (int) (intervalSeconds / timestep);
            for( int m = 0; m < paddingnumber; m++ ) {
                totalQshiftMatrix[i][m] = 0;
                totalshiftmatrixindex++;
            }
            initalshiftmatrixindex = totalshiftmatrixindex;
            for( int k = initalshiftmatrixindex; k < Q.length + initalshiftmatrixindex; k++ ) {
                totalQshiftMatrix[i][k] = Q[k - initalshiftmatrixindex][1];
                totalshiftmatrixindex++;
            }
            for( int k = Q.length + totalshiftmatrixindex; k < totalQshiftMatrix[0].length; k++ ) {
                totalQshiftMatrix[i][k] = 0;
            }
            i++;
            pm.worked(1);
        }
        pm.done();

        /*
         * sum the discharge contributes
         */
        Qtot = new double[totalQshiftMatrix[0].length][2];
        double tottime = 0f;
        for( int k = 0; k < Qtot.length; k++ ) {
            double sum = 0f;
            for( int j = 0; j < totalQshiftMatrix.length; j++ ) {
                sum = sum + totalQshiftMatrix[j][k];
            }

            tottime = tottime + timestep;

            Qtot[k][1] = sum;
            Qtot[k][0] = tottime;
        }

        double total_vol = 0f;
        for( int k = 0; k < Qtot.length; k++ ) {
            total_vol = total_vol + Qtot[k][1];
        }
        double total_rain = 0.0;
        for( DateTime dateTime : dates ) {
            double J = jeff.get(dateTime);
            total_rain = total_rain + J;
        }
        total_rain = total_rain * area_tot * raintimestep;

        return Qtot;
    }
382512
def _compute_magnitude_term(self, C, mag):
        
        fmag = C['c0'] + C['c1'] * mag
        if mag <= 5.5:
            return fmag
        elif mag > 6.5:
            return fmag + (C['c2'] * (mag - 5.5)) + (C['c3'] * (mag - 6.5))
        else:
            return fmag + (C['c2'] * (mag - 5.5))
905059
function calculateBase(groupItem) {
    var extent;
    var baseAxis = groupItem.axis;
    var seriesModels = groupItem.seriesModels;
    var seriesCount = seriesModels.length;

    var boxWidthList = groupItem.boxWidthList = [];
    var boxOffsetList = groupItem.boxOffsetList = [];
    var boundList = [];

    var bandWidth;
    if (baseAxis.type === 'category') {
        bandWidth = baseAxis.getBandWidth();
    }
    else {
        var maxDataCount = 0;
        each(seriesModels, function (seriesModel) {
            maxDataCount = Math.max(maxDataCount, seriesModel.getData().count());
        });
        extent = baseAxis.getExtent(),
        Math.abs(extent[1] - extent[0]) / maxDataCount;
    }

    each(seriesModels, function (seriesModel) {
        var boxWidthBound = seriesModel.get('boxWidth');
        if (!zrUtil.isArray(boxWidthBound)) {
            boxWidthBound = [boxWidthBound, boxWidthBound];
        }
        boundList.push([
            parsePercent(boxWidthBound[0], bandWidth) || 0,
            parsePercent(boxWidthBound[1], bandWidth) || 0
        ]);
    });

    var availableWidth = bandWidth * 0.8 - 2;
    var boxGap = availableWidth / seriesCount * 0.3;
    var boxWidth = (availableWidth - boxGap * (seriesCount - 1)) / seriesCount;
    var base = boxWidth / 2 - availableWidth / 2;

    each(seriesModels, function (seriesModel, idx) {
        boxOffsetList.push(base);
        base += boxGap + boxWidth;

        boxWidthList.push(
            Math.min(Math.max(boxWidth, boundList[idx][0]), boundList[idx][1])
        );
    });
}
531694
def s2tc(s,base=25):
    """"""
    try:
        f = int(s*base)
    except:
        return "--:--:--:--"
    hh  = int((f / base) / 3600)
    hhd = int((hh % 24))
    mm  = int(((f / base) / 60) - (hh*60))
    ss  = int((f/base) - (hh*3600) - (mm*60))
    ff  = int(f - (hh*3600*base) - (mm*60*base) - (ss*base))
    return "{:02d}:{:02d}:{:02d}:{:02d}".format(hhd, mm, ss, ff)
642733
def _calc_cc(self, iso_size):
        # type: (int) -> Tuple[int, int]
        '''
        
        '''
        cylsize = self.geometry_heads * self.geometry_sectors * 512
        frac = iso_size % cylsize
        padding = 0
        if frac > 0:
            padding = cylsize - frac
        cc = (iso_size + padding) // cylsize
        if cc > 1024:
            cc = 1024

        return (cc, padding)
312254
function(date, units)
			{
				var ceilYear = (units.years > 0);
				var ceilMonth = ceilYear || (units.months > 0);
				var ceilDay = ceilMonth || (units.days > 0);
				var ceilHours = ceilDay || (units.hours > 0);
				var ceilMinutes = ceilHours || (units.minutes > 0);
				var ceilSeconds = ceilMinutes || (units.seconds > 0);

				if (!ceilSeconds)
					return;

				if (date.getSeconds() > 0)
				{
					if (units.seconds > 0)
						date.setSeconds(Math.min(Math.ceil(date.getSeconds() / units.seconds) * units.seconds, 60));
					else
						date.setSeconds(60);
				}

				if (!ceilMinutes)
					return;

				if (date.getMinutes() > 0)
				{
					if (units.minutes > 0)
						date.setMinutes(Math.min(Math.ceil(date.getMinutes() / units.minutes) * units.minutes, 60));
					else
						date.setMinutes(60);
				}

				if (!ceilHours)
					return;

				if (date.getHours() > 0)
				{
					if (units.hours > 0)
						date.setHours(Math.min(Math.ceil(date.getHours() / units.hours) * units.hours, 24));
					else
						date.setHours(24);
				}

				if (!ceilDay)
					return;

				if (date.getDay() > 1)
				{
					var daysInMonth = TimeUtils.daysInMonth(date);
					if (units.days > 0)
						date.setDay(Math.min(Math.ceil((date.getDay() - 1) / units.days) * units.days, daysInMonth) + 1);
					else
						date.setDay(daysInMonth + 1);
				}

				if (!ceilMonth)
					return;

				if (date.getMonth() > 1)
				{
					if (units.months > 0)
						date.setMonth(Math.min(Math.ceil((date.getMonth() - 1) / units.months) * units.months, 12) + 1);
					else
						date.setMonth(12 + 1);
				}

				if (!ceilYear)
					return;

				if (units.years > 0)
					date.setYear(Math.ceil(date.getYear() / units.years) * units.years);
			}
109273
function() {

      // atanh(c) = log((1+c) / (1-c)) / 2

      var a = this['re'];
      var b = this['im'];

      var noIM = a > 1 && b === 0;
      var oneMinus = 1 - a;
      var onePlus = 1 + a;
      var d = oneMinus * oneMinus + b * b;

      var x = (d !== 0)
              ? new Complex(
                      (onePlus * oneMinus - b * b) / d,
                      (b * oneMinus + onePlus * b) / d)
              : new Complex(
                      (a !== -1) ? (a / 0) : 0,
                      (b !== 0) ? (b / 0) : 0);

      var temp = x['re'];
      x['re'] = logHypot(x['re'], x['im']) / 2;
      x['im'] = Math.atan2(x['im'], temp) / 2;
      if (noIM) {
        x['im'] = -x['im'];
      }
      return x;
    }
475784
def _compute_magnitude(self, rup, C):
        
        return C['b1'] + (C['b2'] * rup.mag) + (C['b3'] * (rup.mag ** 2))
1295095
def as_base_units(self):
        
        b = collections.defaultdict(int)
        factor = 1
        for k, v in self.items():
            derived = False
            for d in DERIVED_UNITS.values():
                if k in d:
                    for k2, v2 in d[k].items():
                        if isinstance(k2, Number):
                            factor *= k2 ** (v2 * v)
                        else:
                            b[k2] += v2 * v
                    derived = True
                    break
            if not derived:
                si, f = _get_si_unit(k)
                b[si] += v
                factor *= f ** v
        return {k: v for k, v in b.items() if v != 0}, factor
615385
def dew_point_from_db_enth(db_temp, enthlpy, b_press=101325):
    
    rh = rel_humid_from_db_enth(db_temp, enthlpy, b_press)
    td = dew_point_from_db_rh(db_temp, rh)
    return td
477876
def humidity_unit(self):
        """"""
        if CONST.UNIT_PERCENT in self._get_status(CONST.HUMI_STATUS_KEY):
            return CONST.UNIT_PERCENT
        return None
589519
def calc_basics(width=-1, length=-1, height=2.4, prevailing_wind=2.8):   
    
    if width == -1:
        width = int(input('enter building width : '))
    if length == -1:
        length = int(input('enter building length : '))
    res = {}
    
    res['area'] = width * length
    res['perim'] =  2 * width + 2 * length
    res['roof_cladding'] = res['area']
    res['wall_cladding'] = res['perim'] * height
    pprint(res)
    return res
1107080
def to_base
      return self if base?
      if @@unit_map[units] =~ /\A<(?:temp|deg)[CRF]>\Z/
        @signature = @@kinds.key(:temperature)
        base = if temperature?
                 convert_to('tempK')
               elsif degree?
                 convert_to('degK')
               end
        return base
      end

      cached = (begin
                  (@@base_unit_cache[units] * scalar)
                rescue
                  nil
                end)
      return cached if cached

      num = []
      den = []
      q   = Rational(1)
      @numerator.compact.each do |num_unit|
        if @@prefix_values[num_unit]
          q *= @@prefix_values[num_unit]
        else
          q *= @@unit_values[num_unit][:scalar] if @@unit_values[num_unit]
          num << @@unit_values[num_unit][:numerator] if @@unit_values[num_unit] && @@unit_values[num_unit][:numerator]
          den << @@unit_values[num_unit][:denominator] if @@unit_values[num_unit] && @@unit_values[num_unit][:denominator]
        end
      end
      @denominator.compact.each do |num_unit|
        if @@prefix_values[num_unit]
          q /= @@prefix_values[num_unit]
        else
          q /= @@unit_values[num_unit][:scalar] if @@unit_values[num_unit]
          den << @@unit_values[num_unit][:numerator] if @@unit_values[num_unit] && @@unit_values[num_unit][:numerator]
          num << @@unit_values[num_unit][:denominator] if @@unit_values[num_unit] && @@unit_values[num_unit][:denominator]
        end
      end

      num = num.flatten.compact
      den = den.flatten.compact
      num = UNITY_ARRAY if num.empty?
      base = RubyUnits::Unit.new(RubyUnits::Unit.eliminate_terms(q, num, den))
      @@base_unit_cache[units] = base
      base * @scalar
    end
868044
def cal_p_bm3(v, k, p_ref=0.0):
    
    vvr = v / k[0]
    p = (p_ref - 0.5 * (3. * k[1] - 5. * p_ref) * (1. - vvr**(-2. / 3.)) +
         9. / 8. * k[1] * (k[2] - 4. + 35. / 9. * p_ref / k[1]) *
         (1. - vvr**(-2. / 3.))**2.) * vvr**(-5. / 3.)
    return p
457076
public static void statistics( List<Point3D_F64> cloud , Point3D_F64 mean , Point3D_F64 stdev ) {
		final int N = cloud.size();
		for (int i = 0; i < N; i++) {
			Point3D_F64 p = cloud.get(i);
			mean.x += p.x / N;
			mean.y += p.y / N;
			mean.z += p.z / N;
		}

		for (int i = 0; i < N; i++) {
			Point3D_F64 p = cloud.get(i);
			double dx = p.x-mean.x;
			double dy = p.y-mean.y;
			double dz = p.z-mean.z;

			stdev.x += dx*dx/N;
			stdev.y += dy*dy/N;
			stdev.z += dz*dz/N;
		}
		stdev.x = Math.sqrt(stdev.x);
		stdev.y = Math.sqrt(stdev.y);
		stdev.z = Math.sqrt(stdev.z);
	}