IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 29, 2005, 5:44:55 PM (21 years ago)
Author:
eugene
Message:

various psphot updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/output.c

    r4641 r4901  
    33// output functions: we have several fixed modes (sx, obj, cmp)
    44
     5static int GetDophotType (psSource *source) {
     6
     7    switch (source->type) {
     8
     9      case PS_SOURCE_DEFECT:
     10      case PS_SOURCE_SATURATED:
     11        return (8);
     12
     13      case PS_SOURCE_SATSTAR:
     14        return (10);
     15
     16      case PS_SOURCE_PSFSTAR:
     17      case PS_SOURCE_GOODSTAR:
     18        return (1);
     19
     20      case PS_SOURCE_POOR_FIT_PSF:
     21        return (7);
     22
     23      case PS_SOURCE_FAIL_FIT_PSF:
     24      case PS_SOURCE_FAINTSTAR:
     25        return (4);
     26
     27      case PS_SOURCE_GALAXY:
     28      case PS_SOURCE_FAINT_GALAXY:
     29      case PS_SOURCE_DROP_GALAXY:
     30      case PS_SOURCE_FAIL_FIT_GAL:
     31      case PS_SOURCE_POOR_FIT_GAL:
     32        return (2);
     33
     34      case PS_SOURCE_OTHER:
     35      default:
     36        return (0);
     37    }
     38    return (0);
     39}
     40
    541void output (psImageData *imdata, psMetadata *config, psArray *sources) {
    642
    7   char *outputMode = psMetadataLookupPtr (&status, config, "OUTPUT_MODE");
    8 
    9   if (outputMode == NULL) {
    10     WriteSourcesText (imdata, config, sources);
     43    bool status;
     44
     45    char *outputMode = psMetadataLookupPtr (&status, config, "OUTPUT_MODE");
     46
     47    if (outputMode == NULL) {
     48        WriteSourcesText (imdata, config, sources);
     49        exit (0);
     50    }
     51
     52    if (!strcasecmp (outputMode, "OBJ")) {
     53        WriteSourcesOBJ (imdata, config, sources);
     54        exit (0);
     55    }
     56 
     57    if (!strcasecmp (outputMode, "SX")) {
     58        WriteSourcesSX (imdata, config, sources);
     59        exit (0);
     60    }
     61 
     62    if (!strcasecmp (outputMode, "CMP")) {
     63        WriteSourcesCMP (imdata, config, sources);
     64        exit (0);
     65    }
     66 
     67    if (!strcasecmp (outputMode, "CMF")) {
     68        WriteSourcesCMF (imdata, config, sources);
     69        exit (0);
     70    }
     71 
     72    psAbort ("psphot", "unknown output mode %s", outputMode);
     73}
     74
     75bool WriteSourcesText (psImageData *imdata, psMetadata *config, psArray *sources) {
     76
     77    bool status;
     78
     79    char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
     80
     81    DumpImage (imdata->image, filename);
     82
     83    // get these names from config?
     84    DumpModelPSF (sources, "psfsources.dat");
     85    DumpModelFLT (sources, "fltsources.dat");
     86    DumpModelNULL (sources, "nullsources.dat");
     87    DumpMoments (sources, "moments.dat");
     88
    1189    exit (0);
    12   }
    13 
    14   if (!strcasecmp (outputMode, "OBJ")) {
    15     WriteSourcesOBJ (imdata, config, sources);
    16     exit (0);
    17   }
    18  
    19   if (!strcasecmp (outputMode, "SX")) {
    20     WriteSourcesSX (imdata, config, sources);
    21     exit (0);
    22   }
    23  
    24   if (!strcasecmp (outputMode, "CMP")) {
    25     WriteSourcesCMP (imdata, config, sources);
    26     exit (0);
    27   }
    28  
    29   if (!strcasecmp (outputMode, "CMF")) {
    30     WriteSourcesCMF (imdata, config, sources);
    31     exit (0);
    32   }
    33  
    34   psAbort ("psphot", "unknown output mode %s", outputMode);
    35 }
    36 
    37 bool WriteSourceText (psImageData *imdata, psMetadata *config, psArray *sources) {
    38 
    39   char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
    40 
    41   DumpImage (imdata->image, filename);
    42 
    43   // get these names from config?
    44   DumpModelPSF (sources, "psfsources.dat");
    45   DumpModelFLT (sources, "fltsources.dat");
    46   DumpModelNULL (sources, "nullsources.dat");
    47   DumpMoments (sources, "moments.dat");
    48 
    49   exit (0);
    5090}
    5191
     
    5393bool WriteSourcesOBJ (psImageData *imdata, psMetadata *config, psArray *sources) {
    5494
    55 # define NCHAR 104
    56 
    57     char line[NCHAR];
    58 
    59     char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
     95    int i, type;
     96    bool status;
     97    psModel *model;
     98    psF32 *PAR, *dPAR;
     99    float dmag, apMag, fitMag;
     100
     101    char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
     102    psLine *line = psLineAlloc (104);  // 104 is dophot-defined line length
     103
     104    FILE *f = fopen (filename, "w");
     105    if (f == NULL) {
     106        psLogMsg ("WriteSourceOBJ", 3, "can't open output file for output %s\n", filename);
     107        return false;
     108    }
     109
     110    // write sources with models first
     111    for (i = 0; i < sources->n; i++) {
     112        psSource *source = (psSource *) sources->data[i];
     113        model = source->modelPSF;
     114        if (model == NULL) continue;
     115        PAR = model->params->data.F32;
     116        dPAR = model->dparams->data.F32;
     117
     118        pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask);
     119        dmag = dPAR[1] / PAR[1];
     120
     121        type = GetDophotType (source);
     122        psLineInit (line);
     123        psLineAdd (line, "%3d", type);
     124        psLineAdd (line, "%8.2f", PAR[2]);
     125        psLineAdd (line, "%8.2f", PAR[3]);
     126        psLineAdd (line, "%8.3f", fitMag);
     127        psLineAdd (line, "%6.3f", dmag);
     128        psLineAdd (line, "%9.2f", PAR[0]);
     129        psLineAdd (line, "%9.3f", PAR[4]);
     130        psLineAdd (line, "%9.3f", PAR[5]);
     131        psLineAdd (line, "%7.2f", PAR[6]);
     132        psLineAdd (line, "%8.3f", 32.0);
     133        psLineAdd (line, "%8.3f", apMag);
     134        psLineAdd (line, "%8.2f", apMag - fitMag);
     135        fwrite (line->line, 1, line->Nline, f);
     136    }
     137    fclose (f);
     138    return true;
     139
     140}
     141
     142// elixir/sextractor-style output list with fixed line width
     143bool WriteSourcesSX (psImageData *imdata, psMetadata *config, psArray *sources) {
     144
     145    int i, type;
     146    bool status;
     147    psModel *model;
     148    psF32 *PAR, *dPAR;
     149    float dmag, apMag, fitMag;
     150
     151    char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
     152    psLine *line = psLineAlloc (104);  // 104 is dophot-defined line length
    60153
    61154    FILE *f = fopen (filename, "w");
     
    70163        model = (psModel  *) source->modelPSF;
    71164        if (model == NULL) continue;
    72         params = model->params;
    73         dparams = model->dparams;
     165        PAR = model->params->data.F32;
     166        dPAR = model->dparams->data.F32;
    74167
    75168        pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask);
    76         dmag = dparams[0].data.F32[1] / params[0].data.F32[1];
    77 
     169        dmag = dPAR[1] / PAR[1];
     170
     171        // XXX EAM : fix this to match sextractor output
    78172        type = GetDophotType (source);
    79         init_line (line, &Nline);
    80         add_to_line (line, &Nline, "%3d", type);
    81         add_to_line (line, &Nline, "%8.2f", params[0].data.F32[2]);
    82         add_to_line (line, &Nline, "%8.2f", params[0].data.F32[3]);
    83         add_to_line (line, &Nline, "%8.3f", fitMag);
    84         add_to_line (line, &Nline, "%6.3f", dmag);
    85         add_to_line (line, &Nline, "%9.2f", params[0].data.F32[0]);
    86         add_to_line (line, &Nline, "%9.3f", params[0].data.F32[4]);
    87         add_to_line (line, &Nline, "%9.3f", params[0].data.F32[5]);
    88         add_to_line (line, &Nline, "%7.2f", params[0].data.F32[6]);
    89         add_to_line (line, &Nline, "%8.3f", 32.0);
    90         add_to_line (line, &Nline, "%8.3f", apMag);
    91         add_to_line (line, &Nline, "%8.2f", apMag - fitMag);
     173        psLineInit (line);
     174        psLineAdd (line, "%3d", type);
     175        psLineAdd (line, "%8.2f", PAR[2]);
     176        psLineAdd (line, "%8.2f", PAR[3]);
     177        psLineAdd (line, "%8.3f", fitMag);
     178        psLineAdd (line, "%6.3f", dmag);
     179        psLineAdd (line, "%9.2f", PAR[0]);
     180        psLineAdd (line, "%9.3f", PAR[4]);
     181        psLineAdd (line, "%9.3f", PAR[5]);
     182        psLineAdd (line, "%7.2f", PAR[6]);
     183        psLineAdd (line, "%8.3f", 32.0);
     184        psLineAdd (line, "%8.3f", apMag);
     185        psLineAdd (line, "%8.2f", apMag - fitMag);
     186        fwrite (line->line, 1, line->Nline, f);
    92187    }
    93188    fclose (f);
    94189    return true;
    95 
    96 }
    97 
    98 // elixir/sextractor-style output list with fixed line width
    99 bool WriteSourcesSX (psImageData *imdata, psMetadata *config, psArray *sources) {
    100 
    101 # define NCHAR 104
    102 
    103     char line[NCHAR];
    104 
    105     char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
     190}
     191
     192// elixir-style pseudo FITS table (header + ascii list)
     193bool WriteSourcesCMP (psImageData *imdata, psMetadata *config, psArray *sources) {
     194
     195    int i, type;
     196    bool status;
     197    psModel *model;
     198    psF32 *PAR, *dPAR;
     199    float dmag, apMag, fitMag;
     200
     201    char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
     202    psLine *line = psLineAlloc (104);  // 104 is dophot-defined line length
    106203
    107204    FILE *f = fopen (filename, "w");
     
    110207        return false;
    111208    }
     209
     210    // write imdata->header to file
    112211
    113212    // write sources with models first
     
    116215        model = (psModel  *) source->modelPSF;
    117216        if (model == NULL) continue;
    118         params = model->params;
    119         dparams = model->dparams;
     217        PAR = model->params->data.F32;
     218        dPAR = model->dparams->data.F32;
    120219
    121220        pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask);
    122         dmag = dparams[0].data.F32[1] / params[0].data.F32[1];
     221        dmag = dPAR[1] / PAR[1];
    123222
    124223        // XXX EAM : fix this to match sextractor output
    125224        type = GetDophotType (source);
    126         init_line (line, &Nline);
    127         add_to_line (line, &Nline, "%3d", type);
    128         add_to_line (line, &Nline, "%8.2f", params[0].data.F32[2]);
    129         add_to_line (line, &Nline, "%8.2f", params[0].data.F32[3]);
    130         add_to_line (line, &Nline, "%8.3f", fitMag);
    131         add_to_line (line, &Nline, "%6.3f", dmag);
    132         add_to_line (line, &Nline, "%9.2f", params[0].data.F32[0]);
    133         add_to_line (line, &Nline, "%9.3f", params[0].data.F32[4]);
    134         add_to_line (line, &Nline, "%9.3f", params[0].data.F32[5]);
    135         add_to_line (line, &Nline, "%7.2f", params[0].data.F32[6]);
    136         add_to_line (line, &Nline, "%8.3f", 32.0);
    137         add_to_line (line, &Nline, "%8.3f", apMag);
    138         add_to_line (line, &Nline, "%8.2f", apMag - fitMag);
    139     }
    140     fclose (f);
    141     return true;
    142 
    143 }
    144 
    145 // elixir-style pseudo FITS table (header + ascii list)
    146 bool WriteSourcesCMP (psImageData *imdata, psMetadata *config, psArray *sources) {
    147 
    148 
    149 # define NCHAR 104
    150 
    151     char line[NCHAR];
    152 
    153     char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
    154 
    155     FILE *f = fopen (filename, "w");
    156     if (f == NULL) {
    157         psLogMsg ("WriteSourceOBJ", 3, "can't open output file for output %s\n", filename);
    158         return false;
    159     }
    160 
    161     // write imdata->header to file
    162 
    163     // write sources with models first
    164     for (i = 0; i < sources->n; i++) {
    165         psSource *source = (psSource *) sources->data[i];
    166         model = (psModel  *) source->modelPSF;
    167         if (model == NULL) continue;
    168         params = model->params;
    169         dparams = model->dparams;
    170 
    171         pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask);
    172         dmag = dparams[0].data.F32[1] / params[0].data.F32[1];
    173 
    174         // XXX EAM : fix this to match sextractor output
    175         type = GetDophotType (source);
    176         init_line (line, &Nline);
    177         add_to_line (line, &Nline, "%3d", type);
    178         add_to_line (line, &Nline, "%8.2f", params[0].data.F32[2]);
    179         add_to_line (line, &Nline, "%8.2f", params[0].data.F32[3]);
    180         add_to_line (line, &Nline, "%8.3f", fitMag);
    181         add_to_line (line, &Nline, "%6.3f", dmag);
    182         add_to_line (line, &Nline, "%9.2f", params[0].data.F32[0]);
    183         add_to_line (line, &Nline, "%9.3f", params[0].data.F32[4]);
    184         add_to_line (line, &Nline, "%9.3f", params[0].data.F32[5]);
    185         add_to_line (line, &Nline, "%7.2f", params[0].data.F32[6]);
    186         add_to_line (line, &Nline, "%8.3f", 32.0);
    187         add_to_line (line, &Nline, "%8.3f", apMag);
    188         add_to_line (line, &Nline, "%8.2f", apMag - fitMag);
     225        psLineInit (line);
     226        psLineAdd (line, "%3d", type);
     227        psLineAdd (line, "%8.2f", PAR[2]);
     228        psLineAdd (line, "%8.2f", PAR[3]);
     229        psLineAdd (line, "%8.3f", fitMag);
     230        psLineAdd (line, "%6.3f", dmag);
     231        psLineAdd (line, "%9.2f", PAR[0]);
     232        psLineAdd (line, "%9.3f", PAR[4]);
     233        psLineAdd (line, "%9.3f", PAR[5]);
     234        psLineAdd (line, "%7.2f", PAR[6]);
     235        psLineAdd (line, "%8.3f", 32.0);
     236        psLineAdd (line, "%8.3f", apMag);
     237        psLineAdd (line, "%8.2f", apMag - fitMag);
     238        fwrite (line->line, 1, line->Nline, f);
    189239    }
    190240    fclose (f);
     
    195245bool WriteSourcesCMF (psImageData *imdata, psMetadata *config, psArray *sources) {
    196246
     247    bool status;
     248
    197249    char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");
    198250
     
    200252
    201253    // write FITS table to file (use autocode tools)
    202 }
    203 
    204 // we require a fixed number of chars already allocated
    205 init_line (char *line, int *Nline) {
    206   *Nline = 0;
    207 }
    208 
    209 add_to_line (char *line, int *Nline, char *format, ...) {
    210 
    211     va_list ap;
    212 
    213     va_start (ap, format);
    214     Nchar = vsprintf (&line[*Nline], format, ap);
    215     *Nline += Nchar;
    216 }
    217 
     254
     255    return true;
     256}
Note: See TracChangeset for help on using the changeset viewer.