Changeset 39558
- Timestamp:
- Apr 28, 2016, 11:09:46 AM (10 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 1 added
- 7 edited
-
cmd.astro/specpairfit.c (modified) (2 diffs)
-
cmd.astro/transform.c (modified) (1 diff)
-
cmd.data/Makefile (modified) (1 diff)
-
cmd.data/init.c (modified) (2 diffs)
-
cmd.data/type.c (added)
-
lib.shell/VariableOps.c (modified) (2 diffs)
-
lib.shell/convert_to_RPN.c (modified) (1 diff)
-
lib.shell/stack_math.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.astro/specpairfit.c
r33662 r39558 19 19 CastVector (window, OPIHI_INT); 20 20 21 // minimize (flux 1 - flux2*alpha) in window defined by mask21 // minimize (flux2 - flux1*A - B) in window defined by mask 22 22 // note that the mask is a SELECTION mask not an EXCLUSION mask 23 23 24 double F12 = 0.0; 25 double F22 = 0.0; 24 double R = 0.0, F1 = 0.0, F11 = 0.0, F12 = 0.0, F2 = 0.0; 26 25 for (i = 0; i < flux1->Nelements; i++) { 27 if ((mask & window->elements.Int[i]) == 0) continue;26 // if ((mask & window->elements.Int[i]) == 0) continue; 28 27 double weight = 1.0 / (SQ(dflux1->elements.Flt[i]) + SQ(dflux2->elements.Flt[i])); 28 R += weight; 29 F1 += flux1->elements.Flt[i] * weight; 30 F2 += flux2->elements.Flt[i] * weight; 31 F11 += flux1->elements.Flt[i] * flux1->elements.Flt[i] * weight; 29 32 F12 += flux1->elements.Flt[i] * flux2->elements.Flt[i] * weight; 30 F22 += flux2->elements.Flt[i] * flux2->elements.Flt[i] * weight;31 33 } 32 34 33 double Ao = F12 / F22; 34 double dA = sqrt(1.0 / F22); 35 int nterm = 2; 36 double **b = NULL, **c = NULL; 37 ALLOCATE (b, double *, nterm); 38 ALLOCATE (c, double *, nterm); 39 for (i = 0; i < nterm; i++) { 40 ALLOCATE (c[i], double, nterm); 41 ALLOCATE (b[i], double, 1); 42 } 43 c[0][0] = F11; 44 c[1][0] = c[0][1] = F1; 45 c[1][1] = R; 35 46 36 int Ndof = -1; // 1 parameter fit 47 b[0][0] = F12; 48 b[1][0] = F2; 49 50 if (!dgaussjordan (c, b, nterm, 1)) { 51 gprint (GP_ERR, "failed to fit data : ill-conditioned matrix\n"); 52 goto escape; 53 } 54 55 double Ao = b[0][0]; 56 double dA = sqrt(c[0][0]); 57 double Bo = b[1][0]; 58 double dB = sqrt(c[1][1]); 59 60 for (i = 0; i < nterm; i++) { 61 free (b[i]); 62 free (c[i]); 63 } 64 free (b); 65 free (c); 66 67 int Ndof = -2; // 2 parameter fit 37 68 double chisq = 0.0; 38 69 for (i = 0; i < flux1->Nelements; i++) { 39 70 if ((mask & window->elements.Int[i]) == 0) continue; 40 71 double weight = 1.0 / (SQ(dflux1->elements.Flt[i]) + SQ(dflux2->elements.Flt[i])); 41 chisq += SQ(flux1->elements.Flt[i] - Ao * flux2->elements.Flt[i] ) * weight;72 chisq += SQ(flux1->elements.Flt[i] - Ao * flux2->elements.Flt[i] - Bo) * weight; 42 73 Ndof ++; 43 74 } … … 45 76 double chisqNu = chisq / Ndof; 46 77 78 // fprintf (stderr, "R: %f, F1: %f, F11: %f, F2: %f, F12: %f\n", R, F1, F11, F2, F12); 47 79 // fprintf (stderr, "Ao: %f +/- %f, chisq: %f, chisq_nu : %f for %d dof\n", Ao, dA, chisq, chisqNu, Ndof); 48 80 set_variable ("Ao", Ao); 49 81 set_variable ("dA", dA); 82 set_variable ("Bo", Bo); 83 set_variable ("dB", dB); 50 84 set_variable ("Xv", chisqNu); 51 85 set_variable ("Nd", Ndof); -
trunk/Ohana/src/opihi/cmd.astro/transform.c
r34088 r39558 53 53 X = x; Y = y; 54 54 if ((X > -1) && (X < Nx) && (Y > -1) && (Y < Ny)) { 55 if (!isfinite(*Vin)) continue; 55 56 Vout[X + Y*Nx] += *Vin; 56 57 Sout[X + Y*Nx] ++; -
trunk/Ohana/src/opihi/cmd.data/Makefile
r39225 r39558 149 149 $(SRC)/tvcontour.$(ARCH).o \ 150 150 $(SRC)/tvgrid.$(ARCH).o \ 151 $(SRC)/type.$(ARCH).o \ 151 152 $(SRC)/uniq.$(ARCH).o \ 152 153 $(SRC)/unsign.$(ARCH).o \ -
trunk/Ohana/src/opihi/cmd.data/init.c
r39225 r39558 137 137 int tvcontour PROTO((int, char **)); 138 138 int tvgrid PROTO((int, char **)); 139 int opihi_type PROTO((int, char **)); 139 140 int uniq PROTO((int, char **)); 140 141 int unsign PROTO((int, char **)); … … 314 315 {1, "tvcontour", tvcontour, "send contour to image overlay"}, 315 316 {1, "tvgrid", tvgrid, "RA/DEC grid on an image"}, 317 {1, "type", opihi_type, "get scalar/vector/matrix type information"}, 316 318 {1, "ungridify", ungridify, "convert image region to vector triplet"}, 317 319 {1, "uniq", uniq, "create a uniq vector subset from a vector"}, -
trunk/Ohana/src/opihi/lib.shell/VariableOps.c
r18732 r39558 197 197 198 198 /* return TRUE / FALSE if name is an existant variable */ 199 // XXX is this function better than IsScalar? 200 # if (0) 199 201 int get_variable_exists (char *name) { 200 202 … … 205 207 return (FALSE); 206 208 } 209 # endif 207 210 208 211 float get_variable_default (char *name, float dvalue) { -
trunk/Ohana/src/opihi/lib.shell/convert_to_RPN.c
r38441 r39558 76 76 if (!strcmp (argv[i], "max")) { type = ST_BINARY; strcpy (argv[i], "U"); goto gotit; } 77 77 if (!strcmp (argv[i], "min")) { type = ST_BINARY; strcpy (argv[i], "D"); goto gotit; } 78 if (!strcmp (argv[i], "atan2")) { type = ST_BINARY; goto gotit; } 78 if (!strcmp (argv[i], "atan2")) { type = ST_BINARY; strcpy (argv[i], "a"); goto gotit; } 79 if (!strcmp (argv[i], "datan2")) { type = ST_BINARY; strcpy (argv[i], "d"); goto gotit; } 79 80 if (!strcmp (argv[i], ",")) { type = ST_COMMA; goto gotit; } 80 81 -
trunk/Ohana/src/opihi/lib.shell/stack_math.c
r38553 r39558 343 343 case '^': VV_FUNC(ST_SCALAR_FLT, pow (*M1, *M2)); 344 344 case '@': VV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, *M2)); 345 case 'a': VV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, *M2)); 345 case 'd': VV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, *M2)); 346 case 'a': VV_FUNC(ST_SCALAR_FLT, atan2 (*M1, *M2)); 346 347 case 'D': VV_FUNC(ST_SCALAR_INT, MIN (*M1, *M2)); 347 348 case 'U': VV_FUNC(ST_SCALAR_INT, MAX (*M1, *M2)); … … 454 455 case '^': SV_FUNC(ST_SCALAR_FLT, pow (M1, *M2)); 455 456 case '@': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2)); 456 case 'a': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2)); 457 case 'd': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2)); 458 case 'a': SV_FUNC(ST_SCALAR_FLT, atan2 (M1, *M2)); 457 459 case 'D': SV_FUNC(ST_SCALAR_INT, MIN (M1, *M2)); 458 460 case 'U': SV_FUNC(ST_SCALAR_INT, MAX (M1, *M2)); … … 561 563 case '^': VS_FUNC(ST_SCALAR_FLT, pow (*M1, M2)); 562 564 case '@': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2)); 563 case 'a': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2)); 565 case 'd': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2)); 566 case 'a': VS_FUNC(ST_SCALAR_FLT, atan2 (*M1, M2)); 564 567 case 'D': VS_FUNC(ST_SCALAR_INT, MIN (*M1, M2)); 565 568 case 'U': VS_FUNC(ST_SCALAR_INT, MAX (*M1, M2)); … … 652 655 case '^': MV_FUNC(pow (*M1, *M2)); 653 656 case '@': MV_FUNC(DEG_RAD*atan2 (*M1, *M2)); 654 case 'a': MV_FUNC(DEG_RAD*atan2 (*M1, *M2)); 657 case 'd': MV_FUNC(DEG_RAD*atan2 (*M1, *M2)); 658 case 'a': MV_FUNC( atan2 (*M1, *M2)); 655 659 case 'D': MV_FUNC(MIN (*M1, *M2)); 656 660 case 'U': MV_FUNC(MAX (*M1, *M2)); … … 745 749 case '^': VM_FUNC(pow (*M1, *M2)); 746 750 case '@': VM_FUNC(DEG_RAD*atan2 (*M1, *M2)); 747 case 'a': VM_FUNC(DEG_RAD*atan2 (*M1, *M2)); 751 case 'd': VM_FUNC(DEG_RAD*atan2 (*M1, *M2)); 752 case 'a': VM_FUNC( atan2 (*M1, *M2)); 748 753 case 'D': VM_FUNC(MIN (*M1, *M2)); 749 754 case 'U': VM_FUNC(MAX (*M1, *M2)); … … 825 830 case '^': MM_FUNC(pow (*M1, *M2)); 826 831 case '@': MM_FUNC(DEG_RAD*atan2 (*M1, *M2)); 827 case 'a': MM_FUNC(DEG_RAD*atan2 (*M1, *M2)); 832 case 'd': MM_FUNC(DEG_RAD*atan2 (*M1, *M2)); 833 case 'a': MM_FUNC( atan2 (*M1, *M2)); 828 834 case 'D': MM_FUNC(MIN (*M1, *M2)); 829 835 case 'U': MM_FUNC(MAX (*M1, *M2)); … … 910 916 case '^': MS_FUNC(pow (*M1, M2)); 911 917 case '@': MS_FUNC(DEG_RAD*atan2 (*M1, M2)); 912 case 'a': MS_FUNC(DEG_RAD*atan2 (*M1, M2)); 918 case 'd': MS_FUNC(DEG_RAD*atan2 (*M1, M2)); 919 case 'a': MS_FUNC( atan2 (*M1, M2)); 913 920 case 'D': MS_FUNC(MIN (*M1, M2)); 914 921 case 'U': MS_FUNC(MAX (*M1, M2)); … … 986 993 case '^': SM_FUNC(pow (M1, *M2)); 987 994 case '@': SM_FUNC(DEG_RAD*atan2 (M1, *M2)); 988 case 'a': SM_FUNC(DEG_RAD*atan2 (M1, *M2)); 995 case 'd': SM_FUNC(DEG_RAD*atan2 (M1, *M2)); 996 case 'a': SM_FUNC( atan2 (M1, *M2)); 989 997 case 'D': SM_FUNC(MIN (M1, *M2)); 990 998 case 'U': SM_FUNC(MAX (M1, *M2)); … … 1068 1076 case '^': SS_FUNC(ST_SCALAR_FLT, pow (M1, M2)); 1069 1077 case '@': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2)); 1070 case 'a': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2)); 1078 case 'd': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2)); 1079 case 'a': SS_FUNC(ST_SCALAR_FLT, atan2 (M1, M2)); 1071 1080 case 'D': SS_FUNC(ST_SCALAR_INT, MIN (M1, M2)); 1072 1081 case 'U': SS_FUNC(ST_SCALAR_INT, MAX (M1, M2));
Note:
See TracChangeset
for help on using the changeset viewer.
