calcualte statisics when temperatures are selected
169483
def get_new_T_PI_parameters(self, event):
        

        # remember the last saved interpretation
        if "saved" in list(self.pars.keys()):
            if self.pars['saved']:
                self.last_saved_pars = {}
                for key in list(self.pars.keys()):
                    self.last_saved_pars[key] = self.pars[key]
        self.pars['saved'] = False
        t1 = self.tmin_box.GetValue()
        t2 = self.tmax_box.GetValue()

        if (t1 == "" or t2 == ""):
            print("empty interpretation bounds")
            return
        if float(t2) < float(t1):
            print("upper bound less than lower bound")
            return

        index_1 = self.T_list.index(t1)
        index_2 = self.T_list.index(t2)

        # if (index_2-index_1)+1 >= self.acceptance_criteria['specimen_int_n']:
        if (index_2 - index_1) + 1 >= 3:
            if self.Data[self.s]['T_or_MW'] != "MW":
                self.pars = thellier_gui_lib.get_PI_parameters(self.Data, self.acceptance_criteria, self.preferences, self.s, float(
                    t1) + 273., float(t2) + 273., self.GUI_log, THERMAL, MICROWAVE)
                self.Data[self.s]['pars'] = self.pars
            else:
                self.pars = thellier_gui_lib.get_PI_parameters(
                    self.Data, self.acceptance_criteria, self.preferences, self.s, float(t1), float(t2), self.GUI_log, THERMAL, MICROWAVE)
                self.Data[self.s]['pars'] = self.pars
            self.update_GUI_with_new_interpretation()
            self.Add_text(self.s)
25822
private static Stats calcStats(List<Double> nums) {
    double sum = 0.0, mean = 0.0, variance = 0.0, stdDev = 0.0;
    for (Double d : nums) {
      sum += d.doubleValue();
    }
    if (nums.size() > 0) {
      mean = sum / nums.size();
    }

    sum = 0.0;
    for (Double d : nums) {
      sum += (d.doubleValue() - mean) * (d.doubleValue() - mean);
    }
    if (nums.size() > 0) {
      variance = sum / nums.size();
    }

    stdDev = Math.sqrt(variance);
    return new Stats(mean, variance, stdDev);
  }
1035759
def correct(self, temp, we_t):
        
        if not PIDTempComp.in_range(temp):
            return None

        n_t = self.cf_t(temp)

        if n_t is None:
            return None

        we_c = we_t * n_t

        return we_c
570014
def room_temperature(self):
        """"""
        # Check which side is active, if both are return the average
        tmp = None
        tmp2 = None
        for user in self.users:
            obj = self.users[user]
            if obj.current_values['processing']:
                if tmp is None:
                    tmp = obj.current_values['room_temp']
                else:
                    tmp = (tmp + obj.current_values['room_temp']) / 2
            else:
                if tmp2 is None:
                    tmp2 = obj.current_values['room_temp']
                else:
                    tmp2 = (tmp2 + obj.current_values['room_temp']) / 2

        if tmp is not None:
            return tmp
        elif tmp2 is not None:
            return tmp2
878946
def _calculate(seed, world):
        """"""
        rng = numpy.random.RandomState(seed)  # create our own random generator
        base = rng.randint(0, 4096)

        curve_gamma = world.gamma_curve
        curve_bonus = world.curve_offset
        height = world.height
        width = world.width
        border = width / 4
        precipitations = numpy.zeros((height, width), dtype=float)

        octaves = 6
        freq = 64.0 * octaves

        n_scale = 1024 / float(height) #This is a variable I am adding. It exists
                                       #so that worlds sharing a common seed but
                                       #different sizes will have similar patterns

        for y in range(height):#TODO: numpy
            for x in range(width):
                n = snoise2((x * n_scale) / freq, (y * n_scale) / freq, octaves, base=base)

                # Added to allow noise pattern to wrap around right and left.
                if x < border:
                    n = (snoise2( (x * n_scale) / freq, (y * n_scale) / freq, octaves,
                                 base=base) * x / border) + (
                        snoise2(( (x * n_scale) + width) / freq, (y * n_scale) / freq, octaves,
                                base=base) * (border - x) / border)

                precipitations[y, x] = n

        #find ranges
        min_precip = precipitations.min()
        max_precip = precipitations.max()
        min_temp = world.layers['temperature'].min()
        max_temp = world.layers['temperature'].max()
        precip_delta = (max_precip - min_precip)
        temp_delta = (max_temp - min_temp)
        
        #normalize temperature and precipitation arrays
        t = (world.layers['temperature'].data - min_temp) / temp_delta
        p = (precipitations - min_precip) / precip_delta
        
        #modify precipitation based on temperature

        #--------------------------------------------------------------------------------
        #
        # Ok, some explanation here because why the formula is doing this may be a
        # little confusing. We are going to generate a modified gamma curve based on 
        # normalized temperature and multiply our precipitation amounts by it.
        #
        # numpy.power(t,curve_gamma) generates a standard gamma curve. However
        # we probably don't want to be multiplying precipitation by 0 at the far
        # side of the curve. To avoid this we multiply the curve by (1 - curve_bonus)
        # and then add back curve_bonus. Thus, if we have a curve bonus of .2 then
        # the range of our modified gamma curve goes from 0-1 to 0-.8 after we
        # multiply and then to .2-1 after we add back the curve_bonus.
        #
        # Because we renormalize there is not much point to offsetting the opposite end
        # of the curve so it is less than or more than 1. We are trying to avoid
        # setting the start of the curve to 0 because f(t) * p would equal 0 when t equals
        # 0. However f(t) * p does not automatically equal 1 when t equals 1 and if we
        # raise or lower the value for f(t) at 1 it would have negligible impact after
        # renormalizing.
        #
        #--------------------------------------------------------------------------------
        
        curve = (numpy.power(t, curve_gamma) * (1-curve_bonus)) + curve_bonus
        precipitations = numpy.multiply(p, curve)

        #Renormalize precipitation because the precipitation 
        #changes will probably not fully extend from -1 to 1.
        min_precip = precipitations.min()
        max_precip = precipitations.max()
        precip_delta = (max_precip - min_precip)
        precipitations = (((precipitations - min_precip) / precip_delta) * 2) - 1
        
        return precipitations
463710
def lambda_max(self):
        """"""
        return ((const.b_wien.value / self.temperature) * u.m).to(u.AA).value
1078234
def _compute_heating_rates(self):
        
        for varname, value in self.state.items():
            self.heating_rate[varname] = - self.b * (value - global_mean(value))
511353
private function _temperature()
    {
        for ($intPosi = 3; $intPosi < 6; $intPosi++) {
            if ($this->_buf_value[$intPosi] == 0) {
                continue;
            }
            preg_match("/([0-9\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits);
            $dev = new SensorDevice();
            $dev->setName($this->_buf_label[$intPosi]);
            $dev->setValue($hits[0]);
//            $dev->setMax(70);
            $this->mbinfo->setMbTemp($dev);
        }
    }
1302001
def heat_level(self, value):
        """"""
        if value < 0:
            self._heat_level = 0
        elif round(value) > self._num_segments:
            self._heat_level = self._num_segments
        else:
            self._heat_level = int(round(value))
550567
def getLimbdarkeningCoeff(self, wavelength=1.22):  # TODO replace with pylightcurve
        
        # TODO check this returns correct value - im not certain
        # The intervals of values in the tables
        tempind = [ 3500., 3750., 4000., 4250., 4500., 4750., 5000., 5250., 5500., 5750., 6000., 6250.,
                 6500., 6750., 7000., 7250., 7500., 7750., 8000., 8250., 8500., 8750., 9000., 9250.,
                 9500., 9750., 10000., 10250., 10500., 10750., 11000., 11250., 11500., 11750., 12000., 12250.,
                 12500., 12750., 13000., 14000., 15000., 16000., 17000., 19000., 20000., 21000., 22000., 23000.,
                 24000., 25000., 26000., 27000., 28000., 29000., 30000., 31000., 32000., 33000., 34000., 35000.,
                 36000., 37000., 38000., 39000., 40000., 41000., 42000., 43000., 44000., 45000., 46000., 47000.,
                 48000., 49000., 50000.]
        lggind = [0., 0.5, 1., 1.5, 2., 2.5, 3., 3.5, 4., 4.5, 5.]
        mhind = [-5., -4.5, -4., -3.5, -3., -2.5, -2., -1.5, -1., -0.5, -0.3, -0.2, -0.1, 0., 0.1, 0.2, 0.3, 0.5, 1.]

        # Choose the values in the table nearest our parameters
        tempselect = _findNearest(tempind, float(self.T))
        lgselect = _findNearest(lggind, float(self.calcLogg()))
        mhselect = _findNearest(mhind, float(self.Z))

        quadratic_filepath = resource_stream(__name__, 'data/quadratic.dat')
        coeffTable = np.loadtxt(quadratic_filepath)

        foundValues = False
        for i in range(len(coeffTable)):
            if coeffTable[i, 2] == lgselect and coeffTable[i, 3] == tempselect and coeffTable[i, 4] == mhselect:
                if coeffTable[i, 0] == 1:
                    u1array = coeffTable[i, 8:]  # Limb darkening parameter u1 for each wl in waveind
                    u2array = coeffTable[i+1, 8:]
                    foundValues = True
                    break

        if not foundValues:
            raise ValueError('No limb darkening values could be found')  # TODO replace with better exception

        waveind = [0.365, 0.445, 0.551, 0.658, 0.806, 1.22, 1.63, 2.19, 3.45]  # Wavelengths available in table

        # Interpolates the value at wavelength from values in the table (waveind)
        u1AtWavelength = np.interp(wavelength, waveind, u1array, left=0, right=0)
        u2AtWavelength = np.interp(wavelength, waveind, u2array, left=0, right=0)

        return u1AtWavelength, u2AtWavelength
763259
def cal_pst(self, v):
        
        p_h = self._hugoniot_p(v)
        p_th_h = self._hugoniot_pth(v)
        p_st = p_h - p_th_h
        return p_st
1205032
private function _temperature()
    {
        foreach ($this->_lines as $line) {
            $buffer = preg_split("/\s*\|\s*/", $line);
            if ($buffer[2] == "Temperature" && $buffer[11] != "N/A" && $buffer[4] == "C") {
                $dev = new SensorDevice();
                $dev->setName($buffer[1]);
                $dev->setValue($buffer[3]);
                if ($buffer[9] != "N/A") $dev->setMax($buffer[9]);
                if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
                $this->mbinfo->setMbTemp($dev);
            }
        }
    }
265701
def get_temperature_single(self, device):
        """"""
        temp_str = self.__query_cmd('gettemperature', device)
        if temp_str.lstrip('-').isdigit():
            return float(temp_str) / 10.0
        return 'inval'
160273
def set_target_temperature(self, ain, temperature):
        """"""
        param = 16 + ((float(temperature) - 8) * 2)

        if param < min(range(16, 56)):
            param = 253
        elif param > max(range(16, 56)):
            param = 254
        self._aha_request('sethkrtsoll', ain=ain, param=int(param))
966553
def sample_with_temperature(logits, temperature, sampling_keep_top_k=-1):
  
  if temperature == 0.0:
    # TF argmax doesn't handle >5 dimensions, so we reshape here.
    logits_shape = shape_list(logits)
    argmax = tf.argmax(tf.reshape(logits, [-1, logits_shape[-1]]), axis=1)
    return tf.reshape(argmax, logits_shape[:-1])
  else:
    assert temperature > 0.0

    if sampling_keep_top_k != -1:
      if sampling_keep_top_k <= 0:
        raise ValueError("sampling_keep_top_k must either be -1 or positive.")

      vocab_size = shape_list(logits)[1]

      k_largest = tf.contrib.nn.nth_element(
          logits, n=sampling_keep_top_k, reverse=True)
      k_largest = tf.tile(tf.reshape(k_largest, [-1, 1]), [1, vocab_size])

      # Force every position that is not in the top k to have probability near
      # 0 by setting the logit to be very negative.
      logits = tf.where(tf.less_equal(logits, k_largest),
                        tf.ones_like(logits)*-1e6, logits)

    reshaped_logits = (
        tf.reshape(logits, [-1, shape_list(logits)[-1]]) / temperature)
    choices = tf.multinomial(reshaped_logits, 1)
    choices = tf.reshape(choices,
                         shape_list(logits)[:logits.get_shape().ndims - 1])
    return choices
892993
def get_current_temperature(self, refresh=False):
        """"""
        if refresh:
            self.refresh()
        try:
            return float(self.get_value('temperature'))
        except (TypeError, ValueError):
            return None
1345307
def _get_temperature(self, data):
        ''''''
        if data[1:2] == 0x7FFF:
            return None

        temperature = twos_complement((data[1] << 8) + data[2], 16) / 200
        return round(temperature, 2)