def _get_plateau_age(self): ages, errors, k39 = self._get_steps() options = {'nsteps': self.pc_nsteps, 'gas_fraction': self.pc_gas_fraction, 'force_steps': self.calculate_fixed_plateau_steps} args = calculate_plateau_age(ages, errors, k39, options=options) if args: v, e, pidx = args if pidx[0]==pidx[1]: return self.plateau_steps = pidx self.plateau_steps_str = '{}-{}'.format(ALPHAS[pidx[0]], ALPHAS[pidx[1]]) self.nsteps = (pidx[1] - pidx[0]) + 1 # print pidx pages, perrs = zip(*[(ages[i], errors[i]) for i in range(pidx[0], pidx[1])]) mswd = calculate_mswd(pages, perrs) self.plateau_mswd_valid = validate_mswd(mswd, self.nsteps) self.plateau_mswd = mswd e = self._modify_error(v, e, self.plateau_age_error_kind, mswd=mswd, include_j_error=self.include_j_error_in_plateau) if math.isnan(e): e = 0 return ufloat(v, max(0, e))
def _get_plateau_age(self): ages, errors, k39 = self._get_steps() args = calculate_plateau_age(ages, errors, k39) if args: v, e, pidx = args self.plateau_steps = pidx self.plateau_steps_str = '{}-{}'.format(ALPHAS[pidx[0]], ALPHAS[pidx[1]]) self.nsteps = (pidx[1] - pidx[0]) + 1 pages, perrs = zip(*[(ages[i], errors[i]) for i in range(pidx[0], pidx[1])]) mswd = calculate_mswd(pages, perrs) self.plateau_mswd_valid = validate_mswd(mswd, self.nsteps) self.plateau_mswd = mswd e = self._modify_error(v, e, self.plateau_age_error_kind, mswd=mswd, include_j_error=self.include_j_error_in_plateau) if math.isnan(e): e = 0 return ufloat(v, max(0, e))
def _calculate_mswd(self, attr): m = 0 args = self._get_values(attr) if args: vs, es = args m = calculate_mswd(vs, es) return m
def _get_mswd(self): m = '' args = self._get_values('uage') if args: vs, es = args m = calculate_mswd(vs, es) return m
def check_mswd(self, start, end): """ return False if not valid """ ages = self.ages[start, end + 1] errors = self.errors[start, end + 1] mswd = calculate_mswd(ages, errors) return validate_mswd(mswd, len(ages))
def _calculate_mswd(self, attr, values=None): m = 0 if values is None: values = self._get_values(attr) if values: vs, es = values m = calculate_mswd(vs, es) return m
def _get_mswd(self): self.valid_mswd = False ys = self._clean_array(self.ys) yserr = self._clean_array(self.yserr) if self._check_integrity(ys, yserr): mswd = calculate_mswd(ys, yserr) self.valid_mswd = validate_mswd(mswd, len(ys)) return mswd
def _get_mswd(self): self.valid_mswd=False ys=self._clean_array(self.ys) yserr=self._clean_array(self.yserr) if self._check_integrity(ys,yserr): mswd=calculate_mswd(ys, yserr) self.valid_mswd=validate_mswd(mswd,len(ys)) return mswd
def _get_mswd(self): self.valid_mswd = False # ys=self._clean_array(self.ys) # yserr=self._clean_array(self.yserr) ys = self.clean_ys yserr = self.clean_yserr if self._check_integrity(ys, yserr): mswd = calculate_mswd(ys, yserr, k=self.degrees_of_freedom) self.valid_mswd = validate_mswd(mswd, len(ys), k=self.degrees_of_freedom) or False return mswd
def _get_plateau_age(self): # ages, errors, k39 = self._get_steps() ages = [ai.age for ai in self.analyses] errors = [ai.age_err for ai in self.analyses] k39 = [ nominal_value(ai.get_computed_value('k39')) for ai in self.analyses ] options = { 'nsteps': self.pc_nsteps, 'gas_fraction': self.pc_gas_fraction, 'force_steps': self.calculate_fixed_plateau_steps } excludes = [i for i in enumerate(self.analyses) if ai.is_omitted()] args = calculate_plateau_age(ages, errors, k39, options=options, excludes=excludes) if args: v, e, pidx = args if pidx[0] == pidx[1]: return self.plateau_steps = pidx self.plateau_steps_str = '{}-{}'.format(ALPHAS[pidx[0]], ALPHAS[pidx[1]]) step_idxs = [ i for i in xrange(pidx[0], pidx[1] + 1) if not self.analyses[i].is_omitted() ] self.nsteps = len(step_idxs) pages = [ages[i] for i in step_idxs] perrs = [errors[i] for i in step_idxs] mswd = calculate_mswd(pages, perrs) self.plateau_mswd_valid = validate_mswd(mswd, self.nsteps) self.plateau_mswd = mswd e = self._modify_error( v, e, self.plateau_age_error_kind, mswd=mswd, include_j_error=self.include_j_error_in_plateau) if math.isnan(e): e = 0 return ufloat(v, max(0, e))
def attr_stats(self, attr): w, sd, sem, (vs, es) = self._calculate_weighted_mean(attr, error_kind='both') mswd = calculate_mswd(vs, es, wm=w) valid_mswd = validate_mswd(mswd, self.nanalyses) mi = min(vs) ma = max(vs) total_dev = (ma - mi) / ma * 100 return {'mean': w, 'sd': sd, 'sem': sem, 'mswd': mswd, 'valid_mswd': valid_mswd, 'min': mi, 'max': ma, 'total_dev': total_dev}
def _get_plateau_age(self): ans = self.analyses v, e = 0, 0 if all((not isinstance(ai, InterpretedAgeGroup) for ai in ans)): if ans: ages = [ai.age for ai in ans] errors = [ai.age_err for ai in ans] k39 = [nominal_value(ai.get_computed_value('k39')) for ai in ans] options = {'nsteps': self.plateau_nsteps, 'gas_fraction': self.plateau_gas_fraction, 'overlap_sigma': self.plateau_overlap_sigma, 'fixed_steps': self.fixed_steps} excludes = [i for i, ai in enumerate(ans) if ai.is_omitted()] args = calculate_plateau_age(ages, errors, k39, options=options, excludes=excludes) if args: v, e, pidx = args if pidx[0] == pidx[1]: return self.plateau_steps = pidx self.plateau_steps_str = '{}-{}'.format(ALPHAS[pidx[0]], ALPHAS[pidx[1]]) step_idxs = [i for i in range(pidx[0], pidx[1] + 1) if not ans[i].is_omitted()] self.nsteps = len(step_idxs) pages = array([ages[i] for i in step_idxs]) perrs = array([errors[i] for i in step_idxs]) mswd = calculate_mswd(pages, perrs) self.plateau_mswd_valid = validate_mswd(mswd, self.nsteps) self.plateau_mswd = mswd if self.plateau_age_error_kind == SD: e = array(pages).std() else: e = self._modify_error(v, e, self.plateau_age_error_kind, mswd=mswd) if math.isnan(e): e = 0 a = ufloat(v, max(0, e)) self._apply_j_err(a, force=self.include_j_error_in_mean or self.include_j_error_in_plateau) return a
def _get_plateau_age(self): ages, errors, k39 = self._get_steps() args = calculate_plateau_age(ages, errors, k39) if args: v, e, pidx = args self.plateau_steps = pidx self.plateau_steps_str = '{}-{}'.format(ALPHAS[pidx[0]], ALPHAS[pidx[1]]) self.nsteps = (pidx[1] - pidx[0]) + 1 pages, perrs = zip(*[(ages[i], errors[i]) for i in range(pidx[0], pidx[1])]) mswd = calculate_mswd(pages, perrs) self.plateau_mswd_valid = validate_mswd(mswd, self.nsteps) self.plateau_mswd = mswd return ufloat(v, e)
def load(self): ans = self.analyses ages = [ai.age for ai in ans] errors = [ai.age_err_wo_j for ai in ans] self.min_age = min(ages) self.max_age = max(ages) self.n = n = len(self.analyses) self.mean = sum(ages) / float(n) wm, we = calculate_weighted_mean(ages, errors) self.weighted_mean = wm mswd = calculate_mswd(ages, errors, wm=wm) self.mswd = mswd self.mswd_low, self.mswd_high = get_mswd_limits(n) self._create_ideogram() self._create_spectrum()
def _get_plateau_age(self): # ages, errors, k39 = self._get_steps() ages = [ai.age for ai in self.analyses] errors = [ai.age_err for ai in self.analyses] k39 = [nominal_value(ai.get_computed_value('k39')) for ai in self.analyses] options = {'nsteps': self.pc_nsteps, 'gas_fraction': self.pc_gas_fraction, 'force_steps': self.calculate_fixed_plateau_steps} excludes = [i for i in enumerate(self.analyses) if ai.is_omitted()] args = calculate_plateau_age(ages, errors, k39, options=options, excludes=excludes) if args: v, e, pidx = args if pidx[0] == pidx[1]: return self.plateau_steps = pidx self.plateau_steps_str = '{}-{}'.format(ALPHAS[pidx[0]], ALPHAS[pidx[1]]) step_idxs = [i for i in xrange(pidx[0], pidx[1] + 1) if not self.analyses[i].is_omitted()] self.nsteps = len(step_idxs) pages = [ages[i] for i in step_idxs] perrs = [errors[i] for i in step_idxs] mswd = calculate_mswd(pages, perrs) self.plateau_mswd_valid = validate_mswd(mswd, self.nsteps) self.plateau_mswd = mswd e = self._modify_error(v, e, self.plateau_age_error_kind, mswd=mswd, include_j_error=self.include_j_error_in_plateau) if math.isnan(e): e = 0 return ufloat(v, max(0, e))
def _get_plateau_age(self): ages, errors, k39 = self._get_steps() options = { 'nsteps': self.pc_nsteps, 'gas_fraction': self.pc_gas_fraction, 'force_steps': self.calculate_fixed_plateau_steps } args = calculate_plateau_age(ages, errors, k39, options=options) if args: v, e, pidx = args if pidx[0] == pidx[1]: return self.plateau_steps = pidx self.plateau_steps_str = '{}-{}'.format(ALPHAS[pidx[0]], ALPHAS[pidx[1]]) self.nsteps = (pidx[1] - pidx[0]) + 1 # print pidx pages, perrs = zip(*[(ages[i], errors[i]) for i in range(pidx[0], pidx[1])]) mswd = calculate_mswd(pages, perrs) self.plateau_mswd_valid = validate_mswd(mswd, self.nsteps) self.plateau_mswd = mswd e = self._modify_error( v, e, self.plateau_age_error_kind, mswd=mswd, include_j_error=self.include_j_error_in_plateau) if math.isnan(e): e = 0 return ufloat(v, max(0, e))
def attr_stats(self, attr): w, sd, sem, (vs, es) = self._calculate_weighted_mean(attr, error_kind='both') mi, ma, total_dev, mswd, valid_mswd = 0, 0, 0, 0, False if len(vs): mswd = calculate_mswd(vs, es, wm=w) valid_mswd = validate_mswd(mswd, self.nanalyses) mi = min(vs) ma = max(vs) total_dev = (ma - mi) / ma * 100 else: print('atafdsa', attr) return { 'mean': w, 'sd': sd, 'sem': sem, 'mswd': mswd, 'valid_mswd': valid_mswd, 'min': mi, 'max': ma, 'total_dev': total_dev }
def _get_plateau_age(self): ans = self.analyses v, e = 0, 0 self.plateau_steps = None self.plateau_steps_str = '' self.nsteps = 0 self.plateau_mswd = 0 self.plateau_mswd_valid = False if all((not isinstance(ai, InterpretedAgeGroup) for ai in ans)): if ans: ages = [ai.age for ai in ans] errors = [ai.age_err for ai in ans] k39 = [ nominal_value(ai.get_computed_value('k39')) for ai in ans ] options = { 'nsteps': self.plateau_nsteps, 'gas_fraction': self.plateau_gas_fraction, 'overlap_sigma': self.plateau_overlap_sigma, 'fixed_steps': self.fixed_steps } excludes = [i for i, ai in enumerate(ans) if ai.is_omitted()] args = calculate_plateau_age(ages, errors, k39, method=self.plateau_method, options=options, excludes=excludes) if args: v, e, pidx = args if pidx[0] == pidx[1]: return self.plateau_steps = pidx self.plateau_steps_str = '{}-{}'.format( alphas(pidx[0]), alphas(pidx[1])) step_idxs = [ i for i in range(pidx[0], pidx[1] + 1) if not ans[i].is_omitted() ] self.nsteps = len(step_idxs) pages = array([ages[i] for i in step_idxs]) perrs = array([errors[i] for i in step_idxs]) mswd = calculate_mswd(pages, perrs) self.plateau_mswd_valid = validate_mswd(mswd, self.nsteps) self.plateau_mswd = mswd if self.plateau_age_error_kind == SD: e = array(pages).std() else: e = self._modify_error(v, e, self.plateau_age_error_kind, mswd=mswd) if math.isnan(e): e = 0 a = ufloat(v, max(0, e)) self._apply_j_err(a, force=self.include_j_error_in_mean or self.include_j_error_in_plateau) return a
def mean_mswd(self): if len(self.clean_yserr): return calculate_mswd(self.clean_ys, self.clean_yserr)