IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 8, 2006, 5:14:23 PM (20 years ago)
Author:
magnier
Message:

major rework of objects code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/objects/pmSourceIO_CMP.c

    r6545 r6556  
    1 # include "pmSource.h"
     1/** @file  pmSourceIO.c
     2 *
     3 *  @author EAM, IfA
     4 *
     5 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-03-09 03:14:23 $
     7 *
     8 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     9 *
     10 */
     11
     12#include <stdio.h>
     13#include <math.h>
     14#include <string.h>
     15#include "pslib.h"
     16#include "psLine.h"
     17#include "psEllipse.h"
     18#include "pmHDU.h"
     19#include "pmFPA.h"
     20#include "pmPeaks.h"
     21#include "pmMoments.h"
     22#include "pmGrowthCurve.h"
     23#include "pmModel.h"
     24#include "pmPSF.h"
     25#include "pmSource.h"
     26#include "pmModelGroup.h"
     27#include "pmSourceIO.h"
    228
    329// elixir-style pseudo FITS table (header + ascii list)
     
    1036    float dmag, lsky;
    1137    bool status;
     38    EllipseShape shape;
     39    EllipseAxes axes;
    1240
    1341    // find config information for output header
     
    1947    for (i = nSrc = 0; i < sources->n; i++) {
    2048        pmSource *source = (pmSource *) sources->data[i];
    21         pmModel *model = pmModelSelect (source);
     49        pmModel *model = pmSourceSelectModel (source);
    2250        if (model == NULL)
    2351            continue;
     
    4977    for (i = 0; i < sources->n; i++) {
    5078        pmSource *source = (pmSource *) sources->data[i];
    51         pmModel *model = pmModelSelect (source);
     79        pmModel *model = pmSourceSelectModel (source);
    5280        if (model == NULL)
    5381            continue;
     
    5684        dPAR = model->dparams->data.F32;
    5785
    58         dmag = dPAR[1] / PAR[1];
    5986        type = pmSourceDophotType (source);
    6087        lsky = (PAR[0] < 1.0) ? 0.0 : log10(PAR[0]);
    6188
     89        shape.sx  = PAR[4];
     90        shape.sy  = PAR[5];
     91        shape.sxy = PAR[6];
     92        axes = EllipseShapeToAxes (shape);
     93
    6294        psLineInit (line);
    63         psLineAdd (line, "%6.1f ", PAR[2]);
    64         psLineAdd (line, "%6.1f ", PAR[3]);
    65         psLineAdd (line, "%6.3f ", PS_MIN (99.999, source->fitMag + ZERO_POINT));
    66         psLineAdd (line, "%03d ",  PS_MIN (999, (int)(1000*dmag)));
    67         psLineAdd (line, "%2d ",   type);
    68         psLineAdd (line, "%3.1f ", lsky);
    69         psLineAdd (line, "%6.3f ", 99.999); // should be 'Mgal
    70         psLineAdd (line, "%6.3f ", PS_MIN (99.999, source->apMag + ZERO_POINT));
    71         psLineAdd (line, "%6.2f ", PAR[4]); // should be 'FHWM x'
    72         psLineAdd (line, "%6.2f ", PAR[5]); // should be 'FHWM y'
    73         psLineAdd (line, "%5.1f\n", 0); // should be theta
     95        psLineAdd (line, "%6.1f ",  PAR[2]);
     96        psLineAdd (line, "%6.1f ",  PAR[3]);
     97        psLineAdd (line, "%6.3f ",  PS_MIN (99.0, source->psfMag + ZERO_POINT));
     98        psLineAdd (line, "%03d ",   PS_MIN (999, (int)(1000*dmag)));
     99        psLineAdd (line, "%2d ",    type);
     100        psLineAdd (line, "%3.1f ",  lsky);
     101        psLineAdd (line, "%6.3f ",  PS_MIN (99.0, source->extMag + ZERO_POINT));
     102        psLineAdd (line, "%6.3f ",  PS_MIN (99.0, source->apMag + ZERO_POINT));
     103        psLineAdd (line, "%6.2f ",  axes.major);
     104        psLineAdd (line, "%6.2f ",  axes.minor);
     105        psLineAdd (line, "%5.1f\n", axes.theta);
    74106        fwrite (line->line, 1, line->Nline, f);
    75107    }
     
    82114
    83115// elixir-style pseudo FITS table (header + ascii list)
    84 psArray *sources pmSourcesReadCMP (char *filename, psMetadata *header)
     116psArray *pmSourcesReadCMP (char *filename, psMetadata *header)
    85117{
    86118
    87     int i, type, nSrc;
    88     psMetadataItem *mdi;
     119    int Ninstar;
    89120    psF32 *PAR, *dPAR;
    90     float dmag, lsky;
    91121    bool status;
     122    EllipseShape shape;
     123    EllipseAxes axes;
     124
     125    // define PSF model type
     126    int modelType = pmModelSetType ("PS_MODEL_GAUSS");
     127
     128    char *PSF_NAME = psMetadataLookupStr (&status, header, "PSF_NAME");
     129    if (PSF_NAME != NULL) {
     130        modelType = pmModelSetType (PSF_NAME);
     131    }
    92132
    93133    // find config information for output header
     
    113153
    114154    // prepare array to store data
    115     int nStars = psMetadataLookupS32 (&status, myHeader, "NSTARS");
     155    int nStars = psMetadataLookupS32 (&status, header, "NSTARS");
    116156    psArray *sources = psArrayAlloc (nStars);
    117157    sources->n = 0;
    118158
    119159    // we have fixed bytes / line : use that info
    120     char *buffer = psAlloc (NBYTES_STAR*nStars);
     160    char *buffer = psAlloc (BYTES_STAR*nStars);
    121161
    122162    int Nextra = 0;
     
    161201
    162202        /* extract data for stars */
    163         int Ninstar = nbytes / BYTES_STAR;
     203        Ninstar = nbytes / BYTES_STAR;
    164204        Nextra = nbytes % BYTES_STAR;
    165         for (j = 0; j < Ninstar; j++, N++) {
    166             psString line = psStringNCopy (&buffer[j*BYTES_STAR]);
     205        for (int j = 0; j < Ninstar; j++) {
     206            psString line = psStringNCopy (&buffer[j*BYTES_STAR], BYTES_STAR);
    167207            psList *list = psStringSplit (line, " ");
    168208            psArray *array = psListToArray (list);
    169209
    170210            pmSource *source = pmSourceAlloc ();
    171 
    172             source->x      = atof (array->data[0]);
    173             source->y      = atof (array->data[1]);
    174             source->fitMag = atof (array->data[2]);
    175             source->dMag   = 0.001*atof (array->data[3]);
    176             source->type   = atof (array->data[4]);
    177             source->sky    = pow (atof (array->data[5]), 10.0);
    178             source->galMag = atof (array->data[6]);
     211            pmModel *model = pmModelAlloc (modelType);
     212            source->modelPSF  = model;
     213
     214            PAR = model->params->data.F32;
     215            dPAR = model->dparams->data.F32;
     216
     217            PAR[0]         = pow (atof (array->data[5]), 10.0);
     218            PAR[2]         = atof (array->data[0]);
     219            PAR[3]         = atof (array->data[1]);
     220            source->psfMag = atof (array->data[2]);
     221            source->extMag = atof (array->data[6]);
     222            source->errMag = atof (array->data[3]) / 1000.0;
    179223            source->apMag  = atof (array->data[7]);
    180             source->sx     = atof (array->data[8]);
    181             source->sy     = atof (array->data[9]);
    182             source->theta  = atof (array->data[10]);
     224            axes.major     = atof (array->data[8]);
     225            axes.minor     = atof (array->data[9]);
     226            axes.theta  = atof (array->data[10]);
     227
     228            shape = EllipseAxesToShape (axes);
     229
     230            PAR[4] = shape.sx;
     231            PAR[5] = shape.sy;
     232            PAR[6] = shape.sxy;
     233
     234            // source->type   = atof (array->data[4]);
    183235
    184236            psArrayAdd (sources, 100, source);
Note: See TracChangeset for help on using the changeset viewer.