Changeset 40663 for branches/eam_branches/ohana.20190329
- Timestamp:
- Mar 31, 2019, 3:08:13 PM (7 years ago)
- Location:
- branches/eam_branches/ohana.20190329/src/opihi
- Files:
-
- 1 added
- 7 edited
-
cmd.data/interpolate_presort.c (modified) (3 diffs)
-
include/deimos.h (modified) (2 diffs)
-
mana/Makefile (modified) (1 diff)
-
mana/deimos.c (modified) (2 diffs)
-
mana/deimos_fitalt.c (modified) (7 diffs)
-
mana/deimos_getalt.c (added)
-
mana/deimos_getobj.c (modified) (7 diffs)
-
mana/deimos_mkmodel.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20190329/src/opihi/cmd.data/interpolate_presort.c
r40007 r40663 7 7 double x0, dx, dy, y0; 8 8 Vector *xout, *yout, *xin, *yin; 9 10 int N; 11 int FillEnds = FALSE; 12 if ((N = get_argument (argc, argv, "-fill-ends"))) { 13 FillEnds = TRUE; 14 remove_argument (N, &argc, argv); 15 } 9 16 10 17 /** check basic syntax **/ … … 38 45 /* in and out vectors are sorted */ 39 46 j = 0; 47 i = 0; 48 49 // fill in the rest with NANs 50 while (xout[0].elements.Flt[i] < xin[0].elements.Flt[0]) { 51 yout[0].elements.Flt[i] = FillEnds ? yin[0].elements.Flt[0] : NAN; 52 i++; 53 } 40 54 41 55 // every output pixel should get a value unless 42 56 // we are below the lowest in or above the highest in 43 for ( i = 0,j = 0; (i < xout[0].Nelements) && (j < xin[0].Nelements - 1); ) {57 for (j = 0; (i < xout[0].Nelements) && (j < xin[0].Nelements - 1); ) { 44 58 45 59 yout[0].elements.Flt[i] = NAN; … … 66 80 67 81 // fill in the rest with NANs 82 int NinLast = xin[0].Nelements - 1; 68 83 while (i < yout[0].Nelements) { 69 yout[0].elements.Flt[i] = NAN;84 yout[0].elements.Flt[i] = FillEnds ? yin[0].elements.Flt[NinLast] : NAN; 70 85 i++; 71 86 } 72 87 73 88 return (TRUE); 74 75 89 } -
branches/eam_branches/ohana.20190329/src/opihi/include/deimos.h
r40642 r40663 7 7 } DeimosResult; 8 8 9 float *deimos_make_model (opihi_flt *obj, opihi_flt *sky, opihi_flt *bck, Vector *psf, Vector *profile, Spline * trace, int Nx, int Ny, int row);9 float *deimos_make_model (opihi_flt *obj, opihi_flt *sky, opihi_flt *bck, Vector *psf, Vector *profile, Spline *slit_trace, Spline *psf_trace, int Nx, int Ny, int row); 10 10 void deimos_make_kernel (float stilt, int Nx); 11 11 void deimos_free_kernel (); … … 13 13 14 14 // internal to make_model: 15 float *deimos_make_straight_image (opihi_flt *obj, opihi_flt *sky, Vector *psf, int Nx, int Ny, int row);15 float *deimos_make_straight_image (opihi_flt *obj, opihi_flt *sky, Vector *psf, Spline *psf_trace, int Nx, int Ny, int row); 16 16 float *deimos_apply_tilt (float *input, int Nx, int Ny); 17 17 void deimos_apply_profile (Vector *profile, float *out, int Nx, int Ny); 18 18 void deimos_add_background (opihi_flt *backgnd, float *out, int Nx, int Ny, int row); 19 float *deimos_apply_trace (Spline * trace, float *input, int Nx, int Ny, int row);19 float *deimos_apply_trace (Spline *slit_trace, float *input, int Nx, int Ny, int row); 20 20 -
branches/eam_branches/ohana.20190329/src/opihi/mana/Makefile
r40655 r40663 25 25 $(SRC)/deimos_fitslit.$(ARCH).o \ 26 26 $(SRC)/deimos_getobj.$(ARCH).o \ 27 $(SRC)/deimos_getalt.$(ARCH).o \ 27 28 $(SRC)/deimos_fitobj.$(ARCH).o \ 28 29 $(SRC)/deimos_fitalt.$(ARCH).o \ -
branches/eam_branches/ohana.20190329/src/opihi/mana/deimos.c
r40655 r40663 6 6 int deimos_mkalt (int argc, char **argv); 7 7 int deimos_getobj (int argc, char **argv); 8 int deimos_getalt (int argc, char **argv); 8 9 int deimos_fitobj (int argc, char **argv); 9 10 int deimos_fitalt (int argc, char **argv); … … 14 15 {1, "fitalt", deimos_fitalt, "fit for object parameters using LMM"}, 15 16 {1, "getobj", deimos_getobj, "determine crude object parameters"}, 17 {1, "getalt", deimos_getalt, "determine crude object parameters"}, 16 18 {1, "mkobj", deimos_mkobj, "make a full object image"}, 17 19 {1, "mkalt", deimos_mkalt, "make a full object image (uses deimos_make_object, for a test)"}, -
branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_fitalt.c
r40655 r40663 27 27 // input parameters: 28 28 // * buffer : 2D image of slit (full frame or cutout?) 29 // * trace : spline fit of slit central x pos vs y-coord 29 // * slit_trace : spline fit of slit central x pos vs y-coord 30 // * psf_trace : spline fit of slit central x pos vs y-coord 30 31 // * profile : slit window profile (vector) 31 32 // * PSF : point-spread function vector (flux normalized, x-dir) … … 39 40 int N; 40 41 41 Spline *trace = NULL; 42 Spline *slit_trace = NULL; 43 Spline *psf_trace = NULL; 42 44 Vector *profile = NULL; 43 45 … … 106 108 107 109 // Input parameters: 108 if ((N = get_argument (argc, argv, "-trace"))) { 109 remove_argument (N, &argc, argv); 110 if ((trace = FindSpline (argv[N])) == NULL) return (FALSE); 110 if ((N = get_argument (argc, argv, "-slit-trace"))) { 111 remove_argument (N, &argc, argv); 112 if ((slit_trace = FindSpline (argv[N])) == NULL) return (FALSE); 113 remove_argument (N, &argc, argv); 114 } else { goto usage; } 115 if ((N = get_argument (argc, argv, "-psf-trace"))) { 116 remove_argument (N, &argc, argv); 117 if ((psf_trace = FindSpline (argv[N])) == NULL) return (FALSE); 111 118 remove_argument (N, &argc, argv); 112 119 } else { goto usage; } … … 244 251 // current vector value: 245 252 // for deimos_make_model, row is the starting point of the subimage 246 float *model_ref = deimos_make_model (objCurr, skyCurr, bckCurr, psf, profile, trace, Nx, Nrow, row_0);253 float *model_ref = deimos_make_model (objCurr, skyCurr, bckCurr, psf, profile, slit_trace, psf_trace, Nx, Nrow, row_0); 247 254 248 255 // in the test functions below, dRow is the central pixel of the subset, e.g., obj[row] => objCurr[dRow] … … 252 259 // delta obj (save dObj) 253 260 opihi_flt *objtest = deimos_make_test (objCurr, objNoise[row], dRow, Nrow, &dObj); 254 float *model_obj = deimos_make_model (objtest, skyCurr, bckCurr, psf, profile, trace, Nx, Nrow, row_0);261 float *model_obj = deimos_make_model (objtest, skyCurr, bckCurr, psf, profile, slit_trace, psf_trace, Nx, Nrow, row_0); 255 262 256 263 // delta sky (save dSky) 257 264 opihi_flt *skytest = deimos_make_test (skyCurr, skyNoise[row], dRow, Nrow, &dSky); 258 float *model_sky = deimos_make_model (objCurr, skytest, bckCurr, psf, profile, trace, Nx, Nrow, row_0);265 float *model_sky = deimos_make_model (objCurr, skytest, bckCurr, psf, profile, slit_trace, psf_trace, Nx, Nrow, row_0); 259 266 260 267 // delta bck (save dBck) 261 268 opihi_flt *bcktest = deimos_make_test (bckCurr, bckNoise[row], dRow, Nrow, &dBck); 262 float *model_bck = deimos_make_model (objCurr, skyCurr, bcktest, psf, profile, trace, Nx, Nrow, row_0);269 float *model_bck = deimos_make_model (objCurr, skyCurr, bcktest, psf, profile, slit_trace, psf_trace, Nx, Nrow, row_0); 263 270 264 271 // dObj, dSky, dBck carry the delta used derivatives in and the delta applied to the values out … … 294 301 } 295 302 296 float *model_full = deimos_make_model (objVal, skyVal, bckVal, psf, profile, trace, Nx, Ny, 0);303 float *model_full = deimos_make_model (objVal, skyVal, bckVal, psf, profile, slit_trace, psf_trace, Nx, Ny, 0); 297 304 298 305 int Npts = 0; … … 305 312 306 313 usage: 307 gprint (GP_ERR, "USAGE: deimos fitobj (buffer) (Xref) -object vector -sky vector -backgnd vector - trace spline -profile vector -psf vector -stilt (angle)\n");314 gprint (GP_ERR, "USAGE: deimos fitobj (buffer) (Xref) -object vector -sky vector -backgnd vector -slit-trace spline -psf-trace spline -profile vector -psf vector -stilt (angle)\n"); 308 315 return FALSE; 309 316 } -
branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_getobj.c
r40659 r40663 3 3 // temporary storage used in local functions: 4 4 5 float *tmpv = NULL;6 float *tmpx = NULL;5 static float *tmpv = NULL; 6 static float *tmpx = NULL; 7 7 8 8 // pass in a pointer to the row (&buffV[iy*Nx]) … … 39 39 // input parameters: 40 40 // * buffer : 2D image of slit (full frame or cutout?) 41 // * trace : spline fit of slit central x pos vs y-coord 41 // * slit_trace : spline fit of slit central x pos vs y-coord 42 // * psf_trace : spline fit of psf central x pos vs y-coord 42 43 // * profile : slit window profile (vector) 43 44 // * PSF : point-spread function vector (flux normalized, x-dir) … … 51 52 int N; 52 53 53 Spline *trace = NULL; 54 Spline *slit_trace = NULL; 55 Spline *psf_trace = NULL; 54 56 Vector *profile = NULL; 55 57 … … 71 73 72 74 // Input parameters: 73 if ((N = get_argument (argc, argv, "-trace"))) { 74 remove_argument (N, &argc, argv); 75 if ((trace = FindSpline (argv[N])) == NULL) return (FALSE); 75 if ((N = get_argument (argc, argv, "-slit-trace"))) { 76 remove_argument (N, &argc, argv); 77 if ((slit_trace = FindSpline (argv[N])) == NULL) return (FALSE); 78 remove_argument (N, &argc, argv); 79 } else { goto usage; } 80 if ((N = get_argument (argc, argv, "-psf-trace"))) { 81 remove_argument (N, &argc, argv); 82 if ((psf_trace = FindSpline (argv[N])) == NULL) return (FALSE); 76 83 remove_argument (N, &argc, argv); 77 84 } else { goto usage; } … … 218 225 219 226 // loop over the y positions 227 // examine the slit window profile to measure background and slit sky 220 228 for (int iy = 0; iy < Ny; iy++) { 221 229 222 230 // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center 223 float dXtrace = spline_apply_dbl ( trace->xk, trace->yk, trace->y2,trace->Nknots, iy);231 float dXtrace = spline_apply_dbl (slit_trace->xk, slit_trace->yk, slit_trace->y2, slit_trace->Nknots, iy); 224 232 225 233 // Xref is the reference coordinate of the profile on the image … … 284 292 285 293 // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center 286 float dXtrace = spline_apply_dbl (trace->xk, trace->yk, trace->y2, trace->Nknots, iy); 294 float dXtraceSLIT = spline_apply_dbl (slit_trace->xk, slit_trace->yk, slit_trace->y2, slit_trace->Nknots, iy); 295 float dXtracePSF = spline_apply_dbl (psf_trace->xk, psf_trace->yk, psf_trace->y2, psf_trace->Nknots, iy); 287 296 288 297 // Xref is the reference coordinate of the profile on the image 289 298 // Xpsf is the center of the PSF. 290 299 // dXtrace follows the x-dir variations of the slit profile (or PSF?) 291 float Xtrace = Xref - Xpsf + dXtrace; 292 300 float XtracePSF = Xref - Xpsf + dXtraceSLIT + dXtracePSF; 301 float XtraceSLIT = Xref - Xprofile + dXtraceSLIT; 302 293 303 // include the PSF trace and restrict the fit below to portions where the profile is > 0.95 294 304 295 305 // now I need to find the limits of the PSF in the buffer at this iy location 306 int Ntmp = 0; 296 307 for (int ipsf = 0; ipsf < Npsf; ipsf ++) { 297 308 298 int ix = ipsf + Xtrace + 0.5; // image coordinate (nearest pixel center) 309 int ix = ipsf + XtracePSF + 0.5; // image coordinate (nearest pixel center) 310 int islit = ix - XtraceSLIT - 0.5; // image coordinate (nearest pixel center) 311 299 312 float So = S_lf + (ix - X_lf)*(S_rt - S_lf)/(X_rt - X_lf); // interpolated sky under PSF peak 300 313 301 tmpv[ipsf] = buffV[ix + iy*Nx] - So; 302 tmpx[ipsf] = ipsf; 314 if (islit < 0) continue; 315 if (islit >= profile->Nelements) continue; 316 317 if (iy == 6000) { 318 fprintf (stderr, "%d : %f %f : %f : %f\n", ipsf, buffV[ix + iy*Nx] - So, psfV[ipsf], (buffV[ix + iy*Nx] - So)*psfV[ipsf], profile->elements.Flt[islit]); 319 } 320 321 if (profile->elements.Flt[islit] < 0.95) continue; 322 323 tmpv[Ntmp] = buffV[ix + iy*Nx] - So; 324 tmpx[Ntmp] = psfV[ipsf]; 325 Ntmp ++; 303 326 } 304 327 … … 306 329 // now fit the PSF to tmpv by calculating a normalization 307 330 float S1 = 0.0, S2 = 0.0; 308 for (int ipsf = 0; ipsf < N psf; ipsf++) {331 for (int ipsf = 0; ipsf < Ntmp; ipsf++) { 309 332 if (iy == 6000) { 310 fprintf (stderr, "%d : %f %f : %f\n", ipsf, tmpv[ipsf], psfV[ipsf], tmpv[ipsf]*psfV[ipsf]);333 fprintf (stderr, "%d : %f %f : %f\n", ipsf, tmpv[ipsf], tmpx[ipsf], tmpv[ipsf]*tmpx[ipsf]); 311 334 } 312 S1 += tmpv[ipsf]* psfV[ipsf]; // if we have an errorbar, include / SQ(sigv[i])313 S2 += psfV[ipsf]*psfV[ipsf]; // if we have an errorbar, include / SQ(sigv[i])335 S1 += tmpv[ipsf]*tmpx[ipsf]; // if we have an errorbar, include / SQ(sigv[i]) 336 S2 += tmpx[ipsf]*tmpx[ipsf]; // if we have an errorbar, include / SQ(sigv[i]) 314 337 } 315 338 316 int Xo = Xref - dXtrace ; // center of PSF in image x-coordinates339 int Xo = Xref - dXtraceSLIT - dXtracePSF; // center of PSF in image x-coordinates 317 340 float So = S_lf + (Xo - X_lf)*(S_rt - S_lf)/(X_rt - X_lf); // interpolated sky under PSF peak 318 341 object->elements.Flt[iy] = S1 / S2; -
branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_mkmodel.c
r40659 r40663 86 86 // generate a subimage of the full model for the range row - row + Ny 87 87 // obj,sky,bck are subset vectors corresponding to the range row to row+Ny 88 float *deimos_make_model (opihi_flt *obj, opihi_flt *sky, opihi_flt *bck, Vector *psf, Vector *profile, Spline * trace, int Nx, int Ny, int row) {89 90 float *raw = deimos_make_straight_image (obj, sky, psf, Nx, Ny, row);88 float *deimos_make_model (opihi_flt *obj, opihi_flt *sky, opihi_flt *bck, Vector *psf, Vector *profile, Spline *slit_trace, Spline *psf_trace, int Nx, int Ny, int row) { 89 90 float *raw = deimos_make_straight_image (obj, sky, psf, psf_trace, Nx, Ny, row); 91 91 float *new = deimos_apply_tilt (raw, Nx, Ny); 92 92 deimos_apply_profile (profile, new, Nx, Ny); 93 93 deimos_add_background (bck, new, Nx, Ny, row); 94 float *out = deimos_apply_trace ( trace, new, Nx, Ny, row);94 float *out = deimos_apply_trace (slit_trace, new, Nx, Ny, row); 95 95 96 96 free (raw); … … 104 104 // *** generate a raw image with no slit tilt and no trace offsets. apply the PSF to the 105 105 // object flux, add in the sky flux 106 float *deimos_make_straight_image (opihi_flt *obj, opihi_flt *sky, Vector *psf, int Nx, int Ny, int row) {106 float *deimos_make_straight_image (opihi_flt *obj, opihi_flt *sky, Vector *psf, Spline *psf_trace, int Nx, int Ny, int row) { 107 107 OHANA_UNUSED_PARAM(row); 108 108 … … 126 126 opihi_flt skyVy = sky[iy]; // if we shift to using the row offset: sky[iy + row] 127 127 128 // integral and fractional pixel offsets of PSF (none, by default) 129 int dxi = 0; 130 float dxf = 0.0, dxr = 1.0; 131 132 if (psf_trace) { 133 float dx = spline_apply_dbl (psf_trace->xk, psf_trace->yk, psf_trace->y2, psf_trace->Nknots, iy); 134 dxi = floor(dx); 135 dxf = dx - dxi; // -1.7 -> +0.3, -0.5 -> +0.5, +0.5 ->+0.5, +1.7 -> +0.7 136 dxr = 1 - dxf; 137 Xref += dxi; 138 } 139 140 // if fractional offset is small, do not interpolate 141 int doInterp = fabs(dxf) < 1e-5 ? FALSE : TRUE; 142 128 143 // flux = obj * PSF + sky 129 144 for (int ix = 0; ix < Nx; ix++) { … … 136 151 // only add in the flux if we are in range of the PSF 137 152 if ((n >= 0) && (n < NpsfFull)) { 138 value += objVy * psfV[n]; 153 if (doInterp) { 154 if ((n > 0) && (n < NpsfFull)) { 155 value += objVy*psfV[n]*dxr + objVy*psfV[n-1]*dxf; 156 } 157 if (n == 0) { 158 value += objVy*psfV[n]*dxr; 159 } 160 } else { 161 value += objVy * psfV[n]; 162 } 139 163 } 140 164 out[ix + iy*Nx] = value; … … 219 243 220 244 // shift pixels in x based on the trace 221 float *deimos_apply_trace (Spline * trace, float *input, int Nx, int Ny, int row) {245 float *deimos_apply_trace (Spline *slit_trace, float *input, int Nx, int Ny, int row) { 222 246 223 247 ALLOCATE_PTR (output, float, Nx*Ny); … … 227 251 // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center 228 252 // NOTE: spline is evaluated at full dispersion coordinate 229 float dx = -spline_apply_dbl ( trace->xk, trace->yk, trace->y2,trace->Nknots, iy + row);253 float dx = -spline_apply_dbl (slit_trace->xk, slit_trace->yk, slit_trace->y2, slit_trace->Nknots, iy + row); 230 254 231 255 // extract the integer pixel offset and the fractional offset
Note:
See TracChangeset
for help on using the changeset viewer.
