psf.h 5.54 KB
Newer Older
1
2
3
4
5
6
7
8
9
/*
*				psf.h
*
* Include file for psf.c.
*
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*
*	This file part of:	SExtractor
*
10
*	Copyright:		(C) 1998-2020 IAP/CNRS/SorbonneU
Emmanuel Bertin's avatar
Emmanuel Bertin committed
11
*
12
*	License:		GNU General Public License
Emmanuel Bertin's avatar
Emmanuel Bertin committed
13
*
14
15
16
17
18
19
20
21
22
23
*	SExtractor is free software: you can redistribute it and/or modify
*	it under the terms of the GNU General Public License as published by
*	the Free Software Foundation, either version 3 of the License, or
*	(at your option) any later version.
*	SExtractor is distributed in the hope that it will be useful,
*	but WITHOUT ANY WARRANTY; without even the implied warranty of
*	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*	GNU General Public License for more details.
*	You should have received a copy of the GNU General Public License
*	along with SExtractor. If not, see <http://www.gnu.org/licenses/>.
Emmanuel Bertin's avatar
Emmanuel Bertin committed
24
*
25
*	Last modified:		15/07/2020
Emmanuel Bertin's avatar
Emmanuel Bertin committed
26
*
27
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
Emmanuel Bertin's avatar
Emmanuel Bertin committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

/*----------------------------- Internal constants --------------------------*/

#define	PSF_MAXSHIFT	20.0	/* Max shift from initial guess (pixels)*/
#define	PSF_MINSHIFT	1e-3	/* Min shift from previous guess (pixels)*/
#define PSF_NITER	20	/* Maximum number of iterations in fit */
#define PSF_NA		3	/* Number of fitted parameters per component */
#define PSF_NTOT	(PSF_NA*PSF_NPSFMAX)	/* Number of fitted parameters*/
#define PSF_DOUBLETOT   ((PSF_NA+1)*PSF_NPSFMAX)/* Nb of fitted parameters */
#define	PC_NITER	1	/* Maximum number of iterations in PC fit */

/* NOTES:
One must have:	PSF_MAXSHIFT > 0.0
		PSF_NPSF >= 1
		PSF_NITER >= 1
*/

/*--------------------------- structure definitions -------------------------*/

typedef struct code
  {
  float		*pc;
  float		**param;
  int		*parammod;
  int		ncode;
  int		nparam;
  }		codestruct;

typedef struct pc
  {
  char		name[MAXCHAR];	/* PC filename */
  int		npc;		/* Number of Principal Components */
  int		maskdim;	/* Dimensionality of the tabulated data */
  int		*masksize;	/* PC mask dimensions */
  int		masknpix;	/* Total number of involved PC pixels */
  float		*maskcomp; 	/* Convolved pix data (principal components) */
  int		omaskdim;	/* Dimensionality of the tabulated data */
  int		*omasksize;	/* PC mask dimensions */
  int		omasknpix;	/* Total number of involved PC pixels */
  float		*omaskcomp; 	/* Original pix data (principal components) */
68
69
70
71
  float		*maskcurr;	/* Current model */
  float		*mx2,*my2,*mxy;	/* 2nd order moments for each component */
  float		*flux;		/* Flux of each component */
  float		*bt;		/* B/T for each component */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
72
73
74
  codestruct	*code;
  }	pcstruct;

Emmanuel Bertin's avatar
Emmanuel Bertin committed
75
typedef struct psf
Emmanuel Bertin's avatar
Emmanuel Bertin committed
76
77
78
79
80
81
  {
  char		name[MAXCHAR];	/* Name of the file containing the PSF data */
  int		maskdim;	/* Dimensionality of the tabulated data */
  int		*masksize;	/* PSF mask dimensions */
  int		masknpix;	/* Total number of involved PSF pixels */
  float		*maskcomp;      /* Complete pix. data (PSF components) */
82
  float		*maskloc;	/* Local PSF */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
83
  double	**context;	/* Contexts */
84
  int		*contextindex;	/* Context index (for arrays) */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
85
86
87
88
89
90
91
92
  t_type	*contexttyp;	/* Context types */
  char		**contextname;	/* Array of context key-names */
  double	*contextoffset;	/* Offset to apply to context data */
  double	*contextscale;	/* Scaling to apply to context data */
  struct poly	*poly;		/* Polynom describing the PSF variations */
  pcstruct	*pc;		/* PC components */
  double	fwhm;		/* Typical PSF FWHM */
  float		pixstep;	/* PSF sampling step */
93
  int		build_flag;	/* Set if the current PSF has been computed */
94
  int		mag_flag;	/* Set if PSF contexts include magnitudes */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
95
96
97
98
99
100
  }	psfstruct;

typedef struct
  {
  int		niter;		/* Number of iterations required */
  int		npsf;		/* Number of fitted stars for this detection */
101
  double	*x,*y;		/* Position derived from the PSF-fitting */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
102
  float		*flux;		/* Flux derived from the PSF-fitting */
103
  float		*fluxerr;	/* Flux error estimated from the PSF-fitting */
Emmanuel Bertin's avatar
Emmanuel Bertin committed
104
105
106
  }	psfitstruct;

/*----------------------------- Global variables ----------------------------*/
107
108
109
extern psfstruct	*psf,*thedpsf,*thepsf;
extern psfitstruct	*thepsfit,*thedpsfit;
extern PIXTYPE		*checkmask;
Emmanuel Bertin's avatar
Emmanuel Bertin committed
110
111
112
113
114
115
116
117

/*-------------------------------- functions --------------------------------*/
extern void	compute_pos(int *pnpsf,int *pconvflag,int *pnpsfflag,
			double radmin2, double radmax2,double r2, double *sol,
			double *flux , double *deltax,double *deltay,
			double *pdx,double *pdy),
		compute_pos_phot(int *pnpsf,double *sol,double *flux),
		compute_poserr(int j,double *var,double *sol,obj2struct *obj2,
118
			double *x2, double *y2,double *xy, int npsf),
Emmanuel Bertin's avatar
Emmanuel Bertin committed
119
120
		psf_build(psfstruct *psf),
		psf_end(psfstruct *psf, psfitstruct *psfit),
121
		psf_init(void),
122
		svdfit(double *a, float *b, int m, int n, double *sol,
Emmanuel Bertin's avatar
Emmanuel Bertin committed
123
124
125
			double *vmat, double *wmat),
		svdvar(double *vmat, double *wmat, int n, double *covmat);

126
127
extern double	*compute_gradient (float *weight,int width, int height,
			float *masks, float *maskx, float *masky,
Emmanuel Bertin's avatar
Emmanuel Bertin committed
128
			double *mat),
129
		*compute_gradient_phot(float *weight,int width, int height,
130
131
			float *masks, double *pm),
		psf_fwhm(psfstruct *psf);
Emmanuel Bertin's avatar
Emmanuel Bertin committed
132

133
extern psfstruct	*psf_load(char *filename, int ext);
Emmanuel Bertin's avatar
Emmanuel Bertin committed
134
135

extern void	pc_end(pcstruct *pc),
136
137
		pc_fit(psfstruct *psf, float *data, float *weight,
		int width, int height, int ix, int iy, float dx, float dy,
Emmanuel Bertin's avatar
Emmanuel Bertin committed
138
139
140
141
142
143
144
145
146
		int npc, float backrms),
		double_psf_fit(psfstruct *psf, picstruct *field,
			picstruct *wfield, objstruct *obj,
			psfstruct *dpsf, picstruct *dfield, picstruct *dwfield),
		psf_fit(psfstruct *psf, picstruct *field, picstruct *wfield,
		objstruct *obj),
		psf_readcontext(psfstruct *psf, picstruct *field);

extern pcstruct	*pc_load(catstruct *cat);
147