Estimate<double> Pulsar::FourierDomainFit::get_shift () const { Profile prfcopy = *observation; Reference::To<Profile> obs_p = &prfcopy; if (error_method=="mcmc") fit.set_error_method(ProfileShiftFit::MCMC_Variance); else if (error_method=="trad") fit.set_error_method(ProfileShiftFit::Traditional_Chi2); else if (error_method=="num") fit.set_error_method(ProfileShiftFit::Numerical); else throw Error (InvalidParam, "Pulsar::FourierDomainFit::get_shift", "Uncertainty method '" + error_method + "' not known"); fit.set_Profile(obs_p); fit.compute(); reduced_chisq = fit.get_reduced_chisq(); snr = fit.get_snr(); // Change shift range from 0->1 to -0.5->0.5 Estimate<double> result = fit.get_shift(); if (result.get_value() > 0.5) { result -= 1.0; } return result; }
Tempo::toa Pulsar::ArrivalTime::get_toa (Estimate<double>& shift, const Pulsar::Integration* subint, unsigned ichan) { Tempo::toa toa (format); // phase shift in turns toa.set_phase_shift (shift.get_value()); // topocentric folding period double period = subint->get_folding_period(); // epoch of the integration (rise time of bin 0 in each profile) MJD epoch = subint->get_epoch (); // arrival time toa.set_arrival (epoch + shift.get_value() * period); // arrival time error in microseconds toa.set_error (shift.get_error() * period * 1e6); if (subint->get_dedispersed()) toa.set_frequency (subint->get_centre_frequency()); else toa.set_frequency (subint->get_centre_frequency(ichan)); toa.set_channel (ichan); // would like to see this go somewhere else if (format == Tempo::toa::Parkes || format == Tempo::toa::Psrclock) toa.set_auxilliary_text( tostring(ichan) ); return toa; }
void Pulsar::LastHarmonic::build () { if (!profile) throw Error (InvalidState, "Pulsar::LastHarmonic::build", "Profile not set"); if (!baseline_estimator) throw Error (InvalidState, "Pulsar::LastHarmonic::build", "Baseline estimator not set"); Reference::To<PhaseWeight> baseline = baseline_estimator->baseline (profile); Estimate<double> mean = baseline->get_mean (); Estimate<double> var = baseline->get_variance (); Estimate<double> rms = sqrt(var); #ifdef _DEBUG cerr << "Pulsar::LastHarmonic::build mean=" << mean << " rms=" << rms << endl; #endif significant.find (profile, rms.get_value()); // skip the DC term bin_rise = 1; bin_fall = significant.get(); }
//------------------------------------------------------------------------------ void ChangeEstimateFinishedCommand::undo() { Estimate* estimate = root->find(estimateId); if (estimate) { estimate->setFinishedState(oldState); } }
//------------------------------------------------------------------------------ QVariant ImportedTransactionsModel::displayData(const QModelIndex& index) const { int row = index.row(); if (row < 0 || row >= transactions.size()) return QVariant(); ImportedTransaction transaction = transactions.at(row); uint id = transaction.transactionId(); switch (index.column()) { case TRN_ID_COL: return id; case EST_ID_COL: return assignments->estimate(id); case RULE_ID_COL: return assignments->rule(id); case DATE_COL: return transaction.date(); case PAYEE_COL: return transaction.payee(); case MEMO_COL: return transaction.memo(); case AMOUNT_COL: return transaction.amount().toString(); case WITHDRAWAL_COL: return transaction.withdrawalAccount(); case DEPOSIT_COL: return transaction.depositAccount(); case ESTIMATE_COL: { uint eid = assignments->estimate(id); // If transaction was assigned if (eid != 0) { Estimate* estimate = estimates->find(eid); if (estimate) { return estimate->estimateName(); } } return QVariant(); } default: return QVariant(); } }
void SumToOne::DoBuild() { LOG_TRACE(); for (auto& estimate_label : estimate_labels_) { Estimate* estimate = model_->managers().estimate()->GetEstimateByLabel(estimate_label); if (estimate == nullptr) { LOG_ERROR_P(PARAM_ESTIMATE_LABELS) << "Estimate " << estimate_label << " could not be found. Have you defined it?"; return; } else { LOG_FINE() << "transform with objective = " << transform_with_jacobian_ << " estimate transform " << estimate->transform_for_objective() << " together = " << !transform_with_jacobian_ && !estimate->transform_for_objective(); if (!transform_with_jacobian_ && !estimate->transform_for_objective()) { LOG_ERROR_P(PARAM_LABEL) << "You have specified a transformation that does not contribute a jacobian, and the prior parameters do not refer to the transformed estimate, in the @estimate" << estimate_label_ << ". This is not advised, and may cause bias estimation. Please address the user manual if you need help"; } if (estimate->transform_with_jacobian_is_defined()) { if (transform_with_jacobian_ != estimate->transform_with_jacobian()) { LOG_ERROR_P(PARAM_LABEL) << "This parameter is not consistent with the equivalent parameter in the @estimate block " << estimate_label_ << ". please make sure these are both true or both false."; } } estimates_.push_back(estimate); } } // Validate that the parameters sum to one. Double total = 0.0; for (auto& estimate : estimates_) { LOG_FINEST() << "transformation value = " << estimate->value(); total += estimate->value(); } if (total != 1.0) LOG_ERROR_P(PARAM_ESTIMATE_LABELS) << "The estiamtes you supplied to not sum to 1.0, they sum to " << total << ", please check initial values of these parameters"; // Check that the bounds are sensible if (parameters_.Get(PARAM_UPPER_BOUND)->has_been_defined() & parameters_.Get(PARAM_LOWER_BOUND)->has_been_defined()) { for (unsigned i = 0; i < estimates_.size(); ++i) { if (estimates_[i]->lower_bound() < 0.0 || estimates_[i]->lower_bound() > 1.0) LOG_ERROR_P(PARAM_LOWER_BOUND) << "You cannot specify a lower bound less than 0 and greater than 1.0"; if (estimates_[i]->upper_bound() < 0.0 || estimates_[i]->upper_bound() > 1.0) LOG_ERROR_P(PARAM_UPPER_BOUND) << "You cannot specify a upper bound less than 0 and greater than 1.0"; } } LOG_MEDIUM() << "total = " << total; // Turn off the last estimate LOG_FINE() << "Turning off parameter, this won't be estimated, and will be an outcome of other parameters " << estimates_[estimates_.size() - 1]->parameter() << " in the estimation"; estimates_[estimates_.size() - 1]->set_estimated(false); LOG_MEDIUM() << "flagged estimated = " << estimates_[estimates_.size() - 1]->estimated(); }
void FluxCalibrator::VariableGain::compute (unsigned ireceptor, Estimate<double>& S_cal, Estimate<double>& S_sys) { if (calculated) return; if (mean_ratio_on.size() <= ireceptor) throw Error (InvalidState, "FluxCalibrator::VariableGain::calculate", "no on-source observations available"); if (mean_ratio_off.size() <= ireceptor) throw Error (InvalidState, "FluxCalibrator::VariableGain::calculate", "no off-source observations available"); // the flux density of the standard candle in each polarization double S_std_i = S_std / 2; valid = true; Estimate<double> on = mean_ratio_on[ireceptor].get_Estimate(); Estimate<double> off = mean_ratio_off[ireceptor].get_Estimate(); if (on==0 || off==0) { S_cal = S_sys = 0; valid = false; return; } ratio_on.set_value (on); ratio_off.set_value (off); S_sys = S_std_i * flux_sys.get_Estimate(); S_cal = S_std_i * flux_cal.get_Estimate(); if (S_cal.val < S_cal.get_error() || S_sys.val < S_sys.get_error() ) { S_cal = S_sys = 0; valid = false; } }
Estimate recip(const Estimate &arg) { if (!arg.IsNonZero()) throw PrecisionException("recip"); LongFloat r(arg.m_Value.recip()); ErrorEstimate e(arg.m_Value, ErrorEstimate::Down); ErrorEstimate re(RoundingError(r, r.DivisionRoundingError())); return Estimate(r, (arg.m_Error / (e - arg.m_Error) / e) + re); // multiplication in denominator would have the wrong rounding mode }
void Pulsar::ComponentModel::align (const Profile *profile) { Profile modelprof(*profile); evaluate (modelprof.get_amps(), modelprof.get_nbin()); Estimate<double> shift = profile->shift (modelprof); if (verbose) cerr << "Pulsar::ComponentModel::align shift=" << shift << endl; if (phase) { float normalization = profile->sum() / modelprof.sum(); if (verbose) cerr << "Pulsar::ComponentModel::align normalization=" << normalization << endl; for (unsigned icomp=0; icomp < components.size(); icomp++) { Estimate<double> height = components[icomp]->get_height(); components[icomp]->set_height ( height * normalization ); } phase->set_value (phase->get_value() + shift.get_value() * 2*M_PI); return; } // Dick requires this cout << setprecision(6) << fixed << "Shift= " << shift.val << endl; for (unsigned icomp=0; icomp < components.size(); icomp++) { Estimate<double> centre = components[icomp]->get_centre() + shift * 2*M_PI; if (centre.val >= M_PI) centre -= 2*M_PI; if (centre.val < -M_PI) centre += 2*M_PI; components[icomp]->set_centre(centre); } }
Estimate operator / (const Estimate &lhs, const Estimate &rhs) { if (!rhs.IsNonZero()) throw PrecisionException("division"); // this also assures e - rhs.m_Error > 0 LongFloat r(lhs.m_Value / rhs.m_Value); ErrorEstimate e(rhs.m_Value, ErrorEstimate::Down); ErrorEstimate n(ErrorEstimate(lhs.m_Value) * rhs.m_Error + ErrorEstimate(rhs.m_Value, ErrorEstimate::Up) * lhs.m_Error); return Estimate(r, n / (e - rhs.m_Error) / e + RoundingError(r, r.DivisionRoundingError())); // multiplication in denominator would have the wrong rounding mode }
//! Set the Stokes parameters of the model void MEAL::ModeCoherency::set_stokes (const Stokes<Estimate<double> >& stokes) { if (stokes[0].get_value() <= 0.0) throw Error (InvalidParam, "MEAL::ModeCoherency::set_stokes", "total intensity I=%lf <= 0", stokes[0].get_value()); Estimate<double> p = stokes.abs_vect() / stokes[0]; if (p.get_value() >= 1) throw Error (InvalidParam, "MEAL::ModeCoherency::set_stokes", "degree of polarization p=%lf >= 1", p.get_value()); if (p.get_value() == 0.0) throw Error (InvalidParam, "MEAL::ModeCoherency::set_stokes", "degree of polarization p==0"); log_intensity->set_value ( log( 0.5 * stokes[0] * sqrt(1-p*p) ) ); log_beta->set_value ( log(atanh(p)) ); axis->set_vector (stokes.get_vector()); }
/* returns the phase shift and scale that aligns the profile with the model */ void Pulsar::ComponentModel::get_best_alignment (const Profile* profile, double& the_phase, double& the_scale) { Profile modelprof (profile->get_nbin()); if (verbose) cerr << "Pulsar::ComponentModel::get_best_alignment calling evaluate" << endl; evaluate (modelprof.get_amps(), modelprof.get_nbin()); Estimate<double> shift = profile->shift (modelprof); if (verbose) cerr << "Pulsar::ComponentModel::get_best_alignment shift=" << shift << endl; the_phase = shift.get_value(); the_scale = profile->sum() / modelprof.sum(); if (verbose) cerr << "Pulsar::ComponentModel::get_best_alignment scale=" << the_scale << endl; }
void psrflux::process (Pulsar::Archive* archive) { // Convert to total intensity archive->convert_state(Signal::Intensity); // Set self-standard if needed if (stdfile=="") set_standard(archive); // Test for single-profile data bool single_profile = archive->get_nsubint()==1 && archive->get_nchan()==1; // Access to the flux computation StandardFlux *flux = dynamic_cast<StandardFlux*>(ds.get_flux_method().get()); // If shifts not fit, need to dedisperse and possibly align total // with standard. if (noalign) { archive->dedisperse(); flux->set_fit_shift(false); } else if (align==false && single_profile==false) { archive->dedisperse(); Reference::To<Archive> arch_tot = archive->total(); Estimate<double> shift = arch_tot->get_Profile(0,0,0)->shift(stdarch->get_Profile(0,0,0)); stdarch->get_Profile(0,0,0)->rotate_phase(-1.0*shift.get_value()); flux->set_fit_shift(false); } else { flux->set_fit_shift(true); } // Compute DS ds.set_Archive(archive); ds.compute(); // Unload archive with .sm extension std::string outf = archive->get_filename() + "." + ext; cerr << "psrflux: unloading " << outf << endl; ds.unload(outf, command); }
//------------------------------------------------------------------------------ void EstimateDetailsForm::populate(const QModelIndex& index) { Estimate* estimate = static_cast<Estimate*>(index.internalPointer()); // Populate fields with selected estimate's values nameField->setText(estimate->estimateName()); descriptionField->setText(estimate->estimateDescription()); typeField->setCurrentIndex(typeField->findData(estimate->estimateType())); amountField->setValue(estimate->estimatedAmount()); finishedField->setChecked(estimate->isActivityFinished()); int offset = estimate->activityDueDateOffset(); QDate dueDate = period->startDate().addDays(offset); if (dueDate.isNull()) { clearDueDate(); } else { dueDateField->setDate(dueDate); } // Enable fields that are applicable for all non-root estimates nameField->setEnabled(estimate->parentEstimate()); descriptionField->setEnabled(estimate->parentEstimate()); // Disable fields that aren't applicable for parents amountField->setEnabled(estimate->childCount() == 0); dueDateField->setEnabled(estimate->childCount() == 0); clearDueDateButton->setEnabled(estimate->childCount() == 0); finishedField->setEnabled(estimate->childCount() == 0); // Type can only be changed at top-level estimates Estimate* parent = estimate->parentEstimate(); if ( ! parent) // Parent is root { typeField->setEnabled(false); } else if ( ! parent->parentEstimate()) // Parent of parent is root { typeField->setEnabled(true); } else // Not top-level { typeField->setEnabled(false); } // Clear fields that aren't applicable for parents if (estimate->childCount() != 0) { amountField->clear(); clearDueDate(); finishedField->setChecked(false); } }