IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10617


Ignore:
Timestamp:
Dec 11, 2006, 6:55:26 AM (20 years ago)
Author:
magnier
Message:

defined coord transform tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/test/astrom/tap_pmAstrometryWCS_DVO.c

    r10615 r10617  
     1#ifdef HAVE_CONFIG_H
     2#include <config.h>
     3#endif
    14#include <stdio.h>
    25#include <string.h>
     
    1013    # include "dvo.h"
    1114
    12     psMetadata *WriteCoordsToHeader (Coords *coords)
     15    psMetadata *WriteCoordsToHeader (Coords *coords);
     16void test1(); // basic TAN projection,
     17void test2(); // small rotation
     18void test3(); // 2nd order term
     19
     20void testA(); // alloc test
     21void testB(); // alloc test
     22
     23int main (void)
     24{
     25    plan_tests(240);
     26
     27    diag("pmAstrometryWCS tests compared with DVO coords routines");
     28
     29    // test1();
     30    // test2();
     31    test3();
     32    return exit_status();
     33}
     34
     35void test3 ()
     36{
     37    diag("test pmAstromReadWCS");
     38    psMemId id = psMemGetId();
     39
     40    // build a DVO-style coordinate system
     41    Coords coords;
     42    strcpy (coords.ctype, "RA---TAN");
     43    coords.crval1 = 0.0;
     44    coords.crval2 = 0.0;
     45    coords.crpix1 = 0.0;
     46    coords.crpix2 = 0.0;
     47    coords.cdelt1 = 1.0/3600;
     48    coords.cdelt2 = 1.0/3600;
     49    coords.pc1_1  = 1.0;
     50    coords.pc1_2  = 0.0;
     51    coords.pc2_1  = 0.0;
     52    coords.pc2_2  = 1.0;
     53    coords.Npolyterms = 2;
     54    for (int i = 0; i < 7; i++) {
     55        coords.polyterms[i][0] = 0.0;
     56        coords.polyterms[i][1] = 0.0;
     57    }
     58    coords.polyterms[0][0] = 0.01; // L vs X^2
     59    coords.polyterms[2][1] = 0.01; // M vs Y^2
     60
     61    psMetadata *header = WriteCoordsToHeader (&coords);
     62    pmAstromWCS *wcs = pmAstromWCSfromHeader (header);
     63
     64    ok (wcs != NULL, "converted WCS keywords to WCS astrometry");
     65    skip_start (wcs == NULL, 1, "*** WCS Conversion FAILS *** : skipping related tests");
     66
     67    psSphere *sky = psSphereAlloc();
     68    psPlane *chip = psPlaneAlloc();
     69
     70    double rDVO, dDVO;
     71    for (double x = -2000; x <= +2000; x+= 500.0) {
     72        for (double y = -2000; y <= +2000; y+= 500.0) {
     73            XY_to_RD (&rDVO, &dDVO, x, y, &coords);
     74            chip->x = x;
     75            chip->y = y;
     76            pmAstromWCStoSky (sky, wcs, chip);
     77            while (sky->r > 2*M_PI)
     78                sky->r -= 2*M_PI;
     79            while (sky->r <      0)
     80                sky->r += 2*M_PI;
     81
     82            ok_float(rDVO, sky->r*PM_DEG_RAD, "coordinate match: %f vs %f (delta = %f)", rDVO, sky->r*PM_DEG_RAD, rDVO - sky->r*PM_DEG_RAD);
     83            ok_float(dDVO, sky->d*PM_DEG_RAD, "coordinate match: %f vs %f (delta = %f)", dDVO, sky->d*PM_DEG_RAD, dDVO - sky->d*PM_DEG_RAD);
     84        }
     85    }
     86    psFree (sky);
     87    psFree (chip);
     88
     89    skip_end();
     90    psFree (wcs);
     91    psFree (header);
     92
     93    ok(!psMemCheckLeaks (id, NULL, stderr, false), "no memory leaks");
     94}
     95
     96void test2 ()
     97{
     98    diag("test pmAstromReadWCS");
     99    psMemId id = psMemGetId();
     100
     101    // build a DVO-style coordinate system
     102    Coords coords;
     103    strcpy (coords.ctype, "RA---TAN");
     104    coords.crval1 = 0.0;
     105    coords.crval2 = 0.0;
     106    coords.crpix1 = 0.0;
     107    coords.crpix2 = 0.0;
     108    coords.cdelt1 = 1.0/3600;
     109    coords.cdelt2 = 1.0/3600;
     110    coords.pc1_1  = 0.9;
     111    coords.pc1_2  = -0.1;
     112    coords.pc2_1  = 0.1;
     113    coords.pc2_2  = 0.9;
     114    coords.Npolyterms = 0;
     115    for (int i = 0; i < 7; i++) {
     116        coords.polyterms[i][0] = 0.0;
     117        coords.polyterms[i][1] = 0.0;
     118    }
     119
     120    psMetadata *header = WriteCoordsToHeader (&coords);
     121    pmAstromWCS *wcs = pmAstromWCSfromHeader (header);
     122
     123    ok (wcs != NULL, "converted WCS keywords to WCS astrometry");
     124    skip_start (wcs == NULL, 1, "*** WCS Conversion FAILS *** : skipping related tests");
     125
     126    psSphere *sky = psSphereAlloc();
     127    psPlane *chip = psPlaneAlloc();
     128
     129    double rDVO, dDVO;
     130    for (double x = -2000; x <= +2000; x+= 500.0) {
     131        for (double y = -2000; y <= +2000; y+= 500.0) {
     132            XY_to_RD (&rDVO, &dDVO, x, y, &coords);
     133            chip->x = x;
     134            chip->y = y;
     135            pmAstromWCStoSky (sky, wcs, chip);
     136            while (sky->r > 2*M_PI)
     137                sky->r -= 2*M_PI;
     138            while (sky->r <      0)
     139                sky->r += 2*M_PI;
     140
     141            ok_float(rDVO, sky->r*PM_DEG_RAD, "coordinate match: %f vs %f (delta = %f)", rDVO, sky->r*PM_DEG_RAD, rDVO - sky->r*PM_DEG_RAD);
     142            ok_float(dDVO, sky->d*PM_DEG_RAD, "coordinate match: %f vs %f (delta = %f)", dDVO, sky->d*PM_DEG_RAD, dDVO - sky->d*PM_DEG_RAD);
     143        }
     144    }
     145    psFree (sky);
     146    psFree (chip);
     147
     148    skip_end();
     149    psFree (wcs);
     150    psFree (header);
     151
     152    ok(!psMemCheckLeaks (id, NULL, stderr, false), "no memory leaks");
     153}
     154
     155void test1()
     156{
     157    diag("test pmAstromReadWCS");
     158    psMemId id = psMemGetId();
     159
     160    // build a DVO-style coordinate system
     161    Coords coords;
     162    strcpy (coords.ctype, "RA---TAN");
     163    coords.crval1 = 0.0;
     164    coords.crval2 = 0.0;
     165    coords.crpix1 = 0.0;
     166    coords.crpix2 = 0.0;
     167    coords.cdelt1 = 1.0/3600;
     168    coords.cdelt2 = 1.0/3600;
     169    coords.pc1_1  = 1.0;
     170    coords.pc1_2  = 0.0;
     171    coords.pc2_1  = 0.0;
     172    coords.pc2_2  = 1.0;
     173    coords.Npolyterms = 0;
     174    for (int i = 0; i < 7; i++) {
     175        coords.polyterms[i][0] = 0.0;
     176        coords.polyterms[i][1] = 0.0;
     177    }
     178
     179    psMetadata *header = WriteCoordsToHeader (&coords);
     180    pmAstromWCS *wcs = pmAstromWCSfromHeader (header);
     181
     182    ok (wcs != NULL, "converted WCS keywords to WCS astrometry");
     183    skip_start (wcs == NULL, 1, "*** WCS Conversion FAILS *** : skipping related tests");
     184
     185    psSphere *sky = psSphereAlloc();
     186    psPlane *chip = psPlaneAlloc();
     187
     188    double rDVO, dDVO;
     189    for (double x = -2000; x <= +2000; x+= 500.0) {
     190        for (double y = -2000; y <= +2000; y+= 500.0) {
     191            XY_to_RD (&rDVO, &dDVO, x, y, &coords);
     192            chip->x = x;
     193            chip->y = y;
     194            pmAstromWCStoSky (sky, wcs, chip);
     195            while (sky->r > 2*M_PI)
     196                sky->r -= 2*M_PI;
     197            while (sky->r <      0)
     198                sky->r += 2*M_PI;
     199
     200            ok_float(rDVO, sky->r*PM_DEG_RAD, "coordinate match: %f vs %f (delta = %f)", rDVO, sky->r*PM_DEG_RAD, rDVO - sky->r*PM_DEG_RAD);
     201            ok_float(dDVO, sky->d*PM_DEG_RAD, "coordinate match: %f vs %f (delta = %f)", dDVO, sky->d*PM_DEG_RAD, dDVO - sky->d*PM_DEG_RAD);
     202        }
     203    }
     204    psFree (sky);
     205    psFree (chip);
     206
     207    skip_end();
     208    psFree (wcs);
     209    psFree (header);
     210
     211    ok(!psMemCheckLeaks (id, NULL, stderr, false), "no memory leaks");
     212}
     213
     214void testA()
     215{
     216    diag("test coord allocs");
     217    psMemId id = psMemGetId();
     218
     219    psPlane *chip = psPlaneAlloc();
     220    psFree (chip);
     221    ok(!psMemCheckLeaks (id, NULL, stderr, false), "no memory leaks");
     222}
     223
     224void testB()
     225{
     226    diag("test coord allocs");
     227    psMemId id = psMemGetId();
     228
     229    psSphere *sky = psSphereAlloc();
     230    psFree (sky);
     231    ok(!psMemCheckLeaks (id, NULL, stderr, false), "no memory leaks");
     232}
     233
     234psMetadata *WriteCoordsToHeader (Coords *coords)
    13235{
    14236
     
    18240    psMetadata *header = psMetadataAlloc();
    19241
    20     sprintf (name, "RA---", coords[0].ctype[4]);
     242    sprintf (name, "RA--%s", &coords[0].ctype[4]);
    21243    psMetadataAddStr (header, PS_LIST_TAIL, "CTYPE1", PS_META_REPLACE, "", name);
    22     sprintf (name, "DEC--", coords[0].ctype[4]);
     244    sprintf (name, "DEC-%s", &coords[0].ctype[4]);
    23245    psMetadataAddStr (header, PS_LIST_TAIL, "CTYPE2", PS_META_REPLACE, "", name);
    24246
     
    59281}
    60282
    61 int main (void)
    62 {
    63 
    64     pmModelGroupInit ();
    65 
    66     plan_tests(240);
    67 
    68     diag("pmAstrometryWCS tests compared with DVO coords routines");
    69 
    70     {
    71         diag("test pmAstromReadWCS");
    72         psMemId id = psMemGetId();
    73 
    74         // build a DVO-style coordinate system
    75         Coords coords;
    76         strcpy (coords.ctype, "RA---TAN");
    77         coords.crval1 = 0.0;
    78         coords.crval2 = 0.0;
    79         coords.crpix1 = 0.0;
    80         coords.crpix2 = 0.0;
    81         coords.cdelt1 = 1.0/3600;
    82         coords.cdelt2 = 1.0/3600;
    83         coords.pc1_1  = 1.0;
    84         coords.pc1_2  = 0.0;
    85         coords.pc2_1  = 0.0;
    86         coords.pc2_2  = 1.0;
    87         coords.Npolyterms = 0;
    88         for (int i = 0; i < 7; i++) {
    89             coords.polyterms[i][0] = 0.0;
    90             coords.polyterms[i][1] = 0.0;
    91         }
    92 
    93         psMetadata *header = WriteCoordsToHeader (&coords);
    94         pmAstromWCS *wcs = pmAstromWCSfromHeader (header);
    95         ok (wcs != NULL, "converted WCS keywords to WCS astrometry");
    96         skip_start (!status, 1, "*** WCS Conversion FAILS *** : skipping related tests");
    97 
    98         psSphere *sky = psSphereAlloc();
    99         psPlane *chip = psPlaneAlloc();
    100 
    101         for (double x = -2000, x <= +2000; x+= 500.0) {
    102             for (double y = -2000, y <= +2000; y+= 500.0) {
    103                 XY_to_RD (&rDVO, &dDVO, x, y, &coords);
    104                 chip->x = x;
    105                 chip->y = y;
    106                 pmAstromWCStoSky (sky, wcs, chip);
    107 
    108                 ok_float(rDVO, sky->r*PS_DEG_RAD, "coordinate match: %f vs %f (delta = %f)", rDVO, sky->r*PS_DEG_RAD, rDVO - sky->r*PS_DEG_RAD);
    109                 ok_float(dDVO, sky->d*PS_DEG_RAD, "coordinate match: %f vs %f (delta = %f)", dDVO, sky->d*PS_DEG_RAD, dDVO - sky->d*PS_DEG_RAD);
    110             }
    111         }
    112 
    113         psFree (sky);
    114         psFree (chip);
    115         psFree (wcs);
    116         psFree (header);
    117 
    118         skip_end();
    119         ok(!psMemCheckLeaks (id, NULL, stderr, false), "no memory leaks");
    120     }
     283# else
     284
     285    int main (void)
     286{
     287    plan_tests(0);
     288
     289    diag("pmAstrometryWCS tests compared with DVO coords routines : SKIPPED (libdvo not available)");
    121290
    122291    return exit_status();
    123292}
    124293
    125 # else
    126 
    127     int main (void)
    128 {
    129 
    130     pmModelGroupInit ();
    131 
    132     plan_tests(0);
    133 
    134     diag("pmAstrometryWCS tests compared with DVO coords routines : SKIPPED (libdvo not available)");
    135 
    136     return exit_status();
    137 }
    138 
    139294# endif
    140295
Note: See TracChangeset for help on using the changeset viewer.