tmv::SymMatrix<double, tmv::FortranStyle|tmv::Upper> calculateCovarianceSymMatrix( const SBProfile& sbp, const Bounds<int>& bounds, double dx) { // Calculate the required dimensions int idim = 1 + bounds.getXMax() - bounds.getXMin(); int jdim = 1 + bounds.getYMax() - bounds.getYMin(); int covdim = idim * jdim; int k, ell; // k and l are indices that refer to image pixel separation vectors in the // correlation func. double x_k, y_ell; // physical vector separations in the correlation func, dx * k etc. tmv::SymMatrix<double, tmv::FortranStyle|tmv::Upper> cov = tmv::SymMatrix< double, tmv::FortranStyle|tmv::Upper>(covdim); for (int i=1; i<=covdim; i++){ // note that the Image indices use the FITS convention and // start from 1!! for (int j=i; j<=covdim; j++){ k = ((j - 1) / jdim) - ((i - 1) / idim); // using integer division rules here ell = ((j - 1) % jdim) - ((i - 1) % idim); x_k = double(k) * dx; y_ell = double(ell) * dx; Position<double> p = Position<double>(x_k, y_ell); cov(i, j) = sbp.xValue(p); // fill in the upper triangle with the correct value } } return cov; }
std::string MakeErrorMessage(const int x, const int y, const Bounds<int> b) { std::ostringstream oss(" "); bool found=false; if (x<b.getXMin() || x>b.getXMax()) { oss << "Attempt to access column number "<<x << ", range is "<<b.getXMin()<<" to "<<b.getXMax(); found = true; } if (y<b.getYMin() || y>b.getYMax()) { if (found) oss << " and "; oss << "Attempt to access row number "<<y << ", range is "<<b.getYMin()<<" to "<<b.getYMax(); found = true; } if (!found) return "Cannot find bounds violation ???"; else return oss.str(); }
ImageView<T> ImageView<T>::subImage(const Bounds<int>& bounds) const { if (!this->_data) throw ImageError("Attempt to make subImage of an undefined image"); if (!this->_bounds.includes(bounds)) { FormatAndThrow<ImageError>() << "Subimage bounds (" << bounds << ") are outside original image bounds (" << this->_bounds << ")"; } T* newdata = this->_data + (bounds.getYMin() - this->_bounds.getYMin()) * this->_stride + (bounds.getXMin() - this->_bounds.getXMin()); return ImageView<T>(newdata,this->_owner,this->_stride,bounds,this->_scale); }
/* * Covariance matrix calculation using the input SBProfile, the dimensions of the image for * which a covariance matrix is desired (in the form of a Bounds), and a scale dx */ ImageAlloc<double> calculateCovarianceMatrix( const SBProfile& sbp, const Bounds<int>& bounds, double dx) { // Calculate the required dimensions of the image for which a covariance matrix is needed int idim = 1 + bounds.getXMax() - bounds.getXMin(); int jdim = 1 + bounds.getYMax() - bounds.getYMin(); int covdim = idim * jdim; tmv::SymMatrix<double, tmv::FortranStyle|tmv::Upper> symcov = calculateCovarianceSymMatrix(sbp, bounds, dx); ImageAlloc<double> cov = ImageAlloc<double>(covdim, covdim, 0.); for (int i=1; i<=covdim; i++){ // note that the Image indices use the FITS convention and // start from 1!! for (int j=i; j<=covdim; j++){ cov.setValue(i, j, symcov(i, j)); // fill in the upper triangle with the // correct CorrFunc value } } return cov; }