Changeset 41340 for trunk/Ohana/src/opihi/cmd.data
- Timestamp:
- Apr 16, 2020, 1:54:47 PM (6 years ago)
- Location:
- trunk/Ohana/src/opihi/cmd.data
- Files:
-
- 16 deleted
- 23 edited
-
Makefile (modified) (9 diffs)
-
antialias.c (deleted)
-
create.c (modified) (2 diffs)
-
cut.c (modified) (6 diffs)
-
dbselect.c (modified) (2 diffs)
-
extract.c (modified) (5 diffs)
-
init.c (modified) (16 diffs)
-
interpolate_presort.c (modified) (3 diffs)
-
kapamemory.c (deleted)
-
list_vectors.c (modified) (1 diff)
-
match1d.c (deleted)
-
medimage_calc.c (deleted)
-
medimage_commands.c (modified) (3 diffs)
-
mgaussdev.c (deleted)
-
pdf.c (deleted)
-
peak.c (modified) (2 diffs)
-
print_vectors.c (modified) (1 diff)
-
queue2book.c (deleted)
-
read_vectors.c (modified) (12 diffs)
-
roll.c (modified) (2 diffs)
-
rotate.c (modified) (4 diffs)
-
spline.c (modified) (3 diffs)
-
spline_commands.c (modified) (7 diffs)
-
test/cut.sh (modified) (2 diffs)
-
test/delete.sh (modified) (1 diff)
-
test/headtest.sh (deleted)
-
test/medimage.sh (modified) (1 diff)
-
test/set.sh (deleted)
-
test/spline.sh (deleted)
-
test/vsigmoid.sh (deleted)
-
test/vstat.sh (deleted)
-
threshold.c (modified) (4 diffs)
-
tvcolors.c (modified) (1 diff)
-
vgauss.c (modified) (5 diffs)
-
virls.c (deleted)
-
vsigmoid.c (deleted)
-
vtransitions.c (deleted)
-
vwtmean.c (deleted)
-
write_vectors.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/Makefile
r41322 r41340 19 19 $(SRC)/init.$(ARCH).o \ 20 20 $(SRC)/accum.$(ARCH).o \ 21 $(SRC)/antialias.$(ARCH).o \22 21 $(SRC)/applyfit1d.$(ARCH).o \ 23 22 $(SRC)/applyfit2d.$(ARCH).o \ … … 79 78 $(SRC)/join.$(ARCH).o \ 80 79 $(SRC)/jpeg.$(ARCH).o \ 81 $(SRC)/kapamemory.$(ARCH).o \82 80 $(SRC)/kern.$(ARCH).o \ 83 81 $(SRC)/keyword.$(ARCH).o \ … … 91 89 $(SRC)/lookup.$(ARCH).o \ 92 90 $(SRC)/matrix.$(ARCH).o \ 93 $(SRC)/match1d.$(ARCH).o \94 91 $(SRC)/match2d.$(ARCH).o \ 95 92 $(SRC)/mkrgb.$(ARCH).o \ 96 93 $(SRC)/mcreate.$(ARCH).o \ 97 94 $(SRC)/medacc.$(ARCH).o \ 98 $(SRC)/mgaussdev.$(ARCH).o \99 95 $(SRC)/mget.$(ARCH).o \ 100 96 $(SRC)/mget3d.$(ARCH).o \ … … 103 99 $(SRC)/medimage.$(ARCH).o \ 104 100 $(SRC)/medimage_commands.$(ARCH).o \ 105 $(SRC)/medimage_calc.$(ARCH).o \106 101 $(SRC)/mset.$(ARCH).o \ 107 102 $(SRC)/needles.$(ARCH).o \ … … 117 112 $(SRC)/point.$(ARCH).o \ 118 113 $(SRC)/ps.$(ARCH).o \ 119 $(SRC)/pdf.$(ARCH).o \120 114 $(SRC)/print_vectors.$(ARCH).o \ 121 115 $(SRC)/mprint.$(ARCH).o \ … … 130 124 $(SRC)/queuesubstr.$(ARCH).o \ 131 125 $(SRC)/queueinit.$(ARCH).o \ 132 $(SRC)/queue2book.$(ARCH).o \133 126 $(SRC)/radial.$(ARCH).o \ 134 127 $(SRC)/rd.$(ARCH).o \ … … 176 169 $(SRC)/vgauss.$(ARCH).o \ 177 170 $(SRC)/vlorentz.$(ARCH).o \ 178 $(SRC)/vsigmoid.$(ARCH).o \179 171 $(SRC)/vellipse.$(ARCH).o \ 180 172 $(SRC)/vmaxwell.$(ARCH).o \ … … 184 176 $(SRC)/vzload.$(ARCH).o \ 185 177 $(SRC)/vpeaks.$(ARCH).o \ 186 $(SRC)/vtransitions.$(ARCH).o \187 178 $(SRC)/vpop.$(ARCH).o \ 188 179 $(SRC)/vroll.$(ARCH).o \ … … 191 182 $(SRC)/vsmooth.$(ARCH).o \ 192 183 $(SRC)/vstats.$(ARCH).o \ 193 $(SRC)/virls.$(ARCH).o \194 $(SRC)/vwtmean.$(ARCH).o \195 184 $(SRC)/xsection.$(ARCH).o \ 196 185 $(SRC)/vsh.$(ARCH).o \ -
trunk/Ohana/src/opihi/cmd.data/create.c
r41269 r41340 7 7 Vector *vec; 8 8 9 // create a vector of empty strings10 if ((N = get_argument (argc, argv, "-str"))) {11 remove_argument (N, &argc, argv);12 13 char *stringValue = NULL;14 if ((N = get_argument (argc, argv, "-value"))) {15 remove_argument (N, &argc, argv);16 stringValue = strcreate (argv[N]);17 remove_argument (N, &argc, argv);18 }19 20 if (argc != 3) {21 gprint (GP_ERR, "USAGE: create vector Nelements -value word\n");22 return (FALSE);23 }24 25 if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) return (FALSE);26 int Nelements = atoi (argv[2]);27 28 // a newly reset vector has NULL-valued pointers29 ResetVector (vec, OPIHI_STR, Nelements);30 for (int i = 0; i < Nelements; i++) {31 vec[0].elements.Str[i] = stringValue ? strcreate (stringValue) : strcreate ("");32 }33 return TRUE;34 }35 36 9 INT = FALSE; 37 10 if ((N = get_argument (argc, argv, "-int"))) { … … 43 16 gprint (GP_ERR, "USAGE: create vector start end [delta] [-int]\n"); 44 17 gprint (GP_ERR, " -int : resulting vector is integer type (delta must be integer)\n"); 45 gprint (GP_ERR, " -str : resulting vector is string type (only give number of elements)\n");46 18 return (FALSE); 47 19 } -
trunk/Ohana/src/opihi/cmd.data/cut.c
r41164 r41340 1 1 # include "data.h" 2 2 3 enum {SUM, MEAN, MEDIAN, INNER, NGOOD}; 4 5 double cutstat (float *value, int Nvalue, int mode) { 6 7 double output = 0.0; 8 9 if (Nvalue == 0) return NAN; 10 11 if (mode == MEDIAN) { 12 fsort (value, Nvalue); 13 if (Nvalue % 2) { 14 int Ncenter = Nvalue / 2; 15 myAssert ((Ncenter >= 0) && (Ncenter < Nvalue), "cutstat"); 16 output = value[Ncenter]; 17 } else { 18 int Ncenter = Nvalue / 2 - 1; 19 myAssert ((Ncenter >= 0) && (Ncenter < Nvalue - 1), "cutstat"); 20 output = 0.5*(value[Ncenter] + value[Ncenter + 1]); 21 } 22 return output; 23 } 24 if (mode == INNER) { 25 fsort (value, Nvalue); 26 27 int Ns = 0, Ne = 0; 28 if (Nvalue % 2) { 29 // for an odd number of points take the same number below 30 // and above the center value 31 int Ncenter = Nvalue / 2; 32 int Nquarter = 0.25*Nvalue; 33 Ns = Ncenter - Nquarter; 34 Ne = Ncenter + Nquarter; 35 } else { 36 // for an even number, the middle lies between two points 37 // take the same number below as above 38 int Ncenter = (int)(Nvalue / 2) - 1; 39 int Nquarter = 0.25*Nvalue; 40 Ns = Ncenter - Nquarter; 41 Ne = Ncenter + 1 + Nquarter; 42 } 43 int Nv = 0; 44 for (int i = Ns; i <= Ne; i++) { 45 myAssert ((i >= 0) && (i < Nvalue), "cutstat"); 46 output += value[i]; 47 Nv ++; 48 } 49 output /= Nv; 50 return output; 51 } 52 if (mode == NGOOD) { 53 return Nvalue; 54 } 55 if ((mode == MEAN) || (mode == SUM)) { 56 for (int i = 0; i < Nvalue; i++) { 57 myAssert ((i >= 0) && (i < Nvalue), "cutstat"); 58 output += value[i]; 59 } 60 if (mode == MEAN) { output /= Nvalue; } 61 return output; 62 } 63 return NAN; 64 } 3 enum {SUM, MEAN, MEDIAN}; 65 4 66 5 int cut (int argc, char **argv) { 67 6 68 7 int i, j, N, Nx, Ny, Mode; 69 float *Vin, *Vbuf ;8 float *Vin, *Vbuf, value; 70 9 int sx, sy, nx, ny; 71 10 Vector *xvec, *yvec; … … 73 12 74 13 Mode = SUM; 75 if ((N = get_argument (argc, argv, "-sum"))) {76 remove_argument (N, &argc, argv);77 Mode = SUM;78 }79 14 if ((N = get_argument (argc, argv, "-median"))) { 80 15 remove_argument (N, &argc, argv); … … 84 19 remove_argument (N, &argc, argv); 85 20 Mode = MEAN; 86 }87 if ((N = get_argument (argc, argv, "-inner"))) {88 remove_argument (N, &argc, argv);89 Mode = INNER;90 }91 if ((N = get_argument (argc, argv, "-ngood"))) {92 remove_argument (N, &argc, argv);93 Mode = NGOOD;94 21 } 95 22 … … 109 36 Ny = buf[0].matrix.Naxis[1]; 110 37 111 // ny & nx do not need to be constrained by the buffer, but they do need to be sensible 112 if ((nx < 0) || (ny < 0) || (nx > 1e8) || (ny > 1e8)) { 113 gprint (GP_ERR, "warning : extraction size is crazy: %d,%d\n", nx, ny); 38 if ((sx < 0) || (sy < 0) || (sx+nx > Nx) || (sy+ny > Ny)) { 39 gprint (GP_ERR, "region out of range\n"); 114 40 return (FALSE); 115 41 } … … 131 57 132 58 for (i = 0; i < nx; i++) { 133 / / for out-of-range areas, set the output pixels to NAN134 if (i + sx < 0) {135 yvec[0].elements.Flt[i] = NAN; 136 continue;59 /* accumulate values */ 60 Vin = (float *)(buf[0].matrix.buffer) + sy*Nx + sx + i; 61 for (j = 0; j < ny; j++, Vin += Nx) { 62 Vbuf[j] = *Vin; 137 63 } 138 if (i + sx >= Nx) { 139 yvec[0].elements.Flt[i] = NAN; 140 continue; 64 /* apply stat of choice */ 65 if (Mode == MEDIAN) { 66 fsort (Vbuf, ny); 67 value = Vbuf[(int)(0.5*ny)]; 68 } else { 69 value = 0; 70 for (j = 0; j < ny; j++) { 71 value += Vbuf[j]; 72 } 73 if (Mode == MEAN) { value /= ny; } 141 74 } 142 143 /* accumulate values */ 144 // skip out-of-range areas in y 145 if (sy < 0) { 146 ny += sy; 147 sy = 0; 148 } 149 if (sy > Ny) sy = Ny; 150 if (sy + ny >= Ny) ny = Ny - sy; 151 152 Vin = (float *)(buf[0].matrix.buffer) + sy*Nx + sx + i; 153 int Npix = 0; 154 for (j = 0; j < ny; j++, Vin += Nx) { 155 if (!isfinite(*Vin)) continue; 156 Vbuf[Npix] = *Vin; 157 Npix ++; 158 } 159 yvec[0].elements.Flt[i] = cutstat (Vbuf, Npix, Mode); 75 yvec[0].elements.Flt[i] = value; 160 76 } 161 77 free (Vbuf); … … 173 89 174 90 for (i = 0; i < ny; i++) { 175 / / for out-of-range areas, set the output pixels to NAN176 if (i + sy < 0) {177 yvec[0].elements.Flt[i] = NAN; 178 continue;91 /* accumulate values */ 92 Vin = (float *)(buf[0].matrix.buffer) + (sy + i)*Nx + sx; 93 for (j = 0; j < nx; j++, Vin ++) { 94 Vbuf[j] = *Vin; 179 95 } 180 if (i + sy >= Ny) { 181 yvec[0].elements.Flt[i] = NAN; 182 continue; 96 /* apply stat of choice */ 97 if (Mode == MEDIAN) { 98 fsort (Vbuf, nx); 99 value = Vbuf[(int)(0.5*nx)]; 100 } else { 101 value = 0; 102 for (j = 0; j < nx; j++) { 103 value += Vbuf[j]; 104 } 105 if (Mode == MEAN) { value /= nx; } 183 106 } 184 185 /* accumulate values */ 186 // skip out-of-range areas in x 187 if (sx < 0) { 188 nx += sx; 189 sx = 0; 190 } 191 if (sx > Nx) sx = Nx; 192 if (sx + nx >= Nx) nx = Nx - sx; 193 194 Vin = (float *)(buf[0].matrix.buffer) + (sy + i)*Nx + sx; 195 int Npix = 0; 196 for (j = 0; j < nx; j++, Vin ++) { 197 if (!isfinite(*Vin)) continue; 198 Vbuf[Npix] = *Vin; 199 Npix ++; 200 } 201 yvec[0].elements.Flt[i] = cutstat (Vbuf, Npix, Mode); 107 yvec[0].elements.Flt[i] = value; 202 108 } 203 109 free (Vbuf); -
trunk/Ohana/src/opihi/cmd.data/dbselect.c
r41283 r41340 80 80 case FIELD_TYPE_DOUBLE: 81 81 case FIELD_TYPE_TIME: 82 case FIELD_TYPE_TIMESTAMP:83 82 case FIELD_TYPE_DATE: 84 83 case FIELD_TYPE_DATETIME: … … 116 115 break; 117 116 case FIELD_TYPE_TIME: 118 case FIELD_TYPE_TIMESTAMP:119 117 case FIELD_TYPE_DATE: 120 118 case FIELD_TYPE_DATETIME: -
trunk/Ohana/src/opihi/cmd.data/extract.c
r41164 r41340 1 1 # include "data.h" 2 3 /* <from> : source image, must exist4 <to> : target image -- if it does not exist, it is created of size (Nx,Ny)5 sx, sy : source starting coordinate -- need not be on a valid image pixel6 nx, ny : number of source pixels -- currently must not go out of bounds -> allow out-of-bounds7 Sx, Sy : target starting coordinate -- need not be on a valid image pixel8 Nx, Ny : redundant information UNLESS <to> does exist (in which case it is required information) -> make Nx,Ny optional if <to> exists?9 */10 2 11 3 int extract (int argc, char **argv) { 12 4 13 int N; 5 int i, j; 6 float *Vin, *Vout; 7 int sx, sy, nx, ny, NX, NY; 8 int Sx, Sy, Nx, Ny; 14 9 Buffer *in, *out; 15 16 float initValue = 0.0;17 int initOutput = FALSE;18 if ((N = get_argument (argc, argv, "-init"))) {19 remove_argument (N, &argc, argv);20 initValue = atof (argv[N]);21 remove_argument (N, &argc, argv);22 initOutput = TRUE;23 }24 10 25 11 if (argc != 11) { … … 29 15 30 16 if ((in = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE); 31 intNX = in[0].matrix.Naxis[0];32 intNY = in[0].matrix.Naxis[1];17 NX = in[0].matrix.Naxis[0]; 18 NY = in[0].matrix.Naxis[1]; 33 19 34 intsx = atof (argv[3]);35 intsy = atof (argv[4]);36 intnx = atof (argv[5]);37 intny = atof (argv[6]);20 sx = atof (argv[3]); 21 sy = atof (argv[4]); 22 nx = atof (argv[5]); 23 ny = atof (argv[6]); 38 24 39 intSx = atof (argv[7]);40 intSy = atof (argv[8]);41 intNx = atof (argv[9]);42 intNy = atof (argv[10]);25 Sx = atof (argv[7]); 26 Sy = atof (argv[8]); 27 Nx = atof (argv[9]); 28 Ny = atof (argv[10]); 43 29 44 30 if ((Sy + ny > Ny) || (Sx + nx > Nx)) { 45 gprint (GP_ERR, " source pixels extend beyond target pixels\n");31 gprint (GP_ERR, "mismatch between source and dest regions\n"); 46 32 gprint (GP_ERR, "%d + %d > %d or %d + %d > %d\n", Sy, ny, Ny, Sx, nx, Nx); 47 //return (FALSE);33 return (FALSE); 48 34 } 49 50 // XXX : allow source region to fall outside source image51 35 52 36 /* region is not on first image */ … … 55 39 (sy > in[0].matrix.Naxis[1])) { 56 40 gprint (GP_ERR, "region outside of source image\n"); 57 //return (FALSE);41 return (FALSE); 58 42 } 59 43 44 if ((Sx + nx > Nx) || (Sy + ny > Ny)) { 45 gprint (GP_ERR, "source region larger than dest region\n"); 46 return (FALSE); 47 } 60 48 if ((Sx < 0) || (Sy < 0)) { 61 49 gprint (GP_ERR, "dest region out of range\n"); 62 //return (FALSE);50 return (FALSE); 63 51 } 64 52 … … 88 76 } 89 77 90 // (NX,NY) : source image dimensions 91 // (Nx,Ny) : target image dimensions 92 93 // allow (sx, sy), (Sx, Sy) to be off image 94 // allow (sx+nx, sy+ny) to be off image 95 96 // if (sx < 0) { 97 // nx += sx; 98 // sx = 0; 99 // } 100 // if (sx > NX) sx = NX; 101 // 102 // if (Sx < 0) { 103 // Nx += sx; 104 // sx = 0; 105 // } 106 // if (sx > NX) sx = NX; 107 108 float *Vin = (float *)(in[0].matrix.buffer); 109 float *Vout = (float *)(out[0].matrix.buffer); 110 111 if (initOutput) { 112 for (int j = 0; j < Ny; j++) { 113 for (int i = 0; i < Nx; i++) { 114 Vout[i + Nx*j] = initValue; 115 } 116 } 117 } 118 119 int Nps = NX*NY; 120 int Npt = Nx*Ny; 121 122 for (int j = 0; j < ny; j++) { 123 if (j + sy < 0) continue; // not yet on source image 124 if (j + Sy < 0) continue; // not yet on target image 125 if (j + sy >= NY) continue; // past edge of source image 126 if (j + Sy >= Ny) continue; // past edge of target image 127 128 // Vin = (float *)(in[0].matrix.buffer) + (j + sy)*in[0].matrix.Naxis[0] + sx; 129 // Vout = (float *)(out[0].matrix.buffer) + (j + Sy)*out[0].matrix.Naxis[0] + Sx; 130 131 for (int i = 0; i < nx; i++) { 78 for (j = 0; j < ny; j++) { 79 if (j + sy < 0) continue; 80 if (j + sy >= NY) continue; 81 Vin = (float *)(in[0].matrix.buffer) + (j + sy)*in[0].matrix.Naxis[0] + sx; 82 Vout = (float *)(out[0].matrix.buffer) + (j + Sy)*out[0].matrix.Naxis[0] + Sx; 83 for (i = 0; i < nx; i++, Vin++, Vout++) { 132 84 if (i + sx < 0) continue; 133 85 if (i + sx >= NX) continue; 134 if (i + Sx < 0) continue; 135 if (i + Sx >= Nx) continue; 136 137 int ps = i + sx + (j + sy)*NX; 138 int pt = i + Sx + (j + Sy)*Nx; 139 140 myAssert (pt >= 0, "oops 1"); 141 myAssert (pt < Npt, "oops 2"); 142 143 myAssert (ps >= 0, "oops 3"); 144 myAssert (ps < Nps, "oops 4"); 145 146 Vout[pt] = Vin[ps]; 86 *Vout = *Vin; 147 87 } 148 88 } … … 151 91 152 92 } 93 -
trunk/Ohana/src/opihi/cmd.data/init.c
r41322 r41340 3 3 4 4 int accum PROTO((int, char **)); 5 int antialias PROTO((int, char **));6 5 int applyfit PROTO((int, char **)); 7 6 int applyfit1d PROTO((int, char **)); … … 68 67 int join PROTO((int, char **)); 69 68 int jpeg PROTO((int, char **)); 70 int kapamemory PROTO((int, char **));71 69 int kern PROTO((int, char **)); 72 70 int keyword PROTO((int, char **)); … … 81 79 int lookup PROTO((int, char **)); 82 80 int matrix PROTO((int, char **)); 83 int match1d PROTO((int, char **));84 81 int match2d PROTO((int, char **)); 85 82 int mkrgb PROTO((int, char **)); 86 83 int mcreate PROTO((int, char **)); 87 84 int medacc PROTO((int, char **)); 88 int mgaussdev PROTO((int, char **));89 85 int mget PROTO((int, char **)); 90 86 int mget3d PROTO((int, char **)); … … 103 99 int parity PROTO((int, char **)); 104 100 int point PROTO((int, char **)); 105 int pdf PROTO((int, char **));106 101 int ps PROTO((int, char **)); 107 102 int vprint PROTO((int, char **)); … … 116 111 int queuesubstr PROTO((int, char **)); 117 112 int queuesize PROTO((int, char **)); 118 int queue2book PROTO((int, char **));119 113 int rd PROTO((int, char **)); 120 114 int rdseg PROTO((int, char **)); … … 162 156 int vgauss PROTO((int, char **)); 163 157 int vlorentz PROTO((int, char **)); 164 int vsigmoid PROTO((int, char **));165 158 int vellipse PROTO((int, char **)); 166 159 int vmaxwell PROTO((int, char **)); … … 170 163 int vzload PROTO((int, char **)); 171 164 int vstats PROTO((int, char **)); 172 int vstats PROTO((int, char **));173 int virls PROTO((int, char **));174 int vwtmean PROTO((int, char **));175 165 int vroll PROTO((int, char **)); 176 166 int vshift PROTO((int, char **)); 177 167 int vpeaks PROTO((int, char **)); 178 int vtransitions PROTO((int, char **));179 168 int vpop PROTO((int, char **)); 180 169 int vsmooth PROTO((int, char **)); … … 198 187 static Command cmds[] = { 199 188 {1, "accum", accum, "accumulate vector values in another vector"}, 200 {1, "antialias", antialias, "set anti-alias sigma value for display"},201 189 {1, "applyfit", applyfit1d, "apply 1-d fit to new vector"}, 202 190 {1, "applyfit1d", applyfit1d, "apply 1-d fit to new vector"}, … … 267 255 {1, "join", join, "find the join of two ID vectors"}, 268 256 {1, "jpeg", jpeg, "convert display image to JPEG"}, 269 {1, "kapamemory", kapamemory, "manage kapa memory dump options"},270 257 {1, "kern", kern, "convolve with 3x3 kernel"}, 271 258 {1, "keyword", keyword, "extract a FITS keyword from image header"}, … … 278 265 {1, "imcreate", mcreate, "create an image"}, 279 266 {1, "medacc", medacc, "accumulate vector values in another vector"}, 280 {1, "mgaussdev", mgaussdev, "generate a gaussian deviate image"},281 267 {1, "mget", mget, "extract a vector from an image"}, 282 268 {1, "mget3d", mget3d, "extract a vector from a 3D image"}, … … 287 273 {1, "medimage", medimage_command, "median image manipulation"}, 288 274 {1, "matrix", matrix, "matrix math operations"}, 289 {1, "match1d", match1d, "match 2 vectors and return matched indexes"},290 275 {1, "match2d", match2d, "match 2 pairs of X,Y vectors and return matched indexes"}, 291 276 {1, "mkrgb", mkrgb, "convert 3 images to rgb jpeg (use Kapa for better control)"}, … … 304 289 {1, "ppm", jpeg, "convert display graphic to PPM"}, 305 290 {1, "ps", ps, "convert display to PostScript"}, 306 {1, "pdf", pdf, "convert display to PDF"},307 291 {1, "print_vectors", vprint, "print a set of vectors"}, 308 292 {1, "vprint", vprint, "print a set of vectors"}, … … 317 301 {1, "queuesize", queuesize, "show queue size"}, 318 302 {1, "queuesubstr", queuesubstr, "bulk replace strings in queue"}, 319 {1, "queue2book", queue2book, "convert queue with ipptool output to book"},320 {1, "ipptool2book", queue2book, "convert queue with ipptool output to book"},321 303 {1, "rd", rd, "load fits image"}, 322 304 {1, "rdseg", rdseg, "read a segment of an image from a file"}, … … 365 347 {1, "vgauss", vgauss, "fit a Gaussian to a vector"}, 366 348 {1, "vlorentz", vlorentz, "fit a Lorentzian to a vector"}, 367 {1, "vsigmoid", vsigmoid, "fit a Sigmoid to a vector"},368 349 {1, "vellipse", vellipse, "fit a Ellipse to a vector pair"}, 369 350 {1, "vgrid", vgrid, "generate an image from a triplet of vectors"}, … … 373 354 {1, "vload", vload, "load vectors as overlay on image display"}, 374 355 {1, "vmaxwell", vmaxwell, "fit a Maxwellian to a vector"}, 375 {1, "vpeaks", vpeaks, "find coord and flux of peaks in vector"}, 376 {1, "vtransitions", vtransitions, "find points in vector that cross the transition value"}, 356 {1, "vpeaks", vpeaks, "fine coord and flux of peaks in vector"}, 377 357 {1, "vpop", vpop, "remove first element of a vector"}, 378 358 {1, "vroll", vroll, "roll vector elements by 1 entry"}, … … 380 360 {1, "vsmooth", vsmooth, "Gaussian smooth of a vector"}, 381 361 {1, "vstats", vstats, "statistics on a vector"}, 382 {1, "vwtmean", vwtmean, "weighted mean of a vector"},383 {1, "virls", virls, "IRLS mean of a vector"},384 362 {1, "vzload", vzload, "load vectors as overlay on image display (scaled points)"}, 385 363 {1, "vsh", vsh, "Vector Spherical Harmonics"}, -
trunk/Ohana/src/opihi/cmd.data/interpolate_presort.c
r41164 r41340 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 }16 9 17 10 /** check basic syntax **/ … … 43 36 y0 = yin[0].elements.Flt[0]; 44 37 45 // fill in the start with NANs 46 for (i = 0; (i < xout[0].Nelements) && (xout[0].elements.Flt[i] < xin[0].elements.Flt[0]); i++) { 47 yout[0].elements.Flt[i] = FillEnds ? yin[0].elements.Flt[0] : NAN; 48 } 38 /* in and out vectors are sorted */ 39 j = 0; 49 40 50 41 // every output pixel should get a value unless 51 42 // we are below the lowest in or above the highest in 52 for ( j = 0; (i < xout[0].Nelements) && (j < xin[0].Nelements - 1); ) {43 for (i = 0, j = 0; (i < xout[0].Nelements) && (j < xin[0].Nelements - 1); ) { 53 44 54 45 yout[0].elements.Flt[i] = NAN; … … 75 66 76 67 // fill in the rest with NANs 77 int NinLast = xin[0].Nelements - 1;78 68 while (i < yout[0].Nelements) { 79 yout[0].elements.Flt[i] = FillEnds ? yin[0].elements.Flt[NinLast] :NAN;69 yout[0].elements.Flt[i] = NAN; 80 70 i++; 81 71 } 82 72 83 73 return (TRUE); 74 84 75 } -
trunk/Ohana/src/opihi/cmd.data/list_vectors.c
r41269 r41340 32 32 } 33 33 34 switch (vec->type) { 35 case OPIHI_FLT: 36 if (Variable) { 37 set_str_variable (Variable, "FLT"); 38 } else { 39 gprint (GP_LOG, "%s : FLT\n", argv[1]); 40 } 41 break; 42 case OPIHI_INT: 43 if (Variable) { 44 set_str_variable (Variable, "INT"); 45 } else { 46 gprint (GP_LOG, "%s : INT\n", argv[1]); 47 } 48 break; 49 case OPIHI_STR: 50 if (Variable) { 51 set_str_variable (Variable, "STR"); 52 } else { 53 gprint (GP_LOG, "%s : STR\n", argv[1]); 54 } 55 break; 34 if (vec->type == OPIHI_FLT) { 35 if (Variable) { 36 set_str_variable (Variable, "FLT"); 37 } else { 38 gprint (GP_LOG, "%s : FLT\n", argv[1]); 39 } 40 } else { 41 if (Variable) { 42 set_str_variable (Variable, "INT"); 43 } else { 44 gprint (GP_LOG, "%s : INT\n", argv[1]); 45 } 56 46 } 57 47 if (Variable) free (Variable); -
trunk/Ohana/src/opihi/cmd.data/medimage_commands.c
r41164 r41340 15 15 int medimage_add (int argc, char **argv) { 16 16 17 int N;18 17 Buffer *image; 19 Buffer *var = NULL; 20 21 if ((N = get_argument (argc, argv, "-variance"))) { 22 remove_argument (N, &argc, argv); 23 if ((var = SelectBuffer (argv[N], OLDBUFFER, TRUE)) == NULL) return (FALSE); 24 remove_argument (N, &argc, argv); 25 } 26 27 if (argc != 3) { 28 gprint (GP_ERR, "USAGE: medimage add (name) (image) [-variance variance]\n"); 18 19 if (argc != 3) { 20 gprint (GP_ERR, "USAGE: medimage add (name) (image)\n"); 29 21 gprint (GP_ERR, " add the given image to the set of images to be medianed\n"); 30 gprint (GP_ERR, " optionally supply variance image (for weighted calculations)\n");31 22 return FALSE; 32 23 } 33 24 34 25 if ((image = SelectBuffer (argv[2], OLDBUFFER, TRUE)) == NULL) return (FALSE); 35 36 if (var) {37 if ((var->matrix.Naxis[0] != image->matrix.Naxis[0]) ||38 (var->matrix.Naxis[1] != image->matrix.Naxis[1])) {39 gprint (GP_ERR, "variance buffer does not match image buffer dimensions\n");40 return FALSE;41 }42 }43 26 44 27 MedImageType *median = FindMedImage (argv[1]); … … 63 46 // new image should match existing medimage dimensions 64 47 65 // AddMedImage (median, image, var);66 48 int Ninput = median->Ninput; 67 49 median->Ninput ++; 68 REALLOCATE (median->flx, float *, median->Ninput); 69 REALLOCATE (median->var, float *, median->Ninput); 70 71 ALLOCATE (median->flx[Ninput], float, median->Nx*median->Ny); 72 memcpy (median->flx[Ninput], image->matrix.buffer, sizeof(float)*median->Nx*median->Ny); 73 74 median->var[Ninput] = NULL; 75 if (var) { 76 ALLOCATE (median->var[Ninput], float, median->Nx*median->Ny); 77 memcpy (median->var[Ninput], var->matrix.buffer, sizeof(float)*median->Nx*median->Ny); 50 REALLOCATE (median->buffers, float *, median->Ninput); 51 52 ALLOCATE (median->buffers[Ninput], float, median->Nx*median->Ny); 53 memcpy (median->buffers[Ninput], image->matrix.buffer, sizeof(float)*median->Nx*median->Ny); 54 55 return TRUE; 56 } 57 58 int medimage_calc (int argc, char **argv) { 59 60 int ix, iy, n, N; 61 Buffer *output; 62 63 int CALC_MEAN = FALSE; 64 if ((N = get_argument (argc, argv, "-mean"))) { 65 CALC_MEAN = TRUE; 66 remove_argument (N, &argc, argv); 67 } 68 69 if (argc != 3) { 70 gprint (GP_ERR, "USAGE: medimage calc (name) (output) [-mean]\n"); 71 gprint (GP_ERR, " calculate the median image for the median image set\n"); 72 return FALSE; 73 } 74 75 MedImageType *median = FindMedImage (argv[1]); 76 if (!median) { 77 gprint (GP_ERR, "median image %s not found\n", argv[1]); 78 return FALSE; 79 } 80 81 if ((output = SelectBuffer (argv[2], ANYBUFFER, TRUE)) == NULL) return (FALSE); 82 83 int Ninput = median->Ninput; 84 int Nx = median->Nx; 85 int Ny = median->Ny; 86 87 float *value = NULL; 88 ALLOCATE (value, float, Ninput); 89 90 gfits_free_matrix (&output->matrix); 91 gfits_free_header (&output->header); 92 if (!CreateBuffer (output, Nx, Ny, -32, 0.0, 1.0)) return FALSE; 93 94 float *outvalue = (float *) output->matrix.buffer; 95 96 for (iy = 0; iy < Ny; iy++) { 97 for (ix = 0; ix < Nx; ix++) { 98 99 int N = 0; 100 int Npix = ix + Nx*iy; 101 for (n = 0; n < Ninput; n++) { 102 float v = median->buffers[n][Npix]; 103 if (!isfinite(v)) continue; 104 value[N] = v; 105 N++; 106 } 107 if (N == 0) continue; 108 109 if (CALC_MEAN) { 110 float sum = 0.0; 111 for (n = 0; n < N; n++) { 112 sum += value[n]; 113 } 114 outvalue[Npix] = sum / (float) N; 115 } else { 116 fsort (value, N); 117 outvalue[Npix] = value[(int)(0.5*N)]; 118 } 119 } 78 120 } 79 121 … … 82 124 83 125 /* 84 int medimage_save (int argc, char **argv) {85 86 int N;87 88 int APPEND = FALSE;89 if ((N = get_argument (argc, argv, "-append"))) {90 APPEND = TRUE;91 remove_argument (N, &argc, argv);92 }93 94 if (argc != 3) {95 gprint (GP_ERR, "USAGE: medimage save (name) (filename) [-append]\n");96 return FALSE;97 }98 99 if (!SaveMedImage(argv[2], argv[1], APPEND)) {100 gprint (GP_ERR, "failed to save medimage %s\n", argv[1]);101 return (FALSE);102 }103 return TRUE;104 }105 106 int medimage_load (int argc, char **argv) {107 108 if (argc != 3) {109 gprint (GP_ERR, "USAGE: medimage load (name) (filename)\n");110 return FALSE;111 }112 113 if (!LoadMedImage(argv[2], argv[1])) {114 gprint (GP_ERR, "failed to load medimage %s\n", argv[1]);115 return (FALSE);116 }117 return TRUE;118 }126 int medimage_save (int argc, char **argv) { 127 128 int N; 129 130 int APPEND = FALSE; 131 if ((N = get_argument (argc, argv, "-append"))) { 132 APPEND = TRUE; 133 remove_argument (N, &argc, argv); 134 } 135 136 if (argc != 3) { 137 gprint (GP_ERR, "USAGE: medimage save (name) (filename) [-append]\n"); 138 return FALSE; 139 } 140 141 if (!SaveMedImage(argv[2], argv[1], APPEND)) { 142 gprint (GP_ERR, "failed to save medimage %s\n", argv[1]); 143 return (FALSE); 144 } 145 return TRUE; 146 } 147 148 int medimage_load (int argc, char **argv) { 149 150 if (argc != 3) { 151 gprint (GP_ERR, "USAGE: medimage load (name) (filename)\n"); 152 return FALSE; 153 } 154 155 if (!LoadMedImage(argv[2], argv[1])) { 156 gprint (GP_ERR, "failed to load medimage %s\n", argv[1]); 157 return (FALSE); 158 } 159 return TRUE; 160 } 119 161 */ 120 162 -
trunk/Ohana/src/opihi/cmd.data/peak.c
r41164 r41340 39 39 if (*X < start) continue; 40 40 if (*X > end) continue; 41 if (!isfinite(*Y)) continue;42 41 if (*Y < ymax) continue; 43 42 xmax = *X; … … 64 63 if (*X < start) continue; 65 64 if (*X > end) continue; 66 if (!isfinite(*Y)) continue;67 65 if (*Y < ymax) continue; 68 66 xmax = *X; -
trunk/Ohana/src/opihi/cmd.data/print_vectors.c
r41269 r41340 56 56 if (vec[i][0].type == OPIHI_FLT) { 57 57 gprint (GP_LOG, "%f ", vec[i][0].elements.Flt[j]); 58 } 59 if (vec[i][0].type == OPIHI_INT) { 58 } else { 60 59 gprint (GP_LOG, OPIHI_INT_FMT" ", vec[i][0].elements.Int[j]); 61 } 62 if (vec[i][0].type == OPIHI_STR) { 63 gprint (GP_LOG, "%s ", vec[i][0].elements.Str[j]); 64 } 60 } 65 61 } 66 62 } -
trunk/Ohana/src/opihi/cmd.data/read_vectors.c
r41305 r41340 35 35 36 36 // vector types 37 enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME, COLTYPE_ DATE, COLTYPE_CHAR, COLTYPE_STR, COLTYPE_HMS};37 enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME, COLTYPE_CHAR}; 38 38 39 39 static int Nvec = 0; … … 91 91 gprint (GP_ERR, " -skip N : skip N lines before reading\n"); 92 92 gprint (GP_ERR, " column names may include a type: name:type\n"); 93 gprint (GP_ERR, " type is int, float, char, str, time, date, hms\n");93 gprint (GP_ERR, " type is int, float, char, time\n"); 94 94 gprint (GP_ERR, " for char, values are placed into a list $name:0 - $name:n\n"); 95 gprint (GP_ERR, " for str, values are placed into a string-typed vector\n");96 gprint (GP_ERR, " for hms, values are sexigesimal values HH:MM:SS (good for degrees as well)\n");97 gprint (GP_ERR, " for date, values are human-readable date strings YYYY/MM/DD\n");98 95 gprint (GP_ERR, " for time, values are human-readable date/time strings YYYY/MM/DD,hh:mm:ss\n"); 99 gprint (GP_ERR, " date & time values are stored as a float using the TIMEFORMAT, TIMEREF values for the conversion\n");96 gprint (GP_ERR, " the resulting vector is a float based on the TIMEFORMAT, TIMEREF values\n"); 100 97 101 98 gprint (GP_ERR, " -fits options:\n"); … … 155 152 if (!strcasecmp(ptr, "int")) { coltype[i] = COLTYPE_INT; } 156 153 if (!strcasecmp(ptr, "char")) { coltype[i] = COLTYPE_CHAR; } 157 if (!strcasecmp(ptr, "str")) { coltype[i] = COLTYPE_STR; }158 if (!strcasecmp(ptr, "date")) { coltype[i] = COLTYPE_DATE; }159 154 if (!strcasecmp(ptr, "time")) { coltype[i] = COLTYPE_TIME; } 160 if (!strcasecmp(ptr, "hms")) { coltype[i] = COLTYPE_HMS; }161 155 if (!coltype[i]) goto bad_colname; 162 156 } … … 216 210 break; 217 211 case COLTYPE_FLT: 218 case COLTYPE_HMS:219 212 case COLTYPE_TIME: 220 case COLTYPE_DATE: 213 // note that COLTYPE_TIME is a type of float 221 214 ResetVector (vec[i], OPIHI_FLT, NELEM); 222 break;223 case COLTYPE_STR:224 ResetVector (vec[i], OPIHI_STR, NELEM);225 215 break; 226 216 case COLTYPE_CHAR: … … 297 287 time_t tvalue; 298 288 int readStatus = FALSE; 299 int dataStatus = FALSE;300 289 // need to make the if cases for coltype[i] 301 290 switch (coltype[i]) { … … 322 311 break; 323 312 } 324 case COLTYPE_STR:325 {326 // I need to get an isolated word in 'value' with the string value of this field327 char *ptr = IsCSV ? ptrparse_csv (col[i], c0) : ptrparse (col[i], c0);328 char *value = NULL;329 if (IsCSV) {330 char *end = parse_nextword_csv (ptr);331 if (end) {332 value = end ? strncreate (ptr, end - ptr) : strcreate (ptr);333 }334 } else {335 value = thisword(ptr);336 }337 vec[i][0].elements.Str[Nelem] = value; // needs to be freed later.338 break;339 }340 313 case COLTYPE_FLT: 341 314 readStatus = IsCSV ? dparse_csv (&dvalue, col[i], c0) : dparse (&dvalue, col[i], c0); … … 347 320 vec[i][0].elements.Flt[Nelem] = readStatus ? dvalue : NAN; 348 321 break; 349 case COLTYPE_DATE: {350 char *string = NULL;351 if (IsCSV) {352 char *ptr = ptrparse_csv (col[i], c0);353 string = strcreate (ptr); // create separate string (NULL-safe)354 ptr = (string == NULL) ? NULL : strchr (string, ',');355 if (ptr != NULL) *ptr = 0; // place an EOL here so parsing does not go past the comma356 } else {357 char *ptr = ptrparse (col[i], c0); // NULL-safe358 string = getword (ptr); // NULL-safe359 }360 tvalue = ohana_date_to_sec (string); // NULL-safe (returns 0)361 dvalue = TimeValue (tvalue, TimeReference, TimeFormat);362 vec[i][0].elements.Flt[Nelem] = string ? dvalue : NAN;363 FREE (string);364 break;365 }366 case COLTYPE_HMS: {367 char *ptr = IsCSV ? ptrparse_csv (col[i], c0) : ptrparse (col[i], c0);368 char *string = strcreate (ptr); // make a copy so we can munge it in ohana_dms_to_ddd369 dataStatus = ohana_dms_to_ddd (&dvalue, string);370 vec[i][0].elements.Flt[Nelem] = ((string != NULL) && dataStatus) ? dvalue : NAN;371 FREE (string);372 break;373 }374 322 } 375 323 if (!readStatus && VERBOSE) { … … 397 345 break; 398 346 case COLTYPE_FLT: 399 case COLTYPE_HMS:400 347 case COLTYPE_TIME: 401 case COLTYPE_DATE:402 348 ResetVector (vec[i], OPIHI_FLT, NELEM); 403 break;404 case COLTYPE_STR:405 ResetVector (vec[i], OPIHI_STR, NELEM);406 349 break; 407 350 case COLTYPE_CHAR: … … 423 366 break; 424 367 case COLTYPE_FLT: 425 case COLTYPE_HMS:426 368 case COLTYPE_TIME: 427 case COLTYPE_DATE:428 369 ResetVector (vec[i], OPIHI_FLT, Nelem); 429 break;430 case COLTYPE_STR:431 ResetVector (vec[i], OPIHI_STR, Nelem);432 370 break; 433 371 case COLTYPE_CHAR: … … 531 469 } 532 470 533 // by default, we now store a string-type field as a string-type vector. 534 535 // if CharAsList is selected (and My < 10000), char fields will be saved as $NAME:0 - $NAME:m for m rows 536 537 // if CharAsVectors is selected, char fields will be saved as vectors NAME:0 -- NAME:n for n characters 538 471 // if CharAsVectors, char fields will be saved as vectors NAME:0 -- NAME:n for n characters 472 // else char fields will be saved as $NAME:0 - $NAME:m for m rows 539 473 // if (Ny > 10000), force CharAsVectors 540 474 int CharAsVectors = FALSE; … … 542 476 remove_argument (N, &argc, argv); 543 477 CharAsVectors = TRUE; 544 }545 int CharAsList = FALSE;546 if ((N = get_argument (argc, argv, "-char-list"))) {547 remove_argument (N, &argc, argv);548 CharAsList = TRUE;549 478 } 550 479 … … 722 651 if (!FITS_TRANSPOSE) { 723 652 // read string column into a list rather than a vector 724 if (!strcmp (type, "char")) { 725 // save char-type field as a List: 726 if (CharAsList && (Ny < 3000)) { 727 char *fieldName = argv[i]; 728 char *Ptr = data; 729 char varname[1024]; // used as a buffer for the names of string fields 730 for (j = 0; j < Ny; j++) { 731 set_list_varname (varname, fieldName, j, FALSE); 732 char *value = strncreate (&Ptr[j*Nval], Nval); 733 // replace instances of $ with _ 734 char *p = strchr (value, '$'); 735 while (p) { 736 *p = '_'; 737 p = strchr (p, '$'); 738 } 739 set_str_variable (varname, value); 740 free (value); 653 if (!strcmp (type, "char") && !CharAsVectors && (Ny < 3000)) { 654 char *fieldName = argv[i]; 655 char *Ptr = data; 656 char varname[1024]; // used as a buffer for the names of string fields 657 for (j = 0; j < Ny; j++) { 658 set_list_varname (varname, fieldName, j, FALSE); 659 char *value = strncreate (&Ptr[j*Nval], Nval); 660 // replace instances of $ with _ 661 char *p = strchr (value, '$'); 662 while (p) { 663 *p = '_'; 664 p = strchr (p, '$'); 741 665 } 742 sprintf (varname, "%s:n", fieldName); 743 set_int_variable (varname, Ny); 744 continue; 666 set_str_variable (varname, value); 667 free (value); 745 668 } 746 // save char-type field as a string-type vector: 747 if (!CharAsVectors) { 748 Vector *myVector = NULL; 749 sprintf (name, "%s", argv[i]); 750 if ((myVector = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name\n"); 751 ResetVector (myVector, OPIHI_STR, Ny); 752 753 char *Ptr = data; 754 for (j = 0; j < Ny; j++) { 755 myVector[0].elements.Str[j] = strncreate (&Ptr[j*Nval], Nval); 756 // replace instances of $ with _ 757 char *p = strchr (myVector[0].elements.Str[j], '$'); 758 while (p) { *p = '_'; p = strchr (p, '$'); } 759 } 760 continue; 761 } 669 sprintf (varname, "%s:n", fieldName); 670 set_int_variable (varname, Ny); 671 continue; 762 672 } 763 673 764 674 // define the multifield vector names (Nval vectors x Ny elements) 765 // CharAsVectors is handled below automatically766 675 ALLOCATE (vec, Vector *, Nval); 767 676 for (j = 0; j < Nval; j++) { -
trunk/Ohana/src/opihi/cmd.data/roll.c
r41164 r41340 3 3 int roll (int argc, char **argv) { 4 4 5 int Nbytes, Nextra; 6 int dX, dx, dy, nx, ny; 5 7 Buffer *buf; 6 7 // this function is probably not needed8 gprint (GP_ERR, "ERROR: use 'shift' instead of 'roll'\n");9 return (FALSE);10 8 11 9 if (argc != 4) { … … 16 14 if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE); 17 15 18 int dx = atoi (argv[2]); 19 int dy = atoi (argv[3]); 20 21 /* if (dx,dy < 0), we are moving the start position backwards, 22 if (dx,dy > 0), we are moving the start position forward */ 23 24 int Nx = buf[0].matrix.Naxis[0]; 25 int Ny = buf[0].matrix.Naxis[1]; 26 27 if (dy == 0) { 28 // moves in just dx can be done row-by-row 29 30 int dX = abs(dx); 31 int Nbytes = (Nx * Ny - dX) * sizeof (float); 32 int Nextra = dX * sizeof (float); 33 34 if (dx < 0) { 35 memmove (buf[0].matrix.buffer, &buf[0].matrix.buffer[dX*sizeof(float)], Nbytes); 36 memset (&buf[0].matrix.buffer[Nbytes], 0, Nextra); 37 } else { 38 memmove (&buf[0].matrix.buffer[dX*sizeof(float)], buf[0].matrix.buffer, Nbytes); 39 memset (buf[0].matrix.buffer, 0, Nextra); 40 } 41 42 return TRUE; 16 dx = atof (argv[2]); 17 dy = atof (argv[3]); 18 if (dy != 0) { 19 gprint (GP_ERR, "only x rolls implemented for now\n"); 43 20 } 44 21 45 if (dx == 0) { 46 // moves in just dy can be done row-by-row 22 /* if (dx < 0), we are moving the start position back by dx pixels, 23 if (dx > 0), we are moving the start position forward by dx pixels */ 24 25 nx = buf[0].matrix.Naxis[0]; 26 ny = buf[0].matrix.Naxis[1]; 47 27 48 ALLOCATE_PTR (output, float, Nx*Ny); 28 dX = abs(dx); 29 Nbytes = nx * ny * sizeof (float); 30 Nextra = (nx * ny + dX) * sizeof (float); 49 31 50 float *input = (float *) buf[0].matrix.buffer;32 REALLOCATE (buf[0].matrix.buffer, char, Nextra); 51 33 52 for (int iy = 0; iy < Ny; iy++) { 53 if (iy + dy < 0) continue; 54 if (iy + dy >= Ny) continue; 55 memcpy (&output[iy*Nx], &input[(iy + dy)*Nx], Nx); 56 } 57 if (dy > 0) { 58 memset (output, 0, dy*Nx*sizeof(float)); 59 } else { 60 int Nbytes = Nx * (Ny - abs(dy)) * sizeof (float); 61 int Nextra = abs(dy) * Nx * sizeof (float); 62 memset (&output[Nbytes], 0, Nextra); 63 } 64 free (buf[0].matrix.buffer); 65 buf[0].matrix.buffer = (char *) output; 66 return TRUE; 34 if (dx < 0) { 35 memmove (buf[0].matrix.buffer, &buf[0].matrix.buffer[dX*sizeof(float)], Nbytes); 36 } else { 37 memmove (&buf[0].matrix.buffer[dX*sizeof(float)], buf[0].matrix.buffer, Nbytes); 67 38 } 68 39 69 ALLOCATE_PTR (output, float, Nx*Ny); 70 float *input = (float *) buf[0].matrix.buffer; 40 REALLOCATE (buf[0].matrix.buffer, char, Nbytes); 71 41 72 for (int iy = 0; iy < Ny; iy++) { 73 if (iy + dy < 0) continue; 74 if (iy + dy >= Ny) continue; 75 for (int ix = 0; ix < Nx; ix++) { 76 if (ix + dx < 0) continue; 77 if (ix + dx >= Nx) continue; 78 output[ix + iy*Nx] = input[(ix + dx) + (iy + dy)*Nx]; 79 } 80 } 81 free (buf[0].matrix.buffer); 82 buf[0].matrix.buffer = (char *) output; 83 return TRUE; 42 return (TRUE); 43 84 44 } 85 45 86 -
trunk/Ohana/src/opihi/cmd.data/rotate.c
r41269 r41340 3 3 int rotate (int argc, char **argv) { 4 4 5 int i, j, NX, NY ;5 int i, j, NX, NY, X, Y, Lx, Ly, N; 6 6 float *in_buff, *out_buff, *c; 7 double Xo, Yo, x, y, X1, Y1;7 double angle, CosAngle, SinAngle, Xo, Yo, dX, dY, fx, fy, x, y, X1, Y1; 8 8 double pc11, pc12, pc21, pc22, PC11, PC12, PC21, PC22; 9 9 Buffer *buf; 10 10 11 //Xo = 0;12 //Yo = 0;13 //if ((N = get_argument (argc, argv, "-center"))) {14 //remove_argument (N, &argc, argv);15 //Xo = atof(argv[N]);16 //remove_argument (N, &argc, argv);17 //Yo = atof(argv[N]);18 //remove_argument (N, &argc, argv);19 //}11 Xo = 0; 12 Yo = 0; 13 if ((N = get_argument (argc, argv, "-center"))) { 14 remove_argument (N, &argc, argv); 15 Xo = atof(argv[N]); 16 remove_argument (N, &argc, argv); 17 Yo = atof(argv[N]); 18 remove_argument (N, &argc, argv); 19 } 20 20 21 21 if (argc != 3) { … … 221 221 } 222 222 223 doubleangle = atof (argv[2]);224 doubleCosAngle = cos (angle*RAD_DEG);225 doubleSinAngle = sin (angle*RAD_DEG);223 angle = atof (argv[2]); 224 CosAngle = cos (angle*RAD_DEG); 225 SinAngle = sin (angle*RAD_DEG); 226 226 227 227 gprint (GP_ERR, "rotating: %f %f %f\n", angle, CosAngle, SinAngle); 228 228 229 // we are rotating about the center pixel, (NX/2, NY/2),230 // but we are then putting the result in a new image231 // of size (Lx,Ly).232 233 / / (x,y) = (i - Nx/2),(j - Ny/2)234 // (x',y') = R(theta) (x,y)235 // (I,J) = (x' + Lx/2),(y' + Ly/2)236 237 int Lx = NX*fabs(CosAngle) + NY*fabs(SinAngle);238 int Ly = NX*fabs(SinAngle) + NY*fabs(CosAngle);229 Lx = NX*fabs(CosAngle) + NY*fabs(SinAngle); 230 Ly = NX*fabs(SinAngle) + NY*fabs(CosAngle); 231 dX = MAX(0,NY*SinAngle); 232 dY = MAX(0,-NX*SinAngle); 233 /* 234 gprint (GP_ERR, "%f %f --> ", Xo, Yo); 235 X1 = Xo*CosAngle - Yo*SinAngle + dX; 236 Y1 = Xo*SinAngle + Yo*CosAngle + dY; 237 gprint (GP_ERR, "%f %f\n", X1, Y1); 238 */ 239 239 240 240 /* fix reference pixel */ 241 241 gfits_scan (&buf[0].header, "CRPIX1", "%lf", 1, &Xo); 242 242 gfits_scan (&buf[0].header, "CRPIX2", "%lf", 1, &Yo); 243 X1 = (Xo - NX/2)*CosAngle + (Yo - NY/2)*SinAngle + Lx/2; 244 Y1 = (NX/2 - Xo)*SinAngle + (Yo - NY/2)*CosAngle + Ly/2; 243 /* 244 X1 = (Xo - dX)*CosAngle - (Yo - dY)*SinAngle; 245 Y1 = (dX - Xo)*SinAngle + (Yo - dY)*CosAngle; 246 */ 247 X1 = Xo*CosAngle - Yo*SinAngle + dX; 248 Y1 = Xo*SinAngle + Yo*CosAngle + dY; 245 249 gfits_modify (&buf[0].header, "CRPIX1", "%lf", 1, X1); 246 250 gfits_modify (&buf[0].header, "CRPIX2", "%lf", 1, Y1); … … 251 255 gfits_scan (&buf[0].header, "PC002001", "%lf", 1, &pc21); 252 256 gfits_scan (&buf[0].header, "PC002002", "%lf", 1, &pc22); 253 PC11 = pc11*CosAngle +pc21*SinAngle;254 PC12 = pc12*CosAngle +pc22*SinAngle;255 PC21 = pc21*CosAngle -pc11*SinAngle;256 PC22 = pc22*CosAngle -pc12*SinAngle;257 PC11 = pc11*CosAngle - pc21*SinAngle; 258 PC12 = pc12*CosAngle - pc22*SinAngle; 259 PC21 = pc21*CosAngle + pc11*SinAngle; 260 PC22 = pc22*CosAngle + pc12*SinAngle; 257 261 gfits_modify (&buf[0].header, "PC001001", "%le", 1, PC11); 258 262 gfits_modify (&buf[0].header, "PC001002", "%le", 1, PC12); … … 266 270 gfits_create_matrix (&buf[0].header, &buf[0].matrix); 267 271 gfits_print_alt (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!"); 268 269 272 out_buff = (float *)buf[0].matrix.buffer; 270 271 273 for (j = 0; j < Ly; j++) { 272 274 for (i = 0; i < Lx; i++, out_buff++) { 273 275 274 float xo = (i - Lx/2); 275 float yo = (j - Ly/2); 276 277 x = xo*CosAngle + yo*SinAngle; 278 y = -xo*SinAngle + yo*CosAngle; 279 280 int I = x + NX/2; 281 int J = y + NY/2; 282 283 if (I < 0) continue; 284 if (I >= NX - 1) continue; 285 if (J < 0) continue; 286 if (J >= NY - 1) continue; 287 288 c = &in_buff[I + NX*J]; 289 290 int X = (int) x; 291 int Y = (int) y; 292 double fx = x - X; 293 double fy = y - Y; 294 276 x = (i - dX)*CosAngle + (j - dY)*SinAngle; 277 y = (dX - i)*SinAngle + (j - dY)*CosAngle; 278 X = (int) x; 279 Y = (int) y; 280 281 if (X < 0) continue; 282 if (X >= NX - 1) continue; 283 if (Y < 0) continue; 284 if (Y >= NY - 1) continue; 285 286 c = &in_buff[X + NX*Y]; 287 fx = x - X; 288 fy = y - Y; 295 289 *out_buff = (c[0]*(1-fx) + c[1]*fx)*(1-fy) + (c[NX+1]*fx + c[NX]*(1-fx))*fy; 296 // *out_buff = c[0];297 290 } 298 291 } -
trunk/Ohana/src/opihi/cmd.data/spline.c
r41164 r41340 7 7 int spline_load (int argc, char **argv); 8 8 int spline_save (int argc, char **argv); 9 int spline_print (int argc, char **argv);10 9 int spline_delete (int argc, char **argv); 11 10 int spline_rename (int argc, char **argv); … … 19 18 {1, "load", spline_load, "write a spline to a FITS file"}, 20 19 {1, "save", spline_save, "read a spline from a FITS file"}, 21 {1, "print", spline_print, "print a spline to stdout"},22 20 {1, "delete", spline_delete, "delete a spline"}, 23 21 {1, "rename", spline_rename, "rename a spline"}, … … 37 35 gprint (GP_ERR, " spline load (spline) (filename) : load a spline from a FITS file\n"); 38 36 gprint (GP_ERR, " spline save (spline) (filename) [-append] : save a spline in FITS format\n"); 39 gprint (GP_ERR, " spline print (spline) : print a spline to stdout\n");40 37 41 38 return FALSE; -
trunk/Ohana/src/opihi/cmd.data/spline_commands.c
r41164 r41340 28 28 if (xvec->Nelements != yvec->Nelements) { 29 29 gprint (GP_ERR, "x and y vectors must be the same length\n"); 30 return FALSE;31 }32 33 if (xvec->Nelements < 3) {34 gprint (GP_ERR, "cannot make a spline with fewer than 3 knots\n");35 30 return FALSE; 36 31 } … … 98 93 } 99 94 100 int spline_print (int argc, char **argv) {101 102 int i;103 104 if (argc != 2) {105 gprint (GP_ERR, "USAGE: spline print (name)\n");106 return FALSE;107 }108 109 Spline *myspline = FindSpline (argv[1]);110 if (!myspline) {111 gprint (GP_ERR, "spline %s not found\n", argv[1]);112 return (FALSE);113 }114 115 for (i = 0; i < myspline->Nknots; i++) {116 gprint (GP_LOG, "%lf : %lf : %lf\n", myspline->xk[i], myspline->yk[i], myspline->y2[i]);117 }118 119 return TRUE;120 }121 122 95 int spline_load (int argc, char **argv) { 123 96 … … 136 109 int spline_delete (int argc, char **argv) { 137 110 138 int N, status; 139 140 int QUIET = FALSE; 141 if ((N = get_argument (argc, argv, "-q"))) { 142 QUIET = TRUE; 143 remove_argument (N, &argc, argv); 144 } 111 int status; 112 Spline *spline; 145 113 146 114 if (argc != 2) { … … 149 117 } 150 118 151 Spline *spline = FindSpline (argv[1]);119 spline = FindSpline (argv[1]); 152 120 if (spline == NULL) { 153 if (QUIET) return TRUE;154 121 gprint (GP_ERR, "spline %s not found\n", argv[1]); 155 122 return FALSE; … … 163 130 int spline_rename (int argc, char **argv) { 164 131 132 Spline *spline; 133 165 134 if (argc != 3) { 166 135 gprint (GP_ERR, "USAGE: spline rename (spline) (newname)\n"); … … 168 137 } 169 138 170 Spline *spline = FindSpline (argv[1]);139 spline = FindSpline (argv[1]); 171 140 if (spline == NULL) { 172 141 gprint (GP_ERR, "spline %s not found\n", argv[1]); 173 142 return FALSE; 174 }175 176 Spline *newname = FindSpline (argv[2]);177 if (newname != NULL) {178 DeleteSpline (newname);179 143 } 180 144 … … 183 147 return TRUE; 184 148 } 149 150 /* 151 int spline_listspline (int argc, char **argv) { 152 153 Spline *spline; 154 155 if (argc != 2) { 156 gprint (GP_ERR, "USAGE: spline listspline (spline)\n"); 157 return FALSE; 158 } 159 160 spline = FindSpline (argv[1]); 161 if (spline == NULL) { 162 gprint (GP_ERR, "spline %s not found\n", argv[1]); 163 return FALSE; 164 } 165 166 ListPages (spline); 167 return TRUE; 168 } 169 */ 170 -
trunk/Ohana/src/opihi/cmd.data/test/cut.sh
r41164 r41340 4 4 memtest1 5 5 end 6 7 macro test28 9 mgaussdev z 50 100 0.0 1.010 11 cut z x y_sum x 0 0 z[][0] z[0][]12 cut z x y_median x 0 0 z[][0] z[0][] -median13 cut z x y_mean x 0 0 z[][0] z[0][] -mean14 cut z x y_inner x 0 0 z[][0] z[0][] -inner15 16 end17 18 macro checkrange19 if ($0 != 2)20 echo "USAGE: checkrange (Npts)"21 break22 end23 24 $Npts = $125 if ($Npts % 2)26 $Ncenter = int($Npts / 2)27 $Nquarter = int(0.25 * $Npts)28 $Ns = $Ncenter - $Nquarter29 $Ne = $Ncenter + $Nquarter30 else31 $Ncenter = int($Npts / 2) - 132 $Nquarter = int(0.25 * $Npts)33 $Ns = $Ncenter - $Nquarter34 $Ne = $Ncenter + $Nquarter + 135 end36 if ($Ns < 0)37 echo "error: Ns < 0: $Ns $Ncenter $Nquarter"38 end39 if ($Ne >= $Npts)40 echo "error: Ne >= Npts: $Ne $Ncenter $Nquarter"41 end42 echo "$Npts : $Ncenter : $Nquarter : $Ns $Ne"43 for i 0 $Npts44 echo $i {($i >= $Ns) && ($i <= $Ne)}45 end46 end47 48 6 49 7 # Test if cut works … … 79 37 end 80 38 end 81 82 macro memtest183 84 $i = 085 mcreate tim 100 10086 cut tim xdir imx X 40 4 60 687 # do one to set up memory that should stay used88 89 memory check90 for i 0 10091 cut tim xdir imx X 40 4 60 692 end93 memory check94 95 for i 0 10096 cut tim xdir imx y 40 4 60 697 end98 memory check99 100 for i 0 100101 cut -median tim xdir imx X 40 4 60 6102 end103 memory check104 105 for i 0 100106 cut -median tim xdir imx y 40 4 60 6107 end108 memory check109 110 for i 0 100111 cut -mean tim xdir imx X 40 4 60 6112 end113 memory check114 115 for i 0 100116 cut -mean tim xdir imx y 40 4 60 6117 end118 memory check119 120 end -
trunk/Ohana/src/opihi/cmd.data/test/delete.sh
r41164 r41340 49 49 50 50 end 51 52 # Test delete53 macro test254 55 $PASS = 156 57 for i 0 100058 create v 0 20059 delete v60 end61 end -
trunk/Ohana/src/opihi/cmd.data/test/medimage.sh
r41164 r41340 1 1 2 macro test.mean 3 4 $Nsample = 16 5 medimage delete -q t1 6 for i 0 $Nsample 7 mgaussdev t 50 50 0.0 1.0 8 medimage add t1 t 9 imhist -q t x y -range -10 10 -delta 0.1 10 11 $C0 = 0 12 $C1 = 1.5 13 $C2 = 400 14 $C3 = 0 15 vgauss -q x y con yf 16 # echo $C1 2 macro go 3 mcreate a 30 30 4 for i 0 40 5 set a$i = zero(a) + $i 17 6 end 18 7 19 medimage calc t1 T -mean 20 21 imhist -q T x y -range -10 10 -delta 0.1 22 lim -n 1 x y; clear; box; plot -x hist x y 23 $C0 = 0 24 $C1 = 1.5 25 $C2 = 400 26 $C3 = 0 27 vgauss -q x y con yf 28 echo "expect {1/sqrt($Nsample)} : $C1" 29 plot -c red -x line x yf 8 for i 0 40 9 medimage add t1 a$i 10 end 30 11 end 31 32 macro test.median33 34 $Nsample = 1635 medimage delete -q t136 for i 0 $Nsample37 mgaussdev t 50 50 0.0 1.038 medimage add t1 t39 imhist -q t x y -range -10 10 -delta 0.140 41 $C0 = 042 $C1 = 1.543 $C2 = 40044 $C3 = 045 vgauss -q x y con yf46 end47 48 # note that median of a gaussian distributed variable is not distributed with sigma' = sigma / sqrt(N)49 # (somewhat higher scatter)50 medimage calc t1 T51 52 imhist -q T x y -range -10 10 -delta 0.153 lim -n 1 x y; clear; box; plot -x hist x y54 $C0 = 055 $C1 = 1.556 $C2 = 40057 $C3 = 058 vgauss -q x y con yf59 echo "expect {1/sqrt($Nsample)} : $C1 (actually should be a bit higher)"60 plot -c red -x line x yf61 end62 63 macro test.wtmean64 65 $Nsample = 866 $sig1 = 1.067 $sig2 = 3.068 69 medimage delete -q t170 for i 0 $Nsample71 mgaussdev t 50 50 0.0 $sig172 set v = $sig1^2 + zero(t)73 medimage add t1 t -variance v74 imhist -q t x y -range -10 10 -delta 0.175 76 $C0 = 077 $C1 = 1.578 $C2 = 40079 $C3 = 080 vgauss -q x y con yf81 # echo $C182 end83 84 for i 0 $Nsample85 mgaussdev t 50 50 0.0 $sig286 set v = $sig2^2 + zero(t)87 medimage add t1 t -variance v88 imhist -q t x y -range -10 10 -delta 0.189 90 $C0 = 091 $C1 = 1.592 $C2 = 40093 $C3 = 094 vgauss -q x y con yf95 # echo $C196 end97 98 # note that median of a gaussian distributed variable is not distributed with sigma' = sigma / sqrt(N)99 # (somewhat higher scatter)100 medimage calc t1 T -wtmean101 102 imhist -q T x y -range -10 10 -delta 0.1103 lim -n 1 x y; clear; box; plot -x hist x y104 $C0 = 0105 $C1 = 1.5106 $C2 = 400107 $C3 = 0108 vgauss -q x y con yf109 $S1 = $Nsample / $sig1^2 + $Nsample / $sig2^2110 echo "expect {1/sqrt($S1)} : $C1"111 plot -c red -x line x yf112 end113 114 macro test.irls115 medimage delete -q t1116 $Nsample = 16117 $sig = 1.0118 for i 0 $Nsample119 mgaussdev t 50 50 0.0 $sig120 set v = $sig^2 + zero(t)121 122 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t)123 set ts = t + bad124 125 medimage add t1 ts -variance v126 imhist -q t x y -range -10 10 -delta 0.1127 128 $C0 = 0129 $C1 = 1.5130 $C2 = 400131 $C3 = 0132 vgauss -q x y con yf133 # echo $C1134 end135 136 # get stats for straight mean:137 medimage calc t1 Tm -mean138 139 imhist -q Tm x y -range -10 10 -delta 0.1140 lim -n 1 x y; clear; box; plot -x hist x y141 $C0 = 0142 $C1 = 1.5143 $C2 = 400144 $C3 = 0145 vgauss -q x y con yf146 echo "sigma from straight stdev: $C1"147 # stats Tm148 149 plot -c red -x line x yf150 151 # get stats for irls152 medimage calc t1 Ti -irls153 154 imhist -q Ti x y -range -10 10 -delta 0.1155 lim -n 2 x y; clear; box; plot -x hist x y156 $C0 = 0157 $C1 = 1.5158 $C2 = 400159 $C3 = 0160 vgauss -q x y con yf161 echo "sigma from irls: $C1 (ideal is {$sig/sqrt($Nsample)})"162 # stats Ti163 164 plot -c red -x line x yf165 end166 167 168 ###################33169 170 171 macro test.mean.var172 173 $Nsample = 64174 $sig = 2.0175 medimage delete -q t1176 for i 0 $Nsample177 mgaussdev t 100 100 0.0 $sig178 medimage add t1 t179 imhist -q t x y -range -10 10 -delta 0.1180 181 $C0 = 0182 $C1 = 1.5183 $C2 = 400184 $C3 = 0185 vgauss -q x y con yf186 # echo $C1187 end188 189 medimage calc t1 T -mean -variance Tv190 191 imhist -q T x y -range -10 10 -delta 0.1192 lim -n 1 x y; clear; box; plot -x hist x y193 $C0 = 0194 $C1 = 1.5195 $C2 = 400196 $C3 = 0197 vgauss -q x y con yf198 plot -c red -x line x yf199 200 imhist Tv xv yv -range -1 4 -delta 0.1201 lim -n 2 xv yv; clear; box; plot xv yv -x hist202 203 stat Tv204 echo "$C1 vs {sqrt($MEDIAN)} : expect {$sig/sqrt($Nsample)}"205 end206 207 macro test.median.var208 209 $Nsample = 64210 $sig = 2.0211 medimage delete -q t1212 for i 0 $Nsample213 mgaussdev t 50 50 0.0 $sig214 medimage add t1 t215 imhist -q t x y -range -10 10 -delta 0.1216 217 $C0 = 0218 $C1 = 1.5219 $C2 = 400220 $C3 = 0221 vgauss -q x y con yf222 # echo $C1223 end224 225 # note that median of a gaussian distributed variable is not distributed with sigma' = sigma / sqrt(N)226 # (somewhat higher scatter)227 medimage calc t1 T -variance Tv228 229 imhist -q T x y -range -10 10 -delta 0.1230 lim -n 1 x y; clear; box; plot -x hist x y231 $C0 = 0232 $C1 = 1.5233 $C2 = 400234 $C3 = 0235 vgauss -q x y con yf236 plot -c red -x line x yf237 238 imhist Tv xv yv -range -1 4 -delta 0.1239 lim -n 2 xv yv; clear; box; plot xv yv -x hist240 241 stat Tv242 echo "$C1 vs {sqrt($MEDIAN)} : expect {$sig/sqrt($Nsample)}"243 end244 245 macro test.wtmean.var246 247 $Nsample = 32248 $sig1 = 1.0249 $sig2 = 1.0250 251 medimage delete -q t1252 for i 0 $Nsample253 mgaussdev t 50 50 0.0 $sig1254 set v = $sig1^2 + zero(t)255 medimage add t1 t -variance v256 imhist -q t x y -range -10 10 -delta 0.1257 258 $C0 = 0259 $C1 = 1.5260 $C2 = 400261 $C3 = 0262 vgauss -q x y con yf263 # echo $C1264 end265 266 for i 0 $Nsample267 mgaussdev t 50 50 0.0 $sig2268 set v = $sig2^2 + zero(t)269 medimage add t1 t -variance v270 imhist -q t x y -range -10 10 -delta 0.1271 272 $C0 = 0273 $C1 = 1.5274 $C2 = 400275 $C3 = 0276 vgauss -q x y con yf277 # echo $C1278 end279 280 # note that median of a gaussian distributed variable is not distributed with sigma' = sigma / sqrt(N)281 # (somewhat higher scatter)282 medimage calc t1 T -wtmean -variance Tv283 284 imhist -q T x y -range -10 10 -delta 0.1285 lim -n 1 x y; clear; box; plot -x hist x y286 $C0 = 0287 $C1 = 1.5288 $C2 = 400289 $C3 = 0290 vgauss -q x y con yf291 plot -c red -x line x yf292 293 stat -q Tv294 $S1 = $Nsample / $sig1^2 + $Nsample / $sig2^2295 echo $C1 vs {sqrt($MEDIAN)} : expect {1/sqrt($S1)}296 end297 298 macro test.irls.var299 300 $Nsample = 16301 $sig = 1.0302 303 medimage delete -q t1304 for i 0 $Nsample305 mgaussdev t 50 50 0.0 $sig306 set v = $sig^2 + zero(t)307 308 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t)309 set ts = t + bad310 311 medimage add t1 ts -variance v312 imhist -q t x y -range -10 10 -delta 0.1313 314 $C0 = 0315 $C1 = 1.5316 $C2 = 400317 $C3 = 0318 vgauss -q x y con yf319 # echo $C1320 end321 322 # get stats for straight mean:323 medimage calc t1 Tm -mean -variance Tv324 325 imhist -q Tm x y -range -10 10 -delta 0.1326 lim -n 1 x y; clear; box; plot -x hist x y327 $C0 = 0328 $C1 = 1.5329 $C2 = 400330 $C3 = 0331 vgauss -q x y con yf332 echo "sigma from straight stdev: $C1"333 # stats Tm334 335 plot -c red -x line x yf336 337 # get stats for irls338 medimage calc t1 Ti -irls -variance Tv339 340 imhist -q Ti x y -range -10 10 -delta 0.1341 lim -n 2 x y; clear; box; plot -x hist x y342 $C0 = 0343 $C1 = 1.5344 $C2 = 400345 $C3 = 0346 vgauss -q x y con yf347 echo "sigma from irls: $C1 (ideal is {$sig/sqrt($Nsample)})"348 # stats Ti349 350 plot -c red -x line x yf351 352 set dTv = sqrt(Tv)353 imhist dTv xv yv -range -1 4 -delta 0.02; lim -n 3 xv yv; clear; box; plot xv yv -x hist354 355 stat -q Tv356 echo $C1 vs {sqrt($MEDIAN)} (ideal is {$sig/sqrt($Nsample)})"357 end358 359 macro test.irls.boot.var360 361 $Nsample = 64362 $sig = 1.0363 364 medimage delete -q t1365 for i 0 $Nsample366 mgaussdev t 200 200 0.0 $sig367 set v = $sig^2 + zero(t)368 369 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t)370 set ts = t + bad371 372 mgaussdev noise 200 200 0.0 0.5373 set ts = ts + noise374 375 medimage add t1 ts -variance v376 imhist -q t x y -range -10 10 -delta 0.1377 378 $C0 = 0379 $C1 = 1.5380 $C2 = 400381 $C3 = 0382 vgauss -q x y con yf383 # echo $C1384 end385 386 # get stats for straight mean:387 medimage calc t1 Tm -mean -variance Tv388 389 imhist -q Tm x y -range -10 10 -delta 0.02390 lim -n 1 x y; clear; box; plot -x hist x y391 peak -q x y392 $C0 = $peakpos393 $C1 = 1.5*$sig / sqrt($Nsample)394 $C2 = $peakval395 $C3 = 0396 vgauss -q x y con yf397 echo "sigma from straight stdev: $C1"398 # stats Tm399 400 plot -c red -x line x yf401 402 # get stats for irls403 date404 medimage calc t1 Ti -irls -variance Tv -bootstrap-iter 100405 date406 407 imhist -q Ti x y -range -10 10 -delta 0.02408 lim -n 2 x y; clear; box; plot -x hist x y409 peak -q x y410 $C0 = $peakpos411 $C1 = 1.5*$sig / sqrt($Nsample)412 $C2 = $peakval413 $C3 = 0414 vgauss -q x y con yf415 echo "sigma from irls: $C1 (ideal is {$sig/sqrt($Nsample)})"416 # stats Ti417 418 plot -c red -x line x yf419 420 set dTv = sqrt(Tv)421 imhist dTv xv yv -range 0 {5*$sig/sqrt($Nsample)} -delta 0.02; lim -n 3 xv yv; clear; box; plot xv yv -x hist422 423 stat -q Tv424 echo $C1 vs {sqrt($MEDIAN)} (ideal is {$sig/sqrt($Nsample)})"425 end426 427 ##############################428 macro test.irls.boot.test429 430 $Nsample = 100431 $sig1 = 1.0432 433 medimage delete -q t1434 for i 0 $Nsample435 mgaussdev t 100 100 0.0 $sig1436 set v = $sig1^2 + zero(t)437 438 medimage add t1 t -variance v439 end440 441 # get stats for irls442 medimage calc t1 Ti -irls -variance Tv -bootstrap443 444 imhist -q Ti x y -range {-10*$sig1/sqrt($Nsample)} {10*$sig1/sqrt($Nsample)} -delta 0.01445 lim -n 2 x y; clear; box; plot -x hist x y446 peak -q x y447 $C0 = $peakpos448 $C1 = 1.5*$sig1/sqrt($Nsample)449 $C2 = $peakval450 $C3 = 0451 vgauss x y con yf452 echo "sigma from irls: $C1 (ideal is {$sig1/sqrt($Nsample)})"453 # stats Ti454 455 plot -c red -x line x yf456 457 set dTv = sqrt(Tv)458 imhist dTv xv yv -range 0 {5*$sig1/sqrt($Nsample)} -delta 0.02; lim -n 3 xv yv; clear; box; plot xv yv -x hist459 460 stat -q irls_npt461 $Npix = $MEAN462 463 stat -q Tv464 echo "sigma of irls average: $C1, sqrt(mean) of irls variance: {sqrt($MEAN)}, (ideal is {$sig1/sqrt($Npix)})"465 end466 467 macro test.irls.range.var468 medimage delete -q t1469 for i 0 8470 mgaussdev t 50 50 0.0 1.0471 set v = 1.0 + zero(t)472 473 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t)474 set ts = t + bad475 476 medimage add t1 ts -variance v477 imhist -q t x y -range -10 10 -delta 0.1478 479 $C0 = 0480 $C1 = 1.5481 $C2 = 400482 $C3 = 0483 vgauss -q x y con yf484 echo $C1485 end486 487 for i 0 8488 mgaussdev t 50 50 0.0 3.0489 set v = 3.0 + zero(t)490 491 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t)492 set ts = t + bad493 494 medimage add t1 ts -variance v495 imhist -q t x y -range -10 10 -delta 0.1496 497 $C0 = 0498 $C1 = 1.5499 $C2 = 400500 $C3 = 0501 vgauss -q x y con yf502 echo $C1503 end504 505 # get stats for straight mean:506 medimage calc t1 Tm -mean -variance Tv507 508 imhist -q Tm x y -range -10 10 -delta 0.1509 lim -n 1 x y; clear; box; plot -x hist x y510 $C0 = 0511 $C1 = 1.5512 $C2 = 400513 $C3 = 0514 vgauss -q x y con yf515 echo $C1516 stats Tm517 518 plot -c red -x line x yf519 520 # get stats for irls521 medimage calc t1 Ti -irls -variance Tv522 523 imhist -q Ti x y -range -10 10 -delta 0.1524 lim -n 2 x y; clear; box; plot -x hist x y525 $C0 = 0526 $C1 = 1.5527 $C2 = 400528 $C3 = 0529 vgauss -q x y con yf530 echo $C1531 stats Ti532 533 plot -c red -x line x yf534 535 stat -q Tv536 echo $C1 vs {sqrt($MEDIAN)}537 538 set dTv = sqrt(Tv)539 imhist dTv xv yv -range -1 4 -delta 0.02; lim -n 3 xv yv; clear; box; plot xv yv -x hist540 end -
trunk/Ohana/src/opihi/cmd.data/threshold.c
r41164 r41340 25 25 remove_argument (N, &argc, argv); 26 26 BinMax = atoi (argv[N]); 27 remove_argument (N, &argc, argv);28 }29 30 float ValMin = NAN;31 float ValMax = NAN;32 if ((N = get_argument (argc, argv, "-vrange"))) {33 remove_argument (N, &argc, argv);34 ValMin = atof (argv[N]);35 remove_argument (N, &argc, argv);36 ValMax = atof (argv[N]);37 27 remove_argument (N, &argc, argv); 38 28 } … … 74 64 } 75 65 76 // ValMin, ValMax not compatible with BinMin, BinMax77 if (isfinite(ValMin)) {78 int binTest = ohana_bisection_double (vecx[0].elements.Flt, vecx[0].Nelements, ValMin);79 BinMin = (vecx[0].elements.Flt[binTest+1] == ValMin) ? binTest : binTest + 1;80 // XXX dangerous: check that this does not run off the end, etc81 }82 if (isfinite(ValMax)) {83 int binTest = ohana_bisection_double (vecx[0].elements.Flt, vecx[0].Nelements, ValMax);84 BinMax = (vecx[0].elements.Flt[binTest+1] == ValMax) ? binTest : binTest + 1;85 // XXX dangerous: check that this does not run off the end, etc86 }87 88 66 // use bisection to find the value 89 67 … … 93 71 94 72 if (!REVERSE) { 95 // this algorithm assumes vecy[BinMax] > threshold, vecy[BinMin] < threshold96 if (vecy[0].elements.Flt[BinMin] > value) {97 gprint (GP_ERR, "ERROR: all values above threshold\n");98 return FALSE;99 }100 if (vecy[0].elements.Flt[BinMax] < value) {101 gprint (GP_ERR, "ERROR: all values below threshold\n");102 return FALSE;103 }104 73 while (Nhi - Nlo > 10) { 105 74 N = 0.5*(Nlo + Nhi); … … 120 89 } 121 90 } else { 122 // this algorithm assumes vecy[BinMin] > threshold, vecy[BinMax] < threshold123 if (vecy[0].elements.Flt[BinMin] < value) {124 gprint (GP_ERR, "ERROR: all values below threshold\n");125 return FALSE;126 }127 if (vecy[0].elements.Flt[BinMax] > value) {128 gprint (GP_ERR, "ERROR: all values above threshold\n");129 return FALSE;130 }131 91 while (Nhi - Nlo > 10) { 132 92 N = 0.5*(Nlo + Nhi); -
trunk/Ohana/src/opihi/cmd.data/tvcolors.c
r41269 r41340 37 37 gprint (GP_ERR, "USAGE: tvcolors (colormap) [-nan red green blue]\n"); 38 38 gprint (GP_ERR, " colormap options : greyscale, -greyscale, rainbow, heat, fullcolor, ruffcolor (also grayscale, -grayscale)\n"); 39 gprint (GP_ERR, " colormap file: if colormap name is given as file:path/to/file, the colormap is read from the file\n"); 39 gprint (GP_ERR, " colormap file name of the for WORD:PATH where WORD = (file,csvf,lgcy,cetf)\n"); 40 gprint (GP_ERR, " lgcy:\n"); 41 gprint (GP_ERR, " the colormap file must contain 4 columns: f R B G; each line defines a color transition.\n"); 42 gprint (GP_ERR, " f: 0 - 1 defines the scale value for the transition\n"); 43 gprint (GP_ERR, " R,B,G: 0 - 1 define the value of the color at the transition point\n"); 44 gprint (GP_ERR, " file:\n"); 40 45 gprint (GP_ERR, " the colormap file must contain 4 columns: f R G B; each line defines a color transition.\n"); 41 46 gprint (GP_ERR, " f: 0 - 1 defines the scale value for the transition\n"); 42 47 gprint (GP_ERR, " R,G,B: 0 - 1 define the value of the color at the transition point\n"); 48 gprint (GP_ERR, " csvf:\n"); 49 gprint (GP_ERR, " the colormap file must contain 4 columns: f,R,G,B separate by commas; each line defines a color transition.\n"); 50 gprint (GP_ERR, " f: 0 - 1 defines the scale value for the transition\n"); 51 gprint (GP_ERR, " R,G,B: 0 - 1 define the value of the color at the transition point\n"); 52 gprint (GP_ERR, " cetf:\n"); 53 gprint (GP_ERR, " the colormap file must 256 rows contain 3 columns: R,G,B separate by commas; each line defines a color transition.\n"); 54 gprint (GP_ERR, " R,G,B: 0 - 1 define the value of the color at the transition point\n"); 55 gprint (GP_ERR, " CETF-format files can be found at : https://peterkovesi.com/projects/colourmaps\n"); 43 56 return (FALSE); 44 57 } -
trunk/Ohana/src/opihi/cmd.data/vgauss.c
r41164 r41340 3 3 /* local private functions */ 4 4 opihi_flt fgaussOD (opihi_flt, opihi_flt *, int, opihi_flt *); 5 int vgauss_apply (int argc, char **argv);6 5 7 6 # define GET_VAR(V,A) \ … … 21 20 Vector *xvec, *yvec, *svec, *ovec; 22 21 char *c, name[16]; 23 24 if ((N = get_argument (argc, argv, "-apply"))) {25 remove_argument (N, &argc, argv);26 int status = vgauss_apply (argc, argv);27 return status;28 }29 22 30 23 Quiet = FALSE; … … 111 104 } 112 105 if (!Quiet) gprint (GP_ERR, "%d iterations\n", i); 113 set_variable ("Chisq", chisq);114 set_variable ("ChisqNu", chisq / (float) (Npts - Npar));115 106 116 107 for (i = 0; i < Npts; i++) { … … 134 125 } 135 126 136 int vgauss_apply (int argc, char **argv) {137 138 opihi_flt par[4];139 Vector *xvec, *ovec;140 char *c;141 142 // NOTE: -apply has already been stripped by vgauss call143 if (argc != 3) {144 gprint (GP_ERR, "USAGE: vgauss -apply <x> <out>\n");145 return (FALSE);146 }147 148 if ((xvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);149 if ((ovec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) return (FALSE);150 151 CastVector (xvec, OPIHI_FLT);152 153 GET_VAR (par[0], "C0");154 GET_VAR (par[1], "C1");155 GET_VAR (par[2], "C2");156 GET_VAR (par[3], "C3");157 int Npar = 4;158 159 int Npts = xvec[0].Nelements;160 ResetVector (ovec, OPIHI_FLT, Npts);161 162 for (int i = 0; i < Npts; i++) {163 ovec[0].elements.Flt[i] = fgaussOD (xvec[0].elements.Flt[i], par, Npar, NULL);164 }165 ovec[0].Nelements = Npts;166 167 return TRUE;168 }169 170 127 /* pars: x_o, sigma, I, back */ 171 128 opihi_flt fgaussOD (opihi_flt x, opihi_flt *par, int Npar, opihi_flt *dpar) { … … 178 135 f = par[2]*r + par[3]; 179 136 180 if (dpar) { 181 dpar[0] = par[2]*r*z/par[1]; 182 dpar[1] = par[2]*r*z*z/par[1]; 183 dpar[2] = r; 184 dpar[3] = 1; 185 } 137 dpar[0] = par[2]*r*z/par[1]; 138 dpar[1] = par[2]*r*z*z/par[1]; 139 dpar[2] = r; 140 dpar[3] = 1; 186 141 187 142 return (f); -
trunk/Ohana/src/opihi/cmd.data/write_vectors.c
r41269 r41340 32 32 } 33 33 34 // option generate a FITS output table (FITS holds the filename) 35 // in FITS output context, -header is interpretted as a buffer containing 36 // header keywords to supplement the FITS table header 34 /* option generate a FITS output table */ 37 35 char *FITS = NULL; 38 Header *fitsheader = NULL;39 Buffer *headbuffer = NULL;40 36 if ((N = get_argument (argc, argv, "-fits"))) { 41 37 remove_argument (N, &argc, argv); 42 38 FITS = strcreate (argv[N]); 43 39 remove_argument (N, &argc, argv); 44 45 if ((N = get_argument (argc, argv, "-header"))) { 46 remove_argument (N, &argc, argv); 47 if ((headbuffer = SelectBuffer (argv[N], OLDBUFFER, TRUE)) == NULL) return (FALSE); 48 fitsheader = &headbuffer->header; 49 remove_argument (N, &argc, argv); 50 } 51 } 52 40 } 41 53 42 /* option generate a FITS output table */ 54 43 int CSV = FALSE; … … 135 124 136 125 if (FITS) { 137 int status = WriteVectorTableFITS (argv[1], FITS, fitsheader,vec, Nvec, append, compress, format, Ntile);126 int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, compress, format, Ntile); 138 127 free (vec); 139 128 return status; … … 154 143 if (ADD_HEADER) { 155 144 for (j = 0; j < Nvec; j++) { 156 if (j == 0) fprintf (f, "# ");157 145 if (CSV) { 158 146 fprintf (f, "%s,", vec[j][0].name); 159 147 } else { 148 if (j == 0) fprintf (f, "# "); 160 149 fprintf (f, "%s ", vec[j][0].name); 161 150 } … … 166 155 /* default output format */ 167 156 if (format == (char *) NULL) { 168 char padChar = CSV ? ',' : ' ';169 157 for (i = 0; i < vec[0][0].Nelements; i++) { 170 158 for (j = 0; j < Nvec; j++) { 171 switch (vec[j][0].type) { 172 case OPIHI_FLT: 173 fprintf (f, "%.12g%c", vec[j][0].elements.Flt[i], padChar); 174 break; 175 case OPIHI_INT: 176 fprintf (f, OPIHI_INT_FMT"%c", vec[j][0].elements.Int[i], padChar); 177 break; 178 case OPIHI_STR: 179 fprintf (f, "%s%c", vec[j][0].elements.Str[i], padChar); 180 break; 159 if (vec[j][0].type == OPIHI_FLT) { 160 if (CSV) { 161 fprintf (f, "%.12g,", vec[j][0].elements.Flt[i]); 162 } else { 163 fprintf (f, "%.12g ", vec[j][0].elements.Flt[i]); 164 } 165 } else { 166 if (CSV) { 167 fprintf (f, OPIHI_INT_FMT",", vec[j][0].elements.Int[i]); 168 } else { 169 fprintf (f, OPIHI_INT_FMT" ", vec[j][0].elements.Int[i]); 170 } 181 171 } 182 172 } … … 225 215 fmttype[j] = 'd'; 226 216 break; 227 case 's':228 fmttype[j] = 's';229 break;230 217 default: 231 gprint (GP_ERR, "syntax error in format (only e,f,d,c,x ,sallowed)\n");218 gprint (GP_ERR, "syntax error in format (only e,f,d,c,x allowed)\n"); 232 219 return (FALSE); 233 220 } … … 236 223 strcat (fmtlist[Nvec-1], p0); 237 224 238 // check format types against vector types:239 for (j = 0; j < Nvec; j++) {240 switch (vec[j][0].type) {241 case OPIHI_FLT:242 case OPIHI_INT:243 if (fmttype[j] == 's') {244 gprint (GP_ERR, "mismatch between string format and numerical vector for %s\n", vec[j][0].name);245 return FALSE;246 }247 break;248 case OPIHI_STR:249 if (fmttype[j] != 's') {250 gprint (GP_ERR, "mismatch between numerical format and string vector for %s\n", vec[j][0].name);251 return FALSE;252 }253 break;254 }255 }256 257 225 for (i = 0; i < vec[0][0].Nelements; i++) { 258 226 for (j = 0; j < Nvec; j++) { … … 271 239 } 272 240 } 273 if (fmttype[j] == 's') {274 fprintf (f, fmtlist[j], vec[j][0].elements.Str[i]);275 }276 241 } 277 242 fprintf (f, "\n"); … … 295 260 gprint (GP_ERR, " -append : write to the end of the existing file\n"); 296 261 gprint (GP_ERR, " -fits NAME : write a fits table (extention name is NAME, column names match vector names)\n"); 297 gprint (GP_ERR, " in FITS output context, -header takes an additional argument which is interpretted\n");298 gprint (GP_ERR, " as a buffer containing header keywords to supplement the FITS table header\n");299 262 gprint (GP_ERR, " -csv : write a comma-separated values file (eg, to read in excel)\n"); 300 263 gprint (GP_ERR, " -f \"format\" : provide formatting codes for output:\n");
Note:
See TracChangeset
for help on using the changeset viewer.
