/*************************************************************************** * @brief GSkymap_wcs_construct ***************************************************************************/ void TestGSky::test_GSkymap_wcs_construct(void) { // Set precision double eps = 1.0e-5; // Test void constructor test_try("Test void constructor"); try { GSkymap map; test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test non-Healpix constructors test_try("Test non-Healpix constructors"); try { GSkymap map1("CAR", "GAL", 0.0, 0.0, 1.0, 1.0, 100, 100); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test CAR projection test_try("Test CAR projection"); try { GSkymap map1("CAR", "GAL", 138.817, 37.293, 0.521, 0.931, 100, 100); GSkyDir dir; for (int l = -180; l < 180; ++l) { for (int b = -90; b < 90; ++b) { dir.lb_deg(double(l),double(b)); GSkyPixel pixel = map1.dir2pix(dir); GSkyDir dir_back = map1.pix2dir(pixel); double dist = dir.dist_deg(dir_back); if (dist > eps) { throw exception_failure("Sky direction differs: dir="+dir.print()+" pixel="+pixel.print()+" dir_back"+ dir_back.print()+" dist="+gammalib::str(dist)+" deg"); } } } test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Exit test return; }
/***********************************************************************//** * @brief Read model from XML element * * @param[in] xml XML element. * * @exception GException::model_invalid_parnum * Invalid number of model parameters found in XML element. * @exception GException::model_invalid_parnames * Invalid model parameter names found in XML element. * * Reads the elliptical source location and position angle information from * an XML element in the following format * * <spatialModel type="..."> * <parameter name="RA" scale="1" value="83.63" min="-360" max="360" free="1"/> * <parameter name="DEC" scale="1" value="22.01" min="-90" max="90" free="1"/> * <parameter name="PA" scale="1" value="45.0" min="-360" max="360" free="1"/> * ... * </spatialModel> * * or * * <spatialModel type="..."> * <parameter name="GLON" scale="1" value="83.63" min="-360" max="360" free="1"/> * <parameter name="GLAT" scale="1" value="22.01" min="-90" max="90" free="1"/> * <parameter name="PA" scale="1" value="45.0" min="-360" max="360" free="1"/> * ... * </spatialModel> * ***************************************************************************/ void GModelSpatialElliptical::read(const GXmlElement& xml) { // Read RA/DEC parameters if (gammalib::xml_has_par(xml, "RA") && gammalib::xml_has_par(xml, "DEC")) { // Get parameters const GXmlElement* ra = gammalib::xml_get_par(G_READ, xml, "RA"); const GXmlElement* dec = gammalib::xml_get_par(G_READ, xml, "DEC"); // Read parameters m_ra.read(*ra); m_dec.read(*dec); } // ... otherwise read GLON/GLAT parameters else { // Get parameters const GXmlElement* glon = gammalib::xml_get_par(G_READ, xml, "GLON"); const GXmlElement* glat = gammalib::xml_get_par(G_READ, xml, "GLAT"); // Read parameters m_ra.read(*glon); m_dec.read(*glat); // Convert into RA/DEC GSkyDir dir; dir.lb_deg(ra(), dec()), m_ra.value(dir.ra_deg()); m_dec.value(dir.dec_deg()); // Set names to RA/DEC m_ra.name("RA"); m_dec.name("DEC"); } // Get other parameters const GXmlElement* pa = gammalib::xml_get_par(G_READ, xml, m_posangle.name()); // Read other parameters m_posangle.read(*pa); // Return return; }
/***********************************************************************//** * @brief Read model from XML element * * @param[in] xml XML element. * * @exception GException::model_invalid_parnum * Invalid number of model parameters found in XML element. * @exception GException::model_invalid_parnames * Invalid model parameter names found in XML element. * * Reads the radial source location and position angle information from an * XML element in the following format * * <spatialModel type="..."> * <parameter name="RA" scale="1" value="83.63" min="-360" max="360" free="1"/> * <parameter name="DEC" scale="1" value="22.01" min="-90" max="90" free="1"/> * ... * </spatialModel> * * or * * <spatialModel type="..."> * <parameter name="GLON" scale="1" value="83.63" min="-360" max="360" free="1"/> * <parameter name="GLAT" scale="1" value="22.01" min="-90" max="90" free="1"/> * ... * </spatialModel> * ***************************************************************************/ void GModelSpatialRadial::read(const GXmlElement& xml) { // Determine number of parameter nodes in XML element int npars = xml.elements("parameter"); // Verify that XML element has at least 2 parameters if (xml.elements() < 2 || npars < 2) { throw GException::model_invalid_parnum(G_READ, xml, "Radial model requires at least 2 parameters."); } // Extract model parameters bool has_glon = false; bool has_glat = false; int npar[2] = {0, 0}; for (int i = 0; i < npars; ++i) { // Get parameter element const GXmlElement* par = xml.element("parameter", i); // Handle RA/GLON if (par->attribute("name") == "RA") { m_ra.read(*par); npar[0]++; } else if (par->attribute("name") == "GLON") { m_ra.read(*par); npar[0]++; has_glon = true; } // Handle DEC/GLAT else if (par->attribute("name") == "DEC") { m_dec.read(*par); npar[1]++; } else if (par->attribute("name") == "GLAT") { m_dec.read(*par); npar[1]++; has_glat = true; } } // endfor: looped over all parameters // Check if we have to convert GLON/GLAT into RA/DEC if (has_glon && has_glat) { GSkyDir dir; dir.lb_deg(ra(), dec()), m_ra.value(dir.ra_deg()); m_dec.value(dir.dec_deg()); } else if (has_glon || has_glat) { throw GException::model_invalid_parnames(G_READ, xml, "Require either \"RA\"/\"DEC\" or \"GLON\"/\"GLAT\"."); } // Verify that all parameters were found if (npar[0] != 1 || npar[1] != 1) { throw GException::model_invalid_parnames(G_READ, xml, "Require \"RA\"/\"DEC\" and \"GLON\"/\"GLAT\" parameters."); } // Return return; }