//FIM MAIN FIM MAIN FIM MAIN FIM MAIN FIM MAIN FIM MAIn FIM MAIN FIM MAIN TPZMaterial *LerMaterial(char *filename) { ifstream input(filename); TPZFMatrix naxes(3,3); REAL ni1,ni2,h,E1,E2,G12,G13,G23,f; REAL n00,n01,n02,n10,n11,n12,n20,n21,n22; TPZVec<REAL> xf(6); int matindex; input >> matindex; input >> f >> h >> E1 >> E2 >> G12 >> G13 >> G23 >> ni1 >> ni2; input >> n00 >> n01 >> n02 >> n10 >> n11 >> n12 >> n20 >> n21 >> n22; input >> xf[0] >> xf[1] >> xf[2] >> xf[3] >> xf[4] >> xf[5]; naxes(0,0) = n00; naxes(0,1) = n01; naxes(0,2) = n02; naxes(1,0) = n10; naxes(1,1) = n11; naxes(1,2) = n12; naxes(2,0) = n20; naxes(2,1) = n21; naxes(2,2) = n22; return new TPZPlaca(matindex,h,f,E1,E2,ni1,ni2,G12,G13,G23,naxes,xf); }
double Hero::distance(const std::vector<double> &c1, const std::vector<double> &c2) { dbg(1) << "XXXX c1.size = " << c1.size() << " c2.size = " << c2.size(); dbg(1) << "XXXX c1 = " << c1; dbg(1) << "XXXX c2 = " << c2; // resize and pad with '1' to conform to naxis auto pix1 = c1; pix1.resize( naxes(), 1.0); auto pix2 = c2; pix2.resize( naxes(), 1.0); // if we don't have a frame, return cartesian distance if( m_ast.origWcsInfo == AST__NULL) { double sumSq = 0.0; for( int i = 0 ; i < naxes() ; i ++ ) { double diff = pix1[i] - pix2[i]; sumSq += diff * diff; } return sqrt( sumSq); } dbg(1) << "XXXX fpix1 = " << pix1; dbg(1) << "XXXX fpix2 = " << pix2; pix1 = fits2world( pix1); pix2 = fits2world( pix2); dbg(1) << "XXXX wpix1 = " << pix1; dbg(1) << "XXXX wpix2 = " << pix2; AstErrorGuard errGuard( this); AstGCGuard gcGuard; // call ast to figure out the distance double res = astDistance( m_ast.currWcsInfo, & pix1.front(), & pix2.front()); dbg(1) << "XXXX dist = " << res; astClearStatus; return res; }
QString Hero::formatWorldValue(double val, int axis) { if( m_ast.origWcsInfo == AST__NULL) { return QString::number( val); } if( axis >= naxes()) { LTHROW( QString( "formatWorldValue called with axis=%1 but naxes=%2").arg(axis).arg(naxes())); } // format the cursor QString res = astFormat( m_ast.currWcsInfo, axis + 1, val); return res; }
const std::vector<AxisInfo> & Hero::axesInfos() { if( int( m_axisInfos.size()) != naxes()) { warn() << "axes info size and naxes mismatch"; // return some default labels m_axisInfos.clear(); for( int i = 0 ; i < naxes() ; i ++ ) { AxisInfo info; info.label = QString('X' + i); info.symbol = QString('X' + i) + "_"; info.title = QString('X' + i) + " axis"; // default html versions will be the same as the raw versions info.htmlLabel = info.label; info.htmlSymbol = info.symbol; info.htmlUnit = info.unit; info.htmlTitle = info.title; m_axisInfos.push_back( info); } } return m_axisInfos; }
const std::vector<double> & Hero::fits2world(const std::vector<double> & p_pixel) { if( m_ast.origWcsInfo == AST__NULL) { m_pixel2wcsCache = p_pixel; m_pixel2wcsCache.resize( naxes(), 1.0); return m_pixel2wcsCache; } AstErrorGuard errGuard( this); AstGCGuard gcGuard; // resize and pad with '1' to conform to naxis auto pixel = p_pixel; pixel.resize( naxes(), 1.0); m_pixel2wcsCache.resize( naxes()); // do the conversion astTranN( m_ast.currWcsInfo, 1, naxes(), 1, & pixel.front(), 1, naxes(), 1, & m_pixel2wcsCache.front()); astClearStatus; return m_pixel2wcsCache; }
/***********************************************************************//** * @brief Print column information * * @param[in] chatter Chattiness. * @return String containing column information. * * @todo Format and cfitsio information is mainly for debugging. This could * be vanish in a more stable version of the code, or it could be compiled * in conditionally using a debug option. ***************************************************************************/ std::string GFitsImage::print(const GChatter& chatter) const { // Initialise result string std::string result; // Continue only if chatter is not silent if (chatter != SILENT) { // Append header result.append("=== GFitsImage ==="); // Append HDU information result.append("\n"+print_hdu(chatter)); // Append image dimensions result.append("\n"+gammalib::parformat("Image type")); result.append(typecode(type())); result.append("\n"+gammalib::parformat("Number of dimensions")); result.append(gammalib::str(naxis())); result.append("\n"+gammalib::parformat("Number of image pixels")); result.append(gammalib::str(npix())); for (int i = 0; i < naxis(); ++i) { result.append("\n"+gammalib::parformat("Number of bins in "+gammalib::str(i))); result.append(gammalib::str(naxes(i))); } // NORMAL: Append header information if (chatter >= NORMAL) { result.append(+"\n"+m_header.print(gammalib::reduce(chatter))); } } // endif: chatter was not silent // Return result return result; }
void Hero::parseAxesInfo() { m_axisInfos.clear(); m_labelsForAxes.clear(); for( int i = 1 ; i <= naxes() ; i ++ ) { AxisInfo info; info.label = AstWrappers::getC( m_ast.currWcsInfo, QString("Label(%1)").arg(i)); info.symbol = AstWrappers::getC( m_ast.currWcsInfo, QString("Symbol(%1)").arg(i)); info.unit = AstWrappers::getC( m_ast.currWcsInfo, QString("Unit(%1)").arg(i)); info.title = AstWrappers::getC( m_ast.currWcsInfo, QString("Title(%1)").arg(i)); info.setIsLongitude( AstWrappers::getI( m_ast.currWcsInfo, QString("IsLonAxis(%1)").arg(i))); astClearStatus; info.setIsLatitude( AstWrappers::getI( m_ast.currWcsInfo, QString("IsLatAxis(%1)").arg(i))); astClearStatus; // default html versions will be the same as the raw versions info.htmlLabel = info.label; info.htmlSymbol = info.symbol; info.htmlUnit = info.unit; info.htmlTitle = info.title; m_axisInfos.push_back( info); } for( auto v : m_axisInfos) { dbg(1) << "...label:" << v.label << " symbol:" << v.symbol << " unit:" << v.unit << " title:" << v.title; } // htmlize special cases for( AxisInfo & v : m_axisInfos) { // symbols if( v.symbol == "RA") { v.htmlSymbol = "α"; } else if( v.symbol == "Dec") { v.htmlSymbol = "δ"; } else if( v.symbol == "Lambda") { v.htmlSymbol = "λ"; } else if( v.symbol == "Beta") { v.htmlSymbol = "β"; } else if( v.symbol == "FREQ") { v.htmlSymbol = "Freq"; } else if( v.symbol == "STOKES") { v.htmlSymbol = "Stokes"; } // units if( v.unit == "degrees") { v.htmlUnit = "°"; } else if( v.unit == "hh:mm:ss.s") { v.htmlUnit = ""; } else if( v.unit == "ddd:mm:ss") { v.htmlUnit = ""; } } }
void FitsReader::initialize() { int status = 0; fits_open_file(&_fitsPtr, _filename.c_str(), READONLY, &status); checkStatus(status, _filename); // Move to first HDU int hduType; fits_movabs_hdu(_fitsPtr, 1, &hduType, &status); checkStatus(status, _filename); if(hduType != IMAGE_HDU) throw std::runtime_error("First HDU is not an image"); int naxis = 0; fits_get_img_dim(_fitsPtr, &naxis, &status); checkStatus(status, _filename); if(naxis < 2) throw std::runtime_error("NAxis in image < 2"); std::vector<long> naxes(naxis); fits_get_img_size(_fitsPtr, naxis, &naxes[0], &status); checkStatus(status, _filename); _imgWidth = naxes[0]; _imgHeight = naxes[1]; _nFrequencies = 1; std::string tmp; for(int i=2;i!=naxis;++i) { std::ostringstream name; name << "CTYPE" << (i+1); if(ReadStringKeyIfExists(name.str().c_str(), tmp)) { if(tmp == "FREQ" || tmp == "VRAD") _nFrequencies = naxes[i]; else if(naxes[i] != 1) throw std::runtime_error("Multiple images given in fits file"); } } if(_nFrequencies != 1 && !_allowMultiFreq) throw std::runtime_error("Multiple frequencies given in fits file"); double bScale = 1.0, bZero = 0.0, equinox = 2000.0; ReadDoubleKeyIfExists("BSCALE", bScale); ReadDoubleKeyIfExists("BZERO", bZero); ReadDoubleKeyIfExists("EQUINOX", equinox); if(bScale != 1.0) throw std::runtime_error("Invalid value for BSCALE"); if(bZero != 0.0) throw std::runtime_error("Invalid value for BZERO"); if(equinox != 2000.0) throw std::runtime_error("Invalid value for EQUINOX: "+readStringKey("EQUINOX")); if(ReadStringKeyIfExists("CTYPE1", tmp) && tmp != "RA---SIN" && _checkCType) throw std::runtime_error("Invalid value for CTYPE1"); _phaseCentreRA = 0.0; ReadDoubleKeyIfExists("CRVAL1", _phaseCentreRA); _phaseCentreRA *= M_PI / 180.0; _pixelSizeX = 0.0; ReadDoubleKeyIfExists("CDELT1", _pixelSizeX); _pixelSizeX *= -M_PI / 180.0; if(ReadStringKeyIfExists("CUNIT1", tmp) && tmp != "deg" && _checkCType) throw std::runtime_error("Invalid value for CUNIT1"); double centrePixelX = 0.0; if(ReadDoubleKeyIfExists("CRPIX1", centrePixelX)) _phaseCentreDL = (centrePixelX - ((_imgWidth / 2.0)+1.0)) * _pixelSizeX; else _phaseCentreDL = 0.0; if(ReadStringKeyIfExists("CTYPE2",tmp) && tmp != "DEC--SIN" && _checkCType) throw std::runtime_error("Invalid value for CTYPE2"); _phaseCentreDec = 0.0; ReadDoubleKeyIfExists("CRVAL2", _phaseCentreDec); _phaseCentreDec *= M_PI / 180.0; _pixelSizeY = 0.0; ReadDoubleKeyIfExists("CDELT2", _pixelSizeY); _pixelSizeY *= M_PI / 180.0; if(ReadStringKeyIfExists("CUNIT2", tmp) && tmp != "deg" && _checkCType) throw std::runtime_error("Invalid value for CUNIT2"); double centrePixelY = 0.0; if(ReadDoubleKeyIfExists("CRPIX2", centrePixelY)) _phaseCentreDM = ((_imgHeight / 2.0)+1.0 - centrePixelY) * _pixelSizeY; else _phaseCentreDM = 0.0; _dateObs = 0.0; readDateKeyIfExists("DATE-OBS", _dateObs); if(naxis >= 3 && readStringKey("CTYPE3") == "FREQ") { _frequency = readDoubleKey("CRVAL3"); _bandwidth = readDoubleKey("CDELT3"); } else { _frequency = 0.0; _bandwidth = 0.0; } if(naxis >= 4 && readStringKey("CTYPE4") == "STOKES") { double val = readDoubleKey("CRVAL4"); switch(int(val)) { default: throw std::runtime_error("Unknown polarization specified in fits file"); case 1: _polarization = Polarization::StokesI; break; case 2: _polarization = Polarization::StokesQ; break; case 3: _polarization = Polarization::StokesU; break; case 4: _polarization = Polarization::StokesV; break; case -1: _polarization = Polarization::RR; break; case -2: _polarization = Polarization::LL; break; case -3: _polarization = Polarization::RL; break; case -4: _polarization = Polarization::LR; break; case -5: _polarization = Polarization::XX; break; case -6: _polarization = Polarization::YY; break; case -7: _polarization = Polarization::XY; break; case -8: _polarization = Polarization::YX; break; } } else { _polarization = Polarization::StokesI; } double bMaj=0.0, bMin=0.0, bPa=0.0; if(ReadDoubleKeyIfExists("BMAJ", bMaj) && ReadDoubleKeyIfExists("BMIN", bMin) && ReadDoubleKeyIfExists("BPA", bPa)) { _hasBeam = true; _beamMajorAxisRad = bMaj * (M_PI / 180.0); _beamMinorAxisRad = bMin * (M_PI / 180.0); _beamPositionAngle = bPa * (M_PI / 180.0); } else { _hasBeam = false; _beamMajorAxisRad = 0.0; _beamMinorAxisRad = 0.0; _beamPositionAngle = 0.0; } _telescopeName = std::string(); ReadStringKeyIfExists("TELESCOP", _telescopeName); _observer = std::string(); ReadStringKeyIfExists("OBSERVER", _observer); _objectName = std::string(); ReadStringKeyIfExists("OBJECT", _objectName); _origin = std::string(); _originComment = std::string(); ReadStringKeyIfExists("ORIGIN", _origin, _originComment); _history.clear(); readHistory(); }