1  /*
2  				types.h
3 
4 *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 *
6 *	Part of:	SExtractor
7 *
8 *	Author:		E.BERTIN (IAP)
9 *
10 *	Contents:	global type definitions.
11 *
12 *	Last modify:	12/01/2006
13 *
14 *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15 */
16 
17 #include <stdio.h>
18 
19 #ifndef _FITSCAT_H_
20 #include "fits/fitscat.h"
21 #endif
22 
23 /*-------------------------------- flags ------------------------------------*/
24 
25 #define		OBJ_CROWDED	0x0001
26 #define		OBJ_MERGED	0x0002
27 #define		OBJ_SATUR	0x0004
28 #define		OBJ_TRUNC	0x0008
29 #define		OBJ_APERT_PB	0x0010
30 #define		OBJ_ISO_PB	0x0020
31 #define		OBJ_DOVERFLOW	0x0040
32 #define		OBJ_OVERFLOW	0x0080
33 
34 /*----------------------------- weight flags --------------------------------*/
35 
36 #define		OBJ_WEIGHTZERO	0x0001
37 #define		OBJ_DWEIGHTZERO 0x0002
38 
39 /*---------------------------- preanalyse flags -----------------------------*/
40 
41 #define		ANALYSE_FAST		0
42 #define		ANALYSE_FULL		1
43 #define		ANALYSE_ROBUST		2
44 
45 /*--------------------------------- typedefs --------------------------------*/
46 typedef	unsigned char	BYTE;			/* a byte */
47 typedef	unsigned short	USHORT;			/* 0 to 65535 integers */
48 typedef unsigned int	FLAGTYPE;		/* flag type */
49 typedef	char		pliststruct;		/* Dummy type for plist */
50 
51 typedef	int		LONG;
52 typedef	unsigned int	ULONG;
53 
54 typedef  enum {BACK_RELATIVE, BACK_ABSOLUTE}
55 		backenum;				/* BACK_TYPE */
56 
57 typedef  enum {CHECK_NONE, CHECK_IDENTICAL, CHECK_BACKGROUND,
58         CHECK_BACKRMS, CHECK_MINIBACKGROUND, CHECK_MINIBACKRMS,
59         CHECK_SUBTRACTED, CHECK_FILTERED, CHECK_OBJECTS, CHECK_APERTURES,
60 	CHECK_SEGMENTATION, CHECK_ASSOC, CHECK_SUBOBJECTS,
61 	CHECK_SUBPSFPROTOS, CHECK_PSFPROTOS,
62 	CHECK_SUBPCPROTOS, CHECK_PCPROTOS, CHECK_PCOPROTOS,
63 		CHECK_MAPSOM}	checkenum;
64 	/* CHECK_IMAGE type */
65 
66 typedef  enum {WEIGHT_NONE, WEIGHT_FROMBACK, WEIGHT_FROMRMSMAP,
67 		WEIGHT_FROMVARMAP, WEIGHT_FROMWEIGHTMAP, WEIGHT_FROMINTERP}
68 		weightenum;				/* WEIGHT_IMAGE type */
69 
70 /*--------------------------------- objects ---------------------------------*/
71 /* I: "PIXEL" parameters */
72 
73 typedef struct
74   {
75 /* ---- basic parameters */
76   int		number;				/* ID */
77   int		fdnpix;				/* nb of extracted pix */
78   int		dnpix;				/* nb of pix above thresh  */
79   int		npix;				/* "" in measured frame */
80   float		fdflux;				/* integrated ext. flux */
81   float		dflux;				/* integrated det. flux */
82   float		flux;				/* integrated mes. flux */
83   float		fluxerr;			/* integrated variance */
84   float		flux_prof;			/* PROFILE flux*/
85   float		fluxerr_prof;			/* PROFILE flux variance */
86   PIXTYPE	fdpeak;				/* peak intensity (ADU) */
87   PIXTYPE	dpeak;				/* peak intensity (ADU) */
88   PIXTYPE	peak;				/* peak intensity (ADU) */
89 /* ---- astrometric data */
90   int		peakx,peaky;			/* pos of brightest pix */
91   double       	mx, my;				/* barycenter */
92   double	poserr_mx2, poserr_my2,
93 		poserr_mxy;			/* Error ellips moments */
94 /* ---- morphological data */
95   int		xmin,xmax,ymin,ymax,ycmin,ycmax;/* x,y limits */
96   PIXTYPE	*blank, *dblank; 	       	/* BLANKing sub-images  */
97   int		*submap;			/* Pixel-index sub-map */
98   int		subx,suby, subw,subh;		/* sub-image pos. and size */
99   short		flag;				/* extraction flags */
100   BYTE		wflag;				/* weighted extraction flags */
101   FLAGTYPE	imaflag[MAXFLAG];		/* flags from FLAG-images */
102   BYTE		singuflag;			/* flags for singularities */
103   int		imanflag[MAXFLAG];     		/* number of MOST flags */
104   double	mx2,my2,mxy;			/* variances and covariance */
105   float		a, b, theta, abcor;		/* moments and angle */
106   float		cxx,cyy,cxy;			/* ellipse parameters */
107   int		firstpix;			/* ptr to first pixel */
108   int		lastpix;			/* ptr to last pixel */
109   float		bkg, dbkg, sigbkg;		/* Background stats (ADU) */
110   float		thresh;				/* measur. threshold (ADU) */
111   float		dthresh;		       	/* detect. threshold (ADU) */
112   float		mthresh;		       	/* max. threshold (ADU) */
113   int		iso[NISO];			/* isophotal areas */
114   float		fwhm;				/* IMAGE FWHM */
115   }	objstruct;
116 
117 /* II: "BLIND" parameters */
118 typedef struct
119   {
120 /* ---- photometric data */
121   float		flux_iso;			/* ISO integrated flux */
122   float		fluxerr_iso;			/* RMS error on ISO flux */
123   float		mag_iso;			/* ISO mag */
124   float		magerr_iso;			/* ISO mag uncertainty */
125   float		flux_isocor;			/* ISOCOR integrated flux */
126   float		fluxerr_isocor;			/* RMS error on ISOCOR flux */
127   float		mag_isocor;			/* ISOCOR mag */
128   float		magerr_isocor;			/* ISOCOR mag uncertainty */
129   float		kronfactor;			/* kron parameter */
130   float		flux_auto;			/* AUTO integrated flux */
131   float		fluxerr_auto;			/* RMS error on AUTO flux */
132   float		mag_auto;			/* AUTO mag */
133   float		magerr_auto;			/* AUTO mag uncertainty */
134   float		petrofactor;			/* kron parameter */
135   float		flux_petro;			/* AUTO integrated flux */
136   float		fluxerr_petro;			/* RMS error on AUTO flux */
137   float		mag_petro;			/* AUTO mag */
138   float		magerr_petro;			/* AUTO mag uncertainty */
139   float		flux_best;			/* BEST integrated flux */
140   float		fluxerr_best;			/* RMS error on BEST flux */
141   float		mag_best;			/* BEST mag */
142   float		magerr_best;			/* BEST mag uncertainty */
143   float		*flux_aper;			/* APER flux vector */
144   float		*fluxerr_aper;			/* APER flux error vector  */
145   float		*mag_aper;			/* APER magnitude vector */
146   float		*magerr_aper;			/* APER mag error vector */
147   float		flux_prof;			/* PROFILE flux*/
148   float		fluxerr_prof;			/* PROFILE flux error */
149   float		mag_prof;			/* PROFILE magnitude */
150   float		magerr_prof;			/* PROFILE magnitude error */
151   float		flux_win;			/* WINdowed flux*/
152   float		fluxerr_win;			/* WINdowed flux error */
153   float		mag_win;			/* WINdowed magnitude */
154   float		magerr_win;			/* WINdowed magnitude error */
155 /* ---- astrometric data */
156   double	posx,posy;			/* "FITS" pos. in pixels */
157   double	mamaposx,mamaposy;		/* "MAMA" pos. in pixels */
158   float		sposx,sposy;			/* single precision pos. */
159   float		poserr_a, poserr_b,
160 		poserr_theta;			/* Error ellips parameters */
161   float		poserr_cxx, poserr_cyy,
162 		poserr_cxy;			/* pos. error ellipse */
163   double	poserr_mx2w, poserr_my2w,
164 		poserr_mxyw;			/* WORLD error moments */
165   float		poserr_aw, poserr_bw,
166 		poserr_thetaw;			/* WORLD error parameters */
167   float		poserr_thetas;			/* native error pos. angle */
168   float		poserr_theta2000;		/* J2000 error pos. angle */
169   float		poserr_theta1950;		/* B1950 error pos. angle */
170   float		poserr_cxxw, poserr_cyyw,
171 		poserr_cxyw;			/* WORLD error ellipse */
172   double	mx2w,my2w,mxyw;			/* WORLD var. and covar. */
173   double	peakxw, peakyw;			/* WORLD of brightest pix */
174   double	mxw, myw;			/* WORLD barycenters */
175   double	alphas, deltas;			/* native alpha, delta */
176   float		thetas;				/* native position angle E/N*/
177   double	peakalphas, peakdeltas;		/* native for brightest pix */
178   double	peakalpha2000, peakdelta2000;	/* J2000 for brightest pix */
179   double	peakalpha1950, peakdelta1950;	/* B1950 for brightest pix */
180   double	alpha2000, delta2000;		/* J2000 alpha, delta */
181   float		theta2000;			/* J2000 position angle E/N */
182   double	alpha1950, delta1950;		/* B1950 alpha, delta */
183   float		theta1950;			/* B1950 position angle E/N */
184   float		aw, bw;				/* WORLD ellipse size */
185   float		thetaw;				/* WORLD position angle */
186   float		cxxw,cyyw,cxyw;			/* WORLD ellipse parameters */
187   float		npixw, fdnpixw;			/* WORLD isophotal areas */
188   float		threshmu;			/* det. surface brightnees */
189   float		maxmu;				/* max. surface brightnees */
190   float		elong;				/* elongation */
191   float		ellip;				/* ellipticity */
192   float		polar;				/* Kaiser's "polarization" */
193   float		polarw;				/* WORLD "polarization" */
194   float		sprob;				/* Stellarity index */
195   float		fwhmw;				/* WORLD FWHM */
196   float		*assoc;				/* ASSOCiated data */
197   int		assoc_number;			/* nb of ASSOCiated objects */
198   float		*vignet;			/* Pixel data */
199   float		*vigshift;			/* (Shifted) pixel data */
200 
201 /* Windowed measurements */
202   double	winpos_x,winpos_y;		/* Windowed barycenter */
203   double	winposerr_mx2, winposerr_my2,
204 		winposerr_mxy;			/* Error ellips moments */
205   float		winposerr_a, winposerr_b,
206 		winposerr_theta;		/* Error ellips parameters */
207   float		winposerr_cxx, winposerr_cyy,
208 		winposerr_cxy;			/* pos. error ellipse */
209   double	winposerr_mx2w, winposerr_my2w,
210 		winposerr_mxyw;			/* WORLD error moments */
211   float		winposerr_aw, winposerr_bw,
212 		winposerr_thetaw;		/* WORLD error parameters */
213   float		winposerr_thetas;		/* native error pos. angle */
214   float		winposerr_theta2000;		/* J2000 error pos. angle */
215   float		winposerr_theta1950;		/* B1950 error pos. angle */
216   float		winposerr_cxxw, winposerr_cyyw,
217 		winposerr_cxyw;			/* WORLD error ellipse */
218   double	win_mx2, win_my2,
219 		win_mxy;			/* Windowed moments */
220   float		win_a, win_b,
221 		win_theta;			/* Windowed ellipse parameters*/
222   float		win_polar;			/* Windowed "polarization" */
223   float		win_cxx, win_cyy,
224 		win_cxy;			/* Windowed ellipse parameters*/
225   double	win_mx2w, win_my2w,
226 		win_mxyw;			/* WORLD windowed moments */
227   float		win_aw, win_bw,
228 		win_thetaw;			/* WORLD ellipse parameters */
229   float		win_polarw;			/* WORLD WIN "polarization" */
230   float		win_thetas;		/* native error pos. angle */
231   float		win_theta2000;		/* J2000 error pos. angle */
232   float		win_theta1950;		/* B1950 error pos. angle */
233   float		win_cxxw, win_cyyw,
234 		win_cxyw;			/* WORLD ellipse parameters */
235   double	winpos_xw, winpos_yw;		/* WORLD coordinates */
236   double	winpos_alphas, winpos_deltas;	/* native alpha, delta */
237   double	winpos_alpha2000, winpos_delta2000;	/* J2000 alpha, delta */
238   double	winpos_alpha1950, winpos_delta1950;	/* B1950 alpha, delta */
239   short		winpos_niter;			/* Number of WIN iterations */
240   short		win_flag;			/* 1:x2<0 2:xy=x2 4:flux<0 */
241 
242  /* ---- SOM fitting */
243   float		flux_somfit;			/* Fitted amplitude */
244   float		fluxerr_somfit;			/* RMS error on SOM flux */
245   float		mag_somfit;			/* Magnitude from SOM fit */
246   float		magerr_somfit;			/* Mag. err. from SOM fit */
247   float		stderr_somfit;			/* Fitting reduced error */
248   float		*vector_somfit;			/* SOM fit vector position */
249 /* ---- Growth curves and stuff */
250   float		*flux_growth;			/* Cumulated growth_curve */
251   float		flux_growthstep;		/* Growth-curve step */
252   float		*mag_growth;			/* Cumulated growth_curve */
253   float		mag_growthstep;			/* Growth-curve step */
254   float		*flux_radius;			/* f-light-radii */
255   float		hl_radius;			/* Scalar half-light radius */
256 /* ---- PSF-fitting */
257   float		*flux_psf;			/* Flux from PSF-fitting */
258   float		*fluxerr_psf;			/* RMS error on PSF flux */
259   float		*mag_psf;			/* Mag from PSF-fitting */
260   float		*magerr_psf;			/* RMS mag from PSF-fitting */
261   float		*x_psf, *y_psf;			/* Coords from PSF-fitting */
262   short		niter_psf;			/* # of PSF-fitting iterat. */
263   short		npsf;				/* # of fitted PSFs */
264   float		chi2_psf;			/* Red. chi2 of PSF-fitting */
265   double	xw_psf, yw_psf;			/* WORLD coords */
266   double	alphas_psf, deltas_psf;		/* native alpha, delta */
267   double	alpha2000_psf, delta2000_psf;	/* J2000 alpha, delta */
268   double	alpha1950_psf, delta1950_psf;	/* B1950 alpha, delta */
269   double	poserrmx2_psf, poserrmy2_psf,
270 		poserrmxy_psf;			/* Error ellips moments */
271   float		poserra_psf, poserrb_psf,
272 		poserrtheta_psf;		/* Error ellips parameters */
273   float		poserrcxx_psf, poserrcyy_psf,
274 		poserrcxy_psf;			/* pos. error ellipse */
275   double	poserrmx2w_psf, poserrmy2w_psf,
276 		poserrmxyw_psf;			/* WORLD error moments */
277   float		poserraw_psf, poserrbw_psf,
278 		poserrthetaw_psf;		/* WORLD error parameters */
279   float		poserrthetas_psf;		/* native error pos. angle */
280   float		poserrtheta2000_psf;		/* J2000 error pos. angle */
281   float		poserrtheta1950_psf;		/* B1950 error pos. angle */
282   float		poserrcxxw_psf, poserrcyyw_psf,
283 		poserrcxyw_psf;			/* WORLD error ellipse */
284 /* ---- PC-fitting */
285   double	mx2_pc,my2_pc,mxy_pc;		/* PC 2nd-order parameters */
286   float		a_pc,b_pc,theta_pc;		/* PC shape parameters */
287   float		*vector_pc;			/* Principal components */
288   float		gdposang;			/* Gal. disk position angle */
289   float		gdscale;			/* Gal. disk scalelength */
290   float		gdaspect;			/* Gal. disk aspect-ratio */
291   float		gde1,gde2;			/* Gal. disk ellipticities */
292   float		gbratio;			/* Galaxy B/T */
293   float		gbposang;			/* Gal. bulge position angle */
294   float		gbscale;			/* Gal. bulge scalelength */
295   float		gbaspect;			/* Gal. bulge aspect-ratio */
296   float		gbe1,gbe2;			/* Gal. bulge ellipticities */
297   float		flux_galfit;			/* Galaxy tot. flux from fit */
298   float		fluxerr_galfit;			/* RMS error on galfit flux */
299   float		mag_galfit;			/* Galaxy tot. mag from fit */
300   float		magerr_galfit;			/* RMS error on galfit mag */
301 /* ---- MEF */
302   short		ext_number;			/* FITS extension number */
303   }	obj2struct;
304 
305 /*----------------------------- lists of objects ----------------------------*/
306 typedef struct
307   {
308   int		nobj;			/* number of objects in list */
309   objstruct	*obj;			/* pointer to the object array */
310   int		npix;			/* number of pixels in pixel-list */
311   pliststruct	*plist;			/* pointer to the pixel-list */
312   PIXTYPE	dthresh;		/* detection threshold */
313   PIXTYPE	thresh;			/* analysis threshold */
314   }	objliststruct;
315 
316 
317 /*----------------------------- image parameters ----------------------------*/
318 typedef struct pic
319   {
320   char		filename[MAXCHAR];	/* pointer to the image filename */
321   char		*rfilename;		/* pointer to the reduced image name */
322   char		ident[MAXCHAR];		/* field identifier (read from FITS)*/
323   char		rident[MAXCHAR];	/* field identifier (relative) */
324   FILE		*file;			/* pointer the image file structure */
325   char		*fitshead;		/* pointer to the FITS header */
326   int		fitsheadsize;		/* FITS header size */
327 /* ---- main image parameters */
328   int		bitpix, bytepix;	/* nb of bits and bytes per pixel */
329   int		bitsgn;			/* non-zero if signed integer data */
330   int		width, height;		/* x,y size of the field */
331   KINGSIZE_T	npix;			/* total number of pixels */
332   double	bscale, bzero;		/* FITS scale and offset */
333   double	ngamma;			/* normalized photo gamma */
334   int		nlevels;		/* nb of quantification levels */
335   float		pixmin, pixmax;		/* min and max values in frame */
336   int		y;			/* y current position in field */
337   int		ymin;			/* y limit (lowest accessible) */
338   int		ymax;			/* y limit (highest accessible+1) */
339   int		yblank;			/* y blanking limit (highest+1) */
340   PIXTYPE	*strip;			/* pointer to the image buffer */
341   FLAGTYPE	*fstrip;		/* pointer to the FLAG buffer */
342   int		stripheight;		/* height  of a strip (in lines) */
343   int		stripmargin;		/* number of lines in margin */
344   int		stripstep;		/* number of lines at each read */
345   int		stripy;			/* y position in buffer */
346   int		stripylim;		/* y limit in buffer */
347   int		stripysclim;		/* y scroll limit in buffer */
348 /* ---- image (de-)compression */
349   enum {ICOMPRESS_NONE, ICOMPRESS_BASEBYTE, ICOMPRESS_PREVPIX}
350 		compress_type;		/* image compression type */
351   char		*compress_buf;		/* de-compression buffer */
352   char		*compress_bufptr;	/* present pixel in buffer */
353   int		compress_curval;	/* current pixel or checksum value */
354   int		compress_checkval;	/* foreseen pixel or checksum value */
355   int		compress_npix;		/* remaining pixels in buffer */
356 /* ---- basic astrometric parameters */
357    double	pixscale;		/* pixel size in arcsec.pix-1 */
358    double	epoch;			/* epoch of coordinates */
359 /* ---- background parameters */
360   float		*back;			/* ptr to the background map in mem */
361   float		*dback;			/* ptr to the background deriv. map */
362   float		*sigma;			/* ptr to the sigma map */
363   float		*dsigma;		/* Ptr to the sigma deriv. map */
364   int		backw, backh;		/* x,y size of a bkgnd mesh */
365   int		nbackp;			/* total nb of pixels per bkgnd mesh */
366   int		nbackx, nbacky;		/* x,y number of bkgnd meshes */
367   int		nback;			/* total number of bkgnd meshes */
368   int		nbackfx, nbackfy;	/* x,y size of bkgnd filtering mask */
369   float		backmean;		/* median bkgnd value in image */
370   float		backsig;		/* median bkgnd rms in image */
371   float		sigfac;			/* scaling RMS factor (for WEIGHTs) */
372   PIXTYPE	*backline;		/* current interpolated bkgnd line */
373   PIXTYPE	dthresh;		/* detection threshold */
374   PIXTYPE	thresh;			/* analysis threshold */
375   backenum	back_type;		/* Background type */
376 /* ---- astrometric parameters */
377   struct structastrom	*astrom;	/* astrometric data */
378   struct structassoc	*assoc;		/* ptr to the assoc-list */
379   int		flags;			/* flags defining the field type */
380 /* ---- image interpolation */
381   int		interp_flag;		/* interpolation for this field? */
382   PIXTYPE	*interp_backup;		/* backup line for interpolation */
383   PIXTYPE	weight_thresh;		/* interpolation threshold */
384   int		*interp_ytimeoutbuf;	/* interpolation timeout line buffer */
385   int		interp_xtimeout;	/* interpolation timeout value in x */
386   int		interp_ytimeout;	/* interpolation timeout value in y */
387   struct pic	*reffield;	       	/* pointer to a reference field */
388   OFF_T		mefpos;			/* Position in a MEF file */
389   }	picstruct;
390 
391 
392 /*-------------------------------- catalog  ---------------------------------*/
393 
394 typedef struct
395   {
396   int		ndetect;				/* nb of detections */
397   int		ntotal;					/* Total object nb */
398   int		nparam;					/* Nb of parameters */
399 /*----- Misc. strings defining the extraction */
400   char		prefs_name[MAXCHAR];			/* Prefs filename*/
401   char		image_name[MAXCHAR];			/* image filename*/
402   char		psf_name[MAXCHAR];			/* PSF filename*/
403   char		nnw_name[MAXCHAR];			/* NNW name */
404   char		filter_name[MAXCHAR];			/* Filter name */
405   char		soft_name[MAXCHAR];			/* Sextractor version*/
406 /*----- time */
407   char		ext_date[16],ext_time[16];		/* date and time */
408   double	ext_elapsed;				/* processing time */
409 /*----- MEF */
410   int		currext;				/* current extension */
411   int		next;					/* Nb of extensions */
412   }		sexcatstruct;
413 
414