From 1bc1547f59fca0d1ce4c556bb1c04f5f1d0d7e53 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 23 Apr 2017 23:57:08 -0300 Subject: [PATCH 01/53] Add imaged stars magnitude detection by sextractor into plotfits.c --- plotfits.c | 12 ++++++++---- sextractor/default.sex | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plotfits.c b/plotfits.c index 7a9b576..c84df3d 100644 --- a/plotfits.c +++ b/plotfits.c @@ -400,10 +400,14 @@ int main(int argc,char *argv[]) if (plotstars==1) { cpgsci(3); for (i=0;i, SATUR_LEVEL 50000.0 # level (in ADUs) at which arises saturation -MAG_ZEROPOINT 0.0 # magnitude zero-point +MAG_ZEROPOINT 11.0 # magnitude zero-point MAG_GAMMA 4.0 # gamma of emulsion (for photographic scans) -GAIN 0.0 # detector gain in e-/ADU. +GAIN 10.0 # detector gain in e-/ADU. PIXEL_SCALE 1.0 # size of pixel in arcsec (0=use FITS WCS info). #------------------------- Star/Galaxy Separation ---------------------------- From fc76f1e8eeb3fd9bf4eadd026ef386611b2e1a57 Mon Sep 17 00:00:00 2001 From: fmederos Date: Mon, 24 Apr 2017 00:10:26 -0300 Subject: [PATCH 02/53] Restore default.sex --- sextractor/default.sex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sextractor/default.sex b/sextractor/default.sex index 66585e2..fb53e1c 100644 --- a/sextractor/default.sex +++ b/sextractor/default.sex @@ -39,7 +39,7 @@ SATUR_LEVEL 50000.0 # level (in ADUs) at which arises saturation MAG_ZEROPOINT 11.0 # magnitude zero-point MAG_GAMMA 4.0 # gamma of emulsion (for photographic scans) -GAIN 10.0 # detector gain in e-/ADU. +GAIN 0.0 # detector gain in e-/ADU. PIXEL_SCALE 1.0 # size of pixel in arcsec (0=use FITS WCS info). #------------------------- Star/Galaxy Separation ---------------------------- From 8d3ae33eadc324c0f65e820684a2cf01653fcb49 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 9 Jul 2017 05:22:19 -0300 Subject: [PATCH 03/53] Work in progres: Add automatic image calibration based on star triange match --- plotfits.c | 489 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 456 insertions(+), 33 deletions(-) diff --git a/plotfits.c b/plotfits.c index c84df3d..09c1a41 100644 --- a/plotfits.c +++ b/plotfits.c @@ -12,6 +12,16 @@ #define D2R M_PI/180.0 #define R2D 180.0/M_PI #define NMAX 4096 +#define MAXPOINTERR 40 // Maximum pointing error (pixels) + // Do not auto-choose reference stars closer than this to any edge (in pixels) because matching star may + // fall outside astrometric field. This should change to arcseconds in the future and be used to widen + // the astrometric catalog so that it's scale is grater than that of the imaged catalog just enough + // to be sure it includes all imaged stars even at the worst pointing error. +#define MAXROT 10*D2R // Maximum expected rotation error (radians) +#define DISTMATCHTOL 4 +#define MAGMATCHTOL 1 +#define MAXSCALERR 1.05 +#define MAXMAGERR 4 struct star { double ra,de; @@ -65,7 +75,7 @@ struct catalog read_astrometric_catalog(char *filename,float mmin,float sx,float file=fopen(filename,"rb"); if (file==NULL) { - fprintf(stderr,"%s not found!\n",filename); + fprintf(stdout,"%s not found!\n",filename); exit(0); } while (!feof(file)) { @@ -211,12 +221,12 @@ int match_catalogs(struct catalog *cat,struct catalog *ast,float rmax) for (i=0,n=0;in;i++) { for (j=0,flag=0;jn;j++) { if (ast->select[j]!=0) - continue; + continue; r=sqrt(pow(cat->x[i]-ast->x[j],2)+pow(cat->y[i]-ast->y[j],2)); if (flag==0 || rn;i++) { + r=cat->mag[i]; + if(r > mmax) + mmax=r; + if(r < mmin) + mmin=r; + mave+=r; + } + mave/=cat->n; + } + + if(size<0) + fprintf(stdout,"Error: Pointing inaccuracy too high\n"); + + fprintf(stdout,"Stars in imaged catalog: %d, stars in astrometric catalog: %d.\n", cat->n, ast->n); + fprintf(stdout,"MMin:%.1f,MMax:%.1f,MAve.:%.1f \n",mmin,mmax,mave); + + // if last time a suitable reference triangle was found + if(*nselect==3){ + // and also a match was found + if(nmatch==3){ + // this time search for another match beginning with the following 3rd star + triast[2]++; + fprintf(stdout,"Try different match.\n"); + } + else{ + // no match was found for last suitable triangle + // so search nor another reference triangle starting from the following 3rd star + tricat[2]++; + // erase matching triangle + triast[0]=0; + triast[1]=0; + triast[2]=0; + fprintf(stdout,"Try different triangle.\n"); + } + } + + *nselect=0; + // search for candidate triangles satisfying size minimum and stars magnitude, later we can fall back to smaller size if no suitable triangle + // is found + while((*nselect<3) && (size > 10)){ + + fprintf(stdout,"Looking for triangles with min size %4.0f\n",size); + + // Search candidate for 1st star + + for(s1=tricat[0];(*nselect<3) && (s1 < cat->n);s1++){ + // discard if outside high magnitude range + r=cat->mag[s1]; + if(r > mave){ + fprintf(stdout,"Star %d discarded for high magnitude.\n",s1); + continue; + } + // discard if too close to any edge + if((cat->x[s1] < error) || (cat->x[s1] > (img.naxis1-error))){ + fprintf(stdout,"Star %d discarded for close to edge.\n",s1); + continue; + } + if((cat->y[s1] < error) || (cat->y[s1] > (img.naxis2-error))){ + fprintf(stdout,"Star %d discarded for close to edge.\n",s1); + continue; + } + // s1 is viable candidate for 1st star + fprintf(stdout,"Candidate star 1: %d, magnitude: %.1f \n",s1,r); + tricat[0]=s1; + *nselect=1; + + fprintf(stdout,"Looking for 2nd star of triangle.\n"); + // Search candidate for 2nd star + for(s2=tricat[1];(*nselect<3) && (s2 < cat->n);s2++){ + // discard candidate if outside magnitude range + r=cat->mag[s2]; + if(r > mave){ + fprintf(stdout,"Star %d discarded for high magnitude.\n",s2); + continue; + } + // discard if too close to any edge + if((cat->x[s2] < error) || (cat->x[s2] > (img.naxis1-error))){ + fprintf(stdout,"Star %d discarded for close to edge.\n",s2); + continue; + } + if((cat->y[s2] < error) || (cat->y[s2] > (img.naxis2-error))){ + fprintf(stdout,"Star %d discarded for close to edge.\n",s2); + continue; + } + // discard if too close to star 1 + r=sqrt(pow(cat->x[s2]-cat->x[s1],2)+pow(cat->y[s2]-cat->y[s1],2)); + if(r < size){ + fprintf(stdout,"Star %d discarded for close to 1st star.\n",s2); + continue; + } + // s2 is viable candidate for 2nd star + fprintf(stdout,"Candidate star 2: %d, magnitude: %.1f, distance to star 1: %.1f \n",s2,cat->mag[s2],r); + tricat[1]=s2; + *nselect=2; + + fprintf(stdout,"Looking for 3rd star of triangle.\n"); + // Search candidate for 3rd star beginning from the last candidate found + for(s3=tricat[2];(*nselect<3) && (s3 < cat->n);s3++){ + // discard candidate if outside magnitude range + r=cat->mag[s3]; + if(r > mave){ + fprintf(stdout,"Star %d discarded for high magnitude.\n",s3); + continue; + } + // discard if too close to any edge + if((cat->x[s3] < error) || (cat->x[s3] > (img.naxis1-error))){ + fprintf(stdout,"Star %d discarded for close to edge.\n",s3); + continue; + } + if((cat->y[s3] < error) || (cat->y[s3] > (img.naxis2-error))){ + fprintf(stdout,"Star %d discarded for close to edge.\n",s3); + continue; + } + // discard if too close to star 1 + r=sqrt(pow(cat->x[s3]-cat->x[s1],2)+pow(cat->y[s3]-cat->y[s1],2)); + if(r < size){ + fprintf(stdout,"Star %d discarded for close to 1st star.\n",s3); + continue; + } + // discard if too close to star 2 + r=sqrt(pow(cat->x[s3]-cat->x[s2],2)+pow(cat->y[s3]-cat->y[s2],2)); + if(r < size){ + fprintf(stdout,"Star %d discarded for close to 2nd star.\n",s3); + continue; + } + // s3 is viable candidate for 3rd star + fprintf(stdout,"Candidate star 3: %d, magnitude: %.1f, distance to star 2: %.1f \n",s3,cat->mag[s3],r); + tricat[2]=s3; + *nselect=3; + + + // **************************** + // **************************** + // **************************** + // **************************** + //Ref.triangle: 8, 86, 91, + //Match triangle: 125, 64, 115, + //Ref.triangle: 8, 94, 161, + //Match triangle: 125, 1, 90, +//Ref.triangle: 8, 159, 161, +//Match triangle: 125, 55, 90, +//Ref.triangle: 8, 152, 129, +//Match triangle: 151, 54, 120, +//Ref.triangle: 8, 77, 129, +//Match triangle: 125, 24, 120, + +//Está matcheando!!! +//ahora habría que descartar mirrors verticales y/o horizontales y limitar la rotación para llegar más directo + + if(s1==8 && s2==86 && s3==91){ + fprintf(stdout,"Special reference triangle found!!!\n"); + } + + // ************************************************************ + // Calibration triangle candidate found! + // time to look for matching triangle in astrometric catalog... + // ************************************************************ + + // at this point we got 3 reference stars forming suitable triangle, will look for matching triangle in astrometric catalog + // will search by testing relative magnitude and relative distance between suspect matching stars + // a scale tolerance is given as a ratio for distances (triangle size) and is assumed as affecting the whole image, + // this tolerance could be high. + // Also a magnitude tolerance is defined as an absolute value, this should not be too high (1..2 magnitudes) + // + // relative distance between stars of astrometric catalog should closely match relative distances between stars of imaged catalog + // a tolerance for this match is given also as a ratio and should be low + // also magnitude difference between stars of astrometric cat should closely match magn diff between stars of img cat. + // a tolerance for this magnitude match is given and should not be high (0.5 magn) + + nmatch=0; + // Search for candidate 1st match star + for(m1=triast[0];((nmatch<3) && (m1n));m1++){ + // discard if outside magnitude tolerance + // this tolerance includes magnitude extraction tolerance on sextractor tool + r=fabs(cat->mag[s1] - ast->mag[m1]); + if(r > MAXMAGERR){ + fprintf(stdout,"Match 1st star %d discarded for mag. difference.\n",m1); + continue; + } + r=ast->mag[m1]; + // m1 is viable candidate for match to 1st star + fprintf(stdout,"Candidate match star 1: %d, magnitude: %.1f \n",m1,r); + triast[0]=m1; + nmatch=1; + // Search candidate for 2nd star + for(m2=triast[1];(nmatch<3) && (m2n);m2++){ + // magn difference between star 1 and star 2 should be very close to magn diff between matching star 1 and matching star 2 + // discard if difference is outside match tolerance + r=fabs(cat->mag[s2] - cat->mag[s1]); + if((r - fabs(ast->mag[m2] - ast->mag[m1])) > MAGMATCHTOL){ + fprintf(stdout,"Match 2nd star %d discarded for mag. match tolerance.\n",m2); + continue; + } + // distance from star 1 to star 2 should resemble distance from matching star 1 to matching star 2 allowing for + // scale tolerance + r=sqrt(pow(cat->x[s2]-cat->x[s1],2)+pow(cat->y[s2]-cat->y[s1],2)); + // discard if distance between m2 and m1 is too far from distance between s2 and s1 + if(sqrt(pow(ast->x[m2]-ast->x[m1],2)+pow(ast->y[m2]-ast->y[m1],2)) / r > MAXSCALERR){ + fprintf(stdout,"Match 2nd star %d discarded for distance to 1st match star error.\n",m2); + continue; + } + if(r / sqrt(pow(ast->x[m2]-ast->x[m1],2)+pow(ast->y[m2]-ast->y[m1],2)) > MAXSCALERR){ + fprintf(stdout,"Match 2nd star %d discarded for distance to 1st match star error.\n",m2); + continue; + } + // check angle + d=atan((cat->y[s2]-cat->y[s1]) / (cat->x[s2]-cat->x[s1])); + if(fabs(d - atan((ast->y[m2]-ast->y[m1]) / (ast->x[m2]-ast->x[m1]))) > MAXROT){ + fprintf(stdout,"Match 2nd star %d discarded for rotation error.\n",m2); + continue; + } + // keep scale to check for coherence with third matching star + matchscale=sqrt(pow(ast->x[m2]-ast->x[m1],2)+pow(ast->y[m2]-ast->y[m1],2)) / r; + fprintf(stdout,"Triangle size match scale: %f.2.\n",matchscale); + // m2 is viable candidate for match to 2nd star + r=ast->mag[m2]; + fprintf(stdout,"Candidate match star 2: %d, magnitude: %.1f \n",m2,r); + + fprintf(stdout,"Angle star 1 to star 2: %f \n",d); + d=atan((ast->y[m2]-ast->y[m1]) / (ast->x[m2]-ast->x[m1])); + fprintf(stdout,"Angle match 1 to match 2: %f \n",d); + d=fabs(d - atan((ast->y[m2]-ast->y[m1]) / (ast->x[m2]-ast->x[m1]))); + fprintf(stdout,"Angle error %f \n",d); + + triast[1]=m2; + nmatch=2; + // Search candidate for 2nd star + // start from the following star that was found as viable candidate last time + // this allows for selecting a new match each time operator launches auto-calibrate + for(m3=triast[2];(nmatch<3) && (m3n);m3++){ + // discard if magn difference is outside match tolerance + r=fabs(cat->mag[s3] - cat->mag[s1]); + if((r - fabs(ast->mag[m3] - ast->mag[m1])) > MAGMATCHTOL){ + fprintf(stdout,"Match 3rdd star %d discarded for mag. match tolerance.\n",m3); + continue; + } + // scale was fixed when found 2nd match candidate, no different scale error is allowed for 3rd matching star + // discard if distance between m3 and m1 is not very similar to distance between s3 and s1 + //**************se esta descartando el triangulo que corresponde por distancia, aumentar tolerancia y revisar... + r=matchscale * sqrt(pow(cat->x[s3]-cat->x[s1],2)+pow(cat->y[s3]-cat->y[s1],2)); + d=sqrt(pow(ast->x[m3]-ast->x[m1],2)+pow(ast->y[m3]-ast->y[m1],2)); + if(fabs(d - r) > DISTMATCHTOL){ + fprintf(stdout,"Match 3rd star %d discarded for distance to 1st match star error: %f against %f.\n",m3,r,d); + continue; + } + // discard if distance between m3 and m2 is not very similar to distance between s3 and s2 + r=matchscale * sqrt(pow(cat->x[s3]-cat->x[s2],2)+pow(cat->y[s3]-cat->y[s2],2)); + if(fabs(sqrt(pow(ast->x[m3]-ast->x[m2],2)+pow(ast->y[m3]-ast->y[m2],2)) - r) > DISTMATCHTOL){ + fprintf(stdout,"Match 3rd star %d discarded for distance to 2nd match star error.\n",m3); + continue; + } + // check angle + d=atan((cat->y[s3]-cat->y[s1]) / (cat->x[s3]-cat->x[s1])); + if(fabs(d - atan((ast->y[m3]-ast->y[m1]) / (ast->x[m3]-ast->x[m1]))) > MAXROT){ + fprintf(stdout,"Match 3rd star %d discarded for rotation error.\n",m3); + continue; + } + // m3 is viable candidate for match to 3rd star + r=ast->mag[m3]; + fprintf(stdout,"Candidate match star 3: %d, magnitude: %.1f \n",m3,r); + triast[2]=m3; + nmatch=3; + } + // if no match found next try will search again for all possible 3rd match stars + if(nmatch<3) triast[2]=0; + } + // if no match found next try will search again for all possible 2nd match stars + if(nmatch<3) triast[1]=0; + } + if(nmatch<3){ + triast[0]=0; + triast[1]=0; + triast[2]=0; + // try new 3rd star + *nselect=2; + fprintf(stdout,"No match found for this triangle\n"); + } + } + // if no triangle selected we will try next 2nd star and try again all possible 3rd stars + if(*nselect<3) tricat[2]=0; + fprintf(stdout,"Try next 2nd star.\n"); + } + // if no triangle selected we will try next 1st star and try again all possible 2nd stars + if(*nselect<3) tricat[1]=0; + fprintf(stdout,"Try next 1st star.\n"); + } + // at this point either found 3 candidate stars or already tried all candidate stars without success + // if loop continues will look for smaller triangles and accept higher magnitudes next iteration + if(*nselect<3){ + size/=1.25; + mave+=0.25; + } + fprintf(stdout,"Decrase minimum size and increase max magnitude for next search.\n"); + } + // if we could not find suitable triplet erase tricat[] + if(*nselect<3){ + tricat[0]=0; + tricat[1]=0; + tricat[2]=0; + fprintf(stdout,"Did not find any suitable reference triangle.\n"); + } + return; +} + + int main(int argc,char *argv[]) { int i; @@ -298,6 +641,7 @@ int main(int argc,char *argv[]) int nx,ny; FILE *file; char *env,starfile[128]; + int tricat[3],triast[3],n; // Environment variables env=getenv("ST_DATADIR"); @@ -324,7 +668,7 @@ int main(int argc,char *argv[]) } else { file=fopen("position.txt","r"); if (file==NULL) { - fprintf(stderr,"No position file found\n"); + fprintf(stdout,"No position file found\n"); return 0; } fscanf(file,"%s %s",sra,sde); @@ -344,7 +688,7 @@ int main(int argc,char *argv[]) if (file==NULL) { sx=-36.15; sy=33.22; - fprintf(stderr,"No camera file found, using default pixel scale values %3.2f %3.2f\n",sx,sy); + fprintf(stdout,"No camera file found, using default pixel scale values %3.2f %3.2f\n",sx,sy); } else{ // Obtain FOV and image resolution from camera file @@ -354,7 +698,7 @@ int main(int argc,char *argv[]) sy=fh/ny*3600; // Check scheduled camera resolution against FITS image file resolution if((abs(nx)!=img.naxis1) || (abs(ny)!=img.naxis2)){ - fprintf(stderr,"Warning: scheduled camera resolution %dx%d does not match image resolution %dx%d",nx,ny,img.naxis1,img.naxis2); + fprintf(stdout,"Warning: scheduled camera resolution %dx%d does not match image resolution %dx%d\n",nx,ny,img.naxis1,img.naxis2); } } @@ -383,6 +727,7 @@ int main(int argc,char *argv[]) zmin=img.zmin; zmax=img.zmax; + // For ever loop for (;;) { if (redraw==1) { @@ -395,30 +740,57 @@ int main(int argc,char *argv[]) cpgctab (heat_l,heat_r,heat_g,heat_b,5,1.0,0.5); cpgimag(img.z,img.naxis1,img.naxis2,1,img.naxis1,1,img.naxis2,img.zmin,img.zmax,tr); cpgbox("BCTSNI",0.,0,"BCTSNI",0.,0); - + + + // Plot triangle of calibration stars + if(nselect>=2){ + // imaged catalog + cpgmove(cat.x[tricat[0]],cat.y[tricat[0]]); + fprintf(stdout,"\nRef.triangle: "); + fprintf(stdout,"%d, ",tricat[0]); + for(i=1;(i<3 && i0){ + cpgmove(ast.x[triast[0]],ast.y[triast[0]]); + fprintf(stdout,"\nMatch triangle: "); + fprintf(stdout,"%d, ",triast[0]); + for(i=1;(i<3 && i=3) { fit_transformation(cat,ast,nselect); ast=reread_astrometric_catalog(starfile,mag+1); + tricat[0]=0; + triast[0]=0; + tricat[1]=0; + triast[1]=0; + tricat[2]=0; + triast[2]=-1; + nselect=0; redraw=1; } // Reread if (c=='R') { - ast=reread_astrometric_catalog(starfile,mag+1); + for (i=0;i0) { From cc0e0c0bffa8c8e184f3dcea7aa866def840b6a2 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 9 Jul 2017 07:21:09 -0300 Subject: [PATCH 04/53] Work in progress: Automatic image calibration --- plotfits.c | 167 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 128 insertions(+), 39 deletions(-) diff --git a/plotfits.c b/plotfits.c index 09c1a41..5afc19a 100644 --- a/plotfits.c +++ b/plotfits.c @@ -17,11 +17,12 @@ // fall outside astrometric field. This should change to arcseconds in the future and be used to widen // the astrometric catalog so that it's scale is grater than that of the imaged catalog just enough // to be sure it includes all imaged stars even at the worst pointing error. -#define MAXROT 10*D2R // Maximum expected rotation error (radians) +#define MAXROT 20*D2R // Maximum expected rotation error (radians) #define DISTMATCHTOL 4 -#define MAGMATCHTOL 1 +#define MAGMATCHTOL 0.5 #define MAXSCALERR 1.05 -#define MAXMAGERR 4 +#define MAXMAGERR 2 +#define DEBUG 2 struct star { double ra,de; @@ -293,7 +294,7 @@ void get_site(int site_id) // Identify matching triangles in imaged and astrometric catalogs void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, int tricat[3], int triast[3]) { - float r,d; + float r,d,d2; float mmax,mmin,matchscale; float error=MAXPOINTERR; // maximum expected pointing error in pixels int i,s1,s2,s3,m1,m2,m3; @@ -328,11 +329,12 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, mave/=cat->n; } +#if DEBUG>0 if(size<0) fprintf(stdout,"Error: Pointing inaccuracy too high\n"); - fprintf(stdout,"Stars in imaged catalog: %d, stars in astrometric catalog: %d.\n", cat->n, ast->n); fprintf(stdout,"MMin:%.1f,MMax:%.1f,MAve.:%.1f \n",mmin,mmax,mave); +#endif // if last time a suitable reference triangle was found if(*nselect==3){ @@ -340,7 +342,9 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, if(nmatch==3){ // this time search for another match beginning with the following 3rd star triast[2]++; - fprintf(stdout,"Try different match.\n"); +#if DEBUG>2 + fprintf(stdout,"Try different match.\n"); +#endif } else{ // no match was found for last suitable triangle @@ -350,7 +354,9 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, triast[0]=0; triast[1]=0; triast[2]=0; +#if DEBUG>2 fprintf(stdout,"Try different triangle.\n"); +#endif } } @@ -359,118 +365,130 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // is found while((*nselect<3) && (size > 10)){ +#if DEBUG>1 fprintf(stdout,"Looking for triangles with min size %4.0f\n",size); - +#endif // Search candidate for 1st star for(s1=tricat[0];(*nselect<3) && (s1 < cat->n);s1++){ // discard if outside high magnitude range r=cat->mag[s1]; if(r > mave){ +#if DEBUG>2 fprintf(stdout,"Star %d discarded for high magnitude.\n",s1); +#endif continue; } // discard if too close to any edge if((cat->x[s1] < error) || (cat->x[s1] > (img.naxis1-error))){ +#if DEBUG>2 fprintf(stdout,"Star %d discarded for close to edge.\n",s1); +#endif continue; } if((cat->y[s1] < error) || (cat->y[s1] > (img.naxis2-error))){ +#if DEBUG>2 fprintf(stdout,"Star %d discarded for close to edge.\n",s1); +#endif continue; } // s1 is viable candidate for 1st star +#if DEBUG>1 fprintf(stdout,"Candidate star 1: %d, magnitude: %.1f \n",s1,r); +#endif tricat[0]=s1; *nselect=1; +#if DEBUG>1 fprintf(stdout,"Looking for 2nd star of triangle.\n"); +#endif // Search candidate for 2nd star for(s2=tricat[1];(*nselect<3) && (s2 < cat->n);s2++){ // discard candidate if outside magnitude range r=cat->mag[s2]; if(r > mave){ +#if DEBUG>2 fprintf(stdout,"Star %d discarded for high magnitude.\n",s2); +#endif continue; } // discard if too close to any edge if((cat->x[s2] < error) || (cat->x[s2] > (img.naxis1-error))){ +#if DEBUG>2 fprintf(stdout,"Star %d discarded for close to edge.\n",s2); +#endif continue; } if((cat->y[s2] < error) || (cat->y[s2] > (img.naxis2-error))){ +#if DEBUG>2 fprintf(stdout,"Star %d discarded for close to edge.\n",s2); +#endif continue; } // discard if too close to star 1 r=sqrt(pow(cat->x[s2]-cat->x[s1],2)+pow(cat->y[s2]-cat->y[s1],2)); if(r < size){ +#if DEBUG>2 fprintf(stdout,"Star %d discarded for close to 1st star.\n",s2); +#endif continue; } // s2 is viable candidate for 2nd star +#if DEBUG>1 fprintf(stdout,"Candidate star 2: %d, magnitude: %.1f, distance to star 1: %.1f \n",s2,cat->mag[s2],r); +#endif tricat[1]=s2; *nselect=2; +#if DEBUG>1 fprintf(stdout,"Looking for 3rd star of triangle.\n"); +#endif // Search candidate for 3rd star beginning from the last candidate found for(s3=tricat[2];(*nselect<3) && (s3 < cat->n);s3++){ // discard candidate if outside magnitude range r=cat->mag[s3]; if(r > mave){ +#if DEBUG>2 fprintf(stdout,"Star %d discarded for high magnitude.\n",s3); +#endif continue; } // discard if too close to any edge if((cat->x[s3] < error) || (cat->x[s3] > (img.naxis1-error))){ +#if DEBUG>2 fprintf(stdout,"Star %d discarded for close to edge.\n",s3); +#endif continue; } if((cat->y[s3] < error) || (cat->y[s3] > (img.naxis2-error))){ +#if DEBUG>2 fprintf(stdout,"Star %d discarded for close to edge.\n",s3); +#endif continue; } // discard if too close to star 1 r=sqrt(pow(cat->x[s3]-cat->x[s1],2)+pow(cat->y[s3]-cat->y[s1],2)); if(r < size){ +#if DEBUG>2 fprintf(stdout,"Star %d discarded for close to 1st star.\n",s3); +#endif continue; } // discard if too close to star 2 r=sqrt(pow(cat->x[s3]-cat->x[s2],2)+pow(cat->y[s3]-cat->y[s2],2)); if(r < size){ +#if DEBUG>2 fprintf(stdout,"Star %d discarded for close to 2nd star.\n",s3); +#endif continue; } // s3 is viable candidate for 3rd star +#if DEBUG>1 fprintf(stdout,"Candidate star 3: %d, magnitude: %.1f, distance to star 2: %.1f \n",s3,cat->mag[s3],r); +#endif tricat[2]=s3; *nselect=3; - - - // **************************** - // **************************** - // **************************** - // **************************** - //Ref.triangle: 8, 86, 91, - //Match triangle: 125, 64, 115, - //Ref.triangle: 8, 94, 161, - //Match triangle: 125, 1, 90, -//Ref.triangle: 8, 159, 161, -//Match triangle: 125, 55, 90, -//Ref.triangle: 8, 152, 129, -//Match triangle: 151, 54, 120, -//Ref.triangle: 8, 77, 129, -//Match triangle: 125, 24, 120, - -//Está matcheando!!! -//ahora habría que descartar mirrors verticales y/o horizontales y limitar la rotación para llegar más directo - - if(s1==8 && s2==86 && s3==91){ - fprintf(stdout,"Special reference triangle found!!!\n"); - } - + // ************************************************************ // Calibration triangle candidate found! // time to look for matching triangle in astrometric catalog... @@ -494,12 +512,16 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // this tolerance includes magnitude extraction tolerance on sextractor tool r=fabs(cat->mag[s1] - ast->mag[m1]); if(r > MAXMAGERR){ +#if DEBUG>2 fprintf(stdout,"Match 1st star %d discarded for mag. difference.\n",m1); +#endif continue; } r=ast->mag[m1]; // m1 is viable candidate for match to 1st star +#if DEBUG>1 fprintf(stdout,"Candidate match star 1: %d, magnitude: %.1f \n",m1,r); +#endif triast[0]=m1; nmatch=1; // Search candidate for 2nd star @@ -508,7 +530,9 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // discard if difference is outside match tolerance r=fabs(cat->mag[s2] - cat->mag[s1]); if((r - fabs(ast->mag[m2] - ast->mag[m1])) > MAGMATCHTOL){ +#if DEBUG>2 fprintf(stdout,"Match 2nd star %d discarded for mag. match tolerance.\n",m2); +#endif continue; } // distance from star 1 to star 2 should resemble distance from matching star 1 to matching star 2 allowing for @@ -516,32 +540,51 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, r=sqrt(pow(cat->x[s2]-cat->x[s1],2)+pow(cat->y[s2]-cat->y[s1],2)); // discard if distance between m2 and m1 is too far from distance between s2 and s1 if(sqrt(pow(ast->x[m2]-ast->x[m1],2)+pow(ast->y[m2]-ast->y[m1],2)) / r > MAXSCALERR){ +#if DEBUG>2 fprintf(stdout,"Match 2nd star %d discarded for distance to 1st match star error.\n",m2); +#endif continue; } if(r / sqrt(pow(ast->x[m2]-ast->x[m1],2)+pow(ast->y[m2]-ast->y[m1],2)) > MAXSCALERR){ +#if DEBUG>2 fprintf(stdout,"Match 2nd star %d discarded for distance to 1st match star error.\n",m2); +#endif continue; } // check angle d=atan((cat->y[s2]-cat->y[s1]) / (cat->x[s2]-cat->x[s1])); - if(fabs(d - atan((ast->y[m2]-ast->y[m1]) / (ast->x[m2]-ast->x[m1]))) > MAXROT){ + if((cat->x[s2]-cat->x[s1]) < 0){ + if(d >= 0) d -= M_PI; + else d += M_PI; + } + d2=atan((ast->y[m2]-ast->y[m1]) / (ast->x[m2]-ast->x[m1])); + if((ast->x[m2]-ast->x[m1]) < 0){ + if(d2 >= 0) d2 -= M_PI; + else d2 += M_PI; + } + if(fabs(d - d2) > MAXROT){ +#if DEBUG>2 fprintf(stdout,"Match 2nd star %d discarded for rotation error.\n",m2); +#endif continue; - } + } // keep scale to check for coherence with third matching star matchscale=sqrt(pow(ast->x[m2]-ast->x[m1],2)+pow(ast->y[m2]-ast->y[m1],2)) / r; +#if DEBUG>1 fprintf(stdout,"Triangle size match scale: %f.2.\n",matchscale); +#endif // m2 is viable candidate for match to 2nd star r=ast->mag[m2]; +#if DEBUG>1 fprintf(stdout,"Candidate match star 2: %d, magnitude: %.1f \n",m2,r); - +#endif +#if DEBUG>2 fprintf(stdout,"Angle star 1 to star 2: %f \n",d); d=atan((ast->y[m2]-ast->y[m1]) / (ast->x[m2]-ast->x[m1])); fprintf(stdout,"Angle match 1 to match 2: %f \n",d); d=fabs(d - atan((ast->y[m2]-ast->y[m1]) / (ast->x[m2]-ast->x[m1]))); fprintf(stdout,"Angle error %f \n",d); - +#endif triast[1]=m2; nmatch=2; // Search candidate for 2nd star @@ -551,7 +594,9 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // discard if magn difference is outside match tolerance r=fabs(cat->mag[s3] - cat->mag[s1]); if((r - fabs(ast->mag[m3] - ast->mag[m1])) > MAGMATCHTOL){ +#if DEBUG>2 fprintf(stdout,"Match 3rdd star %d discarded for mag. match tolerance.\n",m3); +#endif continue; } // scale was fixed when found 2nd match candidate, no different scale error is allowed for 3rd matching star @@ -560,24 +605,41 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, r=matchscale * sqrt(pow(cat->x[s3]-cat->x[s1],2)+pow(cat->y[s3]-cat->y[s1],2)); d=sqrt(pow(ast->x[m3]-ast->x[m1],2)+pow(ast->y[m3]-ast->y[m1],2)); if(fabs(d - r) > DISTMATCHTOL){ +#if DEBUG>2 fprintf(stdout,"Match 3rd star %d discarded for distance to 1st match star error: %f against %f.\n",m3,r,d); +#endif continue; } // discard if distance between m3 and m2 is not very similar to distance between s3 and s2 r=matchscale * sqrt(pow(cat->x[s3]-cat->x[s2],2)+pow(cat->y[s3]-cat->y[s2],2)); if(fabs(sqrt(pow(ast->x[m3]-ast->x[m2],2)+pow(ast->y[m3]-ast->y[m2],2)) - r) > DISTMATCHTOL){ +#if DEBUG>2 fprintf(stdout,"Match 3rd star %d discarded for distance to 2nd match star error.\n",m3); +#endif continue; } // check angle d=atan((cat->y[s3]-cat->y[s1]) / (cat->x[s3]-cat->x[s1])); - if(fabs(d - atan((ast->y[m3]-ast->y[m1]) / (ast->x[m3]-ast->x[m1]))) > MAXROT){ + if((cat->x[s3]-cat->x[s1]) < 0){ + if(d >= 0) d -= M_PI; + else d += M_PI; + } + d2=atan((ast->y[m3]-ast->y[m1]) / (ast->x[m3]-ast->x[m1])); + if((ast->x[m3]-ast->x[m1]) < 0){ + if(d2 >= 0) d2 -= M_PI; + else d2 += M_PI; + } + if(fabs(d - d2) > MAXROT){ +#if DEBUG>2 fprintf(stdout,"Match 3rd star %d discarded for rotation error.\n",m3); +#endif continue; } // m3 is viable candidate for match to 3rd star r=ast->mag[m3]; - fprintf(stdout,"Candidate match star 3: %d, magnitude: %.1f \n",m3,r); +#if DEBUG>1 + fprintf(stdout,"Match found with 3rd match star: %d, magnitude: %.1f \n",m3,r); +#endif triast[2]=m3; nmatch=3; } @@ -593,31 +655,41 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, triast[2]=0; // try new 3rd star *nselect=2; +#if DEBUG>1 fprintf(stdout,"No match found for this triangle\n"); +#endif } } // if no triangle selected we will try next 2nd star and try again all possible 3rd stars if(*nselect<3) tricat[2]=0; +#if DEBUG>2 fprintf(stdout,"Try next 2nd star.\n"); +#endif } // if no triangle selected we will try next 1st star and try again all possible 2nd stars if(*nselect<3) tricat[1]=0; +#if DEBUG>2 fprintf(stdout,"Try next 1st star.\n"); +#endif } // at this point either found 3 candidate stars or already tried all candidate stars without success // if loop continues will look for smaller triangles and accept higher magnitudes next iteration if(*nselect<3){ size/=1.25; mave+=0.25; +#if DEBUG>1 + fprintf(stdout,"Decrased minimum size and increase max magnitude for next search.\n"); +#endif } - fprintf(stdout,"Decrase minimum size and increase max magnitude for next search.\n"); } - // if we could not find suitable triplet erase tricat[] + // if we could not find suitable triplet erase triange in catalog tricat[] if(*nselect<3){ tricat[0]=0; tricat[1]=0; tricat[2]=0; +#if DEBUG>1 fprintf(stdout,"Did not find any suitable reference triangle.\n"); +#endif } return; } @@ -746,21 +818,29 @@ int main(int argc,char *argv[]) if(nselect>=2){ // imaged catalog cpgmove(cat.x[tricat[0]],cat.y[tricat[0]]); +#if DEBUG>1 fprintf(stdout,"\nRef.triangle: "); fprintf(stdout,"%d, ",tricat[0]); +#endif for(i=1;(i<3 && i1 fprintf(stdout,"%d, ",tricat[i]); +#endif } cpgdraw(cat.x[tricat[0]],cat.y[tricat[0]]); // astrometric catalog if(triast[2]>0){ cpgmove(ast.x[triast[0]],ast.y[triast[0]]); +#if DEBUG>1 fprintf(stdout,"\nMatch triangle: "); fprintf(stdout,"%d, ",triast[0]); +#endif for(i=1;(i<3 && i1 fprintf(stdout,"%d, ",triast[i]); +#endif } cpgdraw(ast.x[triast[0]],ast.y[triast[0]]); } @@ -875,6 +955,15 @@ int main(int argc,char *argv[]) // Autoidentify triangles in imaged and astrometric catalogs if (c=='i') { identify_triangles(&cat,&ast,&nselect,tricat,triast); + // if match was found mark stars into selected fields of catalogs + if((nselect >=3) && (triast[2] > 0)){ + cat.select[tricat[0]]=1; + cat.select[tricat[1]]=2; + cat.select[tricat[2]]=3; + ast.select[triast[0]]=1; + ast.select[triast[1]]=2; + ast.select[triast[2]]=3; + } redraw=1; click=1; } From 11162204555bfd15af0fe0b2d10b2d1918f41d06 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sat, 15 Jul 2017 03:54:51 -0300 Subject: [PATCH 05/53] Add semi-automatic image calibration (work in progress) --- plotfits.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/plotfits.c b/plotfits.c index 5afc19a..4931491 100644 --- a/plotfits.c +++ b/plotfits.c @@ -337,7 +337,7 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, #endif // if last time a suitable reference triangle was found - if(*nselect==3){ + if(*nselect>=3){ // and also a match was found if(nmatch==3){ // this time search for another match beginning with the following 3rd star @@ -370,7 +370,7 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, #endif // Search candidate for 1st star - for(s1=tricat[0];(*nselect<3) && (s1 < cat->n);s1++){ + for(s1=tricat[0];(*nselect<3) && (s1 <= cat->n);s1++){ // discard if outside high magnitude range r=cat->mag[s1]; if(r > mave){ @@ -403,7 +403,7 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, fprintf(stdout,"Looking for 2nd star of triangle.\n"); #endif // Search candidate for 2nd star - for(s2=tricat[1];(*nselect<3) && (s2 < cat->n);s2++){ + for(s2=tricat[1];(*nselect<3) && (s2 <= cat->n);s2++){ // discard candidate if outside magnitude range r=cat->mag[s2]; if(r > mave){ @@ -444,7 +444,7 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, fprintf(stdout,"Looking for 3rd star of triangle.\n"); #endif // Search candidate for 3rd star beginning from the last candidate found - for(s3=tricat[2];(*nselect<3) && (s3 < cat->n);s3++){ + for(s3=tricat[2];(*nselect<3) && (s3 <= cat->n);s3++){ // discard candidate if outside magnitude range r=cat->mag[s3]; if(r > mave){ @@ -504,10 +504,14 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // a tolerance for this match is given also as a ratio and should be low // also magnitude difference between stars of astrometric cat should closely match magn diff between stars of img cat. // a tolerance for this magnitude match is given and should not be high (0.5 magn) - + +//persiste un problema con la identificacion de triangulos y el fit +//el fit da mal con el segundo triangulo pero da bien con el cuarto que es el mismo triangulo con el orden de 2da y 3er estrellas intercambiadas + + nmatch=0; // Search for candidate 1st match star - for(m1=triast[0];((nmatch<3) && (m1n));m1++){ + for(m1=triast[0];((nmatch<3) && (m1<=ast->n));m1++){ // discard if outside magnitude tolerance // this tolerance includes magnitude extraction tolerance on sextractor tool r=fabs(cat->mag[s1] - ast->mag[m1]); @@ -525,7 +529,7 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, triast[0]=m1; nmatch=1; // Search candidate for 2nd star - for(m2=triast[1];(nmatch<3) && (m2n);m2++){ + for(m2=triast[1];(nmatch<3) && (m2<=ast->n);m2++){ // magn difference between star 1 and star 2 should be very close to magn diff between matching star 1 and matching star 2 // discard if difference is outside match tolerance r=fabs(cat->mag[s2] - cat->mag[s1]); @@ -590,7 +594,7 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // Search candidate for 2nd star // start from the following star that was found as viable candidate last time // this allows for selecting a new match each time operator launches auto-calibrate - for(m3=triast[2];(nmatch<3) && (m3n);m3++){ + for(m3=triast[2];(nmatch<3) && (m3<=ast->n);m3++){ // discard if magn difference is outside match tolerance r=fabs(cat->mag[s3] - cat->mag[s1]); if((r - fabs(ast->mag[m3] - ast->mag[m1])) > MAGMATCHTOL){ @@ -661,16 +665,20 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, } } // if no triangle selected we will try next 2nd star and try again all possible 3rd stars - if(*nselect<3) tricat[2]=0; + if(*nselect<3){ + tricat[2]=0; #if DEBUG>2 - fprintf(stdout,"Try next 2nd star.\n"); + fprintf(stdout,"Try next 2nd star.\n"); #endif + } } // if no triangle selected we will try next 1st star and try again all possible 2nd stars - if(*nselect<3) tricat[1]=0; + if(*nselect<3){ + tricat[1]=0; #if DEBUG>2 - fprintf(stdout,"Try next 1st star.\n"); + fprintf(stdout,"Try next 1st star.\n"); #endif + } } // at this point either found 3 candidate stars or already tried all candidate stars without success // if loop continues will look for smaller triangles and accept higher magnitudes next iteration @@ -678,7 +686,7 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, size/=1.25; mave+=0.25; #if DEBUG>1 - fprintf(stdout,"Decrased minimum size and increase max magnitude for next search.\n"); + fprintf(stdout,"Decrased minimum size and increase max magnitude for next search.\n"); #endif } } @@ -799,7 +807,6 @@ int main(int argc,char *argv[]) zmin=img.zmin; zmax=img.zmax; - // For ever loop for (;;) { if (redraw==1) { @@ -957,18 +964,24 @@ int main(int argc,char *argv[]) identify_triangles(&cat,&ast,&nselect,tricat,triast); // if match was found mark stars into selected fields of catalogs if((nselect >=3) && (triast[2] > 0)){ - cat.select[tricat[0]]=1; + // erase prior selection first + for (i=0;i Date: Sat, 15 Jul 2017 04:24:39 -0300 Subject: [PATCH 06/53] Add semi-automatic image calibration (work in progress) --- plotfits.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plotfits.c b/plotfits.c index 4931491..9d6990c 100644 --- a/plotfits.c +++ b/plotfits.c @@ -22,7 +22,7 @@ #define MAGMATCHTOL 0.5 #define MAXSCALERR 1.05 #define MAXMAGERR 2 -#define DEBUG 2 +#define DEBUG 0 struct star { double ra,de; @@ -329,11 +329,13 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, mave/=cat->n; } -#if DEBUG>0 - if(size<0) - fprintf(stdout,"Error: Pointing inaccuracy too high\n"); + if(size<0){ + fprintf(stdout,"Warning: Pointing inaccuracy too high\n"); + size=10; + } +#if DEBUG>1 fprintf(stdout,"Stars in imaged catalog: %d, stars in astrometric catalog: %d.\n", cat->n, ast->n); - fprintf(stdout,"MMin:%.1f,MMax:%.1f,MAve.:%.1f \n",mmin,mmax,mave); + fprintf(stdout,"MMin:%2.1f,MMax:%2.1f,MAve.:%2.1f \n",mmin,mmax,mave); #endif // if last time a suitable reference triangle was found From 7ae0ef1af7b31a567acab12472e9d4256ec9b453 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 16 Jul 2017 02:58:24 -0300 Subject: [PATCH 07/53] Semi-automatic image calibration debugging --- plotfits.c | 58 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/plotfits.c b/plotfits.c index 9d6990c..9dd9ad2 100644 --- a/plotfits.c +++ b/plotfits.c @@ -13,16 +13,17 @@ #define R2D 180.0/M_PI #define NMAX 4096 #define MAXPOINTERR 40 // Maximum pointing error (pixels) - // Do not auto-choose reference stars closer than this to any edge (in pixels) because matching star may - // fall outside astrometric field. This should change to arcseconds in the future and be used to widen + // Algorithm will not choose reference stars closer than this amount to any edge (in pixels) + // because matching star may fall outside astrometric field. + // This should change to arcseconds in the future and be used to widen // the astrometric catalog so that it's scale is grater than that of the imaged catalog just enough // to be sure it includes all imaged stars even at the worst pointing error. -#define MAXROT 20*D2R // Maximum expected rotation error (radians) -#define DISTMATCHTOL 4 -#define MAGMATCHTOL 0.5 -#define MAXSCALERR 1.05 -#define MAXMAGERR 2 -#define DEBUG 0 +#define MAXROT 10*D2R // Maximum expected rotation error (radians) +#define MAXSCALERR 1.05 // Expected scaling error +#define DISTMATCHTOL 4 // Distance tolerance between matching stars after aplying scale error +#define MAXMAGERR 2.5 // Expected magnitude error between imaged stars and corresponding astometric catalog star +#define MAGMATCHTOL 0.5 // Relative magnitude between mathing stars tolerance +#define DEBUG 3 struct star { double ra,de; @@ -487,6 +488,9 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // s3 is viable candidate for 3rd star #if DEBUG>1 fprintf(stdout,"Candidate star 3: %d, magnitude: %.1f, distance to star 2: %.1f \n",s3,cat->mag[s3],r); + fprintf(stdout,"\n"); + fprintf(stdout,"Reference triangle: %d, %d, %d\n",s1,s2,s3); + fprintf(stdout,"Magnitudes: %f, %f, %f\n",cat->mag[s1],cat->mag[s2],cat->mag[s3]); #endif tricat[2]=s3; *nselect=3; @@ -586,28 +590,48 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, #endif #if DEBUG>2 fprintf(stdout,"Angle star 1 to star 2: %f \n",d); - d=atan((ast->y[m2]-ast->y[m1]) / (ast->x[m2]-ast->x[m1])); - fprintf(stdout,"Angle match 1 to match 2: %f \n",d); - d=fabs(d - atan((ast->y[m2]-ast->y[m1]) / (ast->x[m2]-ast->x[m1]))); + d2=atan((ast->y[m2]-ast->y[m1]) / (ast->x[m2]-ast->x[m1])); + fprintf(stdout,"Angle match 1 to match 2: %f \n",d2); + d=fabs(d - d2); fprintf(stdout,"Angle error %f \n",d); #endif triast[1]=m2; nmatch=2; - // Search candidate for 2nd star - // start from the following star that was found as viable candidate last time + // Search candidate for 3rd star + // start from the following star that was found as viable candidate last time this routine was run // this allows for selecting a new match each time operator launches auto-calibrate for(m3=triast[2];(nmatch<3) && (m3<=ast->n);m3++){ // discard if magn difference is outside match tolerance r=fabs(cat->mag[s3] - cat->mag[s1]); if((r - fabs(ast->mag[m3] - ast->mag[m1])) > MAGMATCHTOL){ #if DEBUG>2 - fprintf(stdout,"Match 3rdd star %d discarded for mag. match tolerance.\n",m3); + fprintf(stdout,"Match 3rd star %d discarded for mag. match tolerance.\n",m3); #endif continue; } + + // discard this star if matching triangle center is too far from reference triangle center + // check pointing error along X axis + r=(cat->x[s1] + cat->x[s2] + cat->x[s3]) / 3; + d=(ast->x[m1] + ast->x[m2] + ast->x[m3]) / 3; + if((d2=fabs(d - r)) > error){ +#if DEBUG>2 + fprintf(stdout,"Match 3rd star %d discarded for excesive X pointing error: %f.\n",m3,d2); +#endif + continue; + } + // check pointing error along Y axis + r=(cat->y[s1] + cat->y[s2] + cat->y[s3]) / 3; + d=(ast->y[m1] + ast->y[m2] + ast->y[m3]) / 3; + if((d2=fabs(d - r)) > error){ +#if DEBUG>2 + fprintf(stdout,"Match 3rd star %d discarded for excesive Y pointing error: %f.\n",m3,d2); +#endif + continue; + } + // scale was fixed when found 2nd match candidate, no different scale error is allowed for 3rd matching star // discard if distance between m3 and m1 is not very similar to distance between s3 and s1 - //**************se esta descartando el triangulo que corresponde por distancia, aumentar tolerancia y revisar... r=matchscale * sqrt(pow(cat->x[s3]-cat->x[s1],2)+pow(cat->y[s3]-cat->y[s1],2)); d=sqrt(pow(ast->x[m3]-ast->x[m1],2)+pow(ast->y[m3]-ast->y[m1],2)); if(fabs(d - r) > DISTMATCHTOL){ @@ -952,13 +976,13 @@ int main(int argc,char *argv[]) // Select pixel catalog if (c=='1') { i=select_nearest(cat,x,y); - fprintf(stdout,"%d",i); + fprintf(stdout,"Imaged star %d, Mag. %f\n",i,cat.mag[i]); } // Select catalog if (c=='2') { i=select_nearest(ast,x,y); - fprintf(stdout,"%d",i); + fprintf(stdout,"Asto.Catalog star %d, Mag. %f\n",i,ast.mag[i]); } // Autoidentify triangles in imaged and astrometric catalogs From f3337a4fb2ca027d5c9f9061707e8b411cc3b9fb Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 23 Jul 2017 03:24:27 -0300 Subject: [PATCH 08/53] Implement Az/Alt parameters to cameras.txt for fixed cameras, runsched checks for fixed cameras, skymap auto center map to fixed camera position. --- data/cameras.txt | 3 ++- runsched.c | 63 +++++++++++++++++++++++++++--------------------- skymap.c | 12 ++++++++- 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/data/cameras.txt b/data/cameras.txt index 1b6fc5b..5c23ef3 100644 --- a/data/cameras.txt +++ b/data/cameras.txt @@ -1,5 +1,6 @@ # List of available cameras -# Camera mnemonic (Camera/Optics), field width, field height, horiz resolution (neg.to mirror), vert resolution (neg.to mirror), mount type (AltAz/Eq/XY/Fixed), video device +# Camera mnemonic (Camera/Optics), field width, field height, horiz resolution (neg.to mirror), vert resolution (neg.to mirror), mount type (AltAz/Eq/XY/Fixed), video device , Azimuth (for fixed, south is zero), Altitude (for fixed) +S25H 15 12 -720 576 Fixed /dev/video1 35 42.5 W50H 7.21 5.31 -720 576 AltAz /dev/video1 W28H 13.10 7.97 D85V 9.97 14.96 diff --git a/runsched.c b/runsched.c index 5c2f44f..4a956c4 100644 --- a/runsched.c +++ b/runsched.c @@ -160,40 +160,49 @@ void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname) FILE *file; float ra,de; char camera[128],fname[128]; + float f; + char s[31]; + // Check if camera is fixed + // read complete line from data/cameras.txt describing the scheduled camera + read_cameras(camname,datadir,camera); // search for camera name + sscanf(camera,"%s %f %f %f %f %s", s, &f, &f, &f, &f, s); + // Look for "fix" string... + if(strstr(s,"ix")==NULL){ + + // Old packet style + // sprintf(packet,"%s%s",sra,sde); - // Old packet style - // sprintf(packet,"%s%s",sra,sde); - - // New packet style (as of 2013-08-20) - sprintf(packet,"%s%s",sra,sde); - - // Send TCP packet - skt=socket(AF_INET,SOCK_STREAM,0); - addr.sin_family=AF_INET; - port=PORT; - addr.sin_port=htons(port); - he=gethostbyname(IP); - bcopy(he->h_addr,(struct in_addr *) &addr.sin_addr,he->h_length); - while((connect(skt,(struct sockaddr *) &addr,sizeof(addr))<0) && (port < MAXPORT)) { - fprintf(stderr,"Connection refused by remote host on port %04d.\n",port); - port++; - // Skip port 7265... used by some other service? - if(port==7265) port++; - fprintf(stderr,"Trying port %04d.\n",port); + // New packet style (as of 2013-08-20) + sprintf(packet,"%s%s",sra,sde); + // Send TCP packet + skt=socket(AF_INET,SOCK_STREAM,0); + addr.sin_family=AF_INET; + port=PORT; addr.sin_port=htons(port); he=gethostbyname(IP); bcopy(he->h_addr,(struct in_addr *) &addr.sin_addr,he->h_length); + while((connect(skt,(struct sockaddr *) &addr,sizeof(addr))<0) && (port < MAXPORT)) { + fprintf(stderr,"Connection refused by remote host on port %04d.\n",port); + port++; + // Skip port 7265... used by some other service? + if(port==7265) port++; + fprintf(stderr,"Trying port %04d.\n",port); + addr.sin_port=htons(port); + he=gethostbyname(IP); + bcopy(he->h_addr,(struct in_addr *) &addr.sin_addr,he->h_length); + + } + if(port>=MAXPORT) return; + + printf("Connected to Indi server on port %04d.\n",port); + + write(skt,packet,strlen(packet)); + close(skt); } - if(port>=MAXPORT) return; - - printf("Connected to Indi server on port %04d.\n",port); - - write(skt,packet,strlen(packet)); - close(skt); - + // Set restart sprintf(fname,"%s/control/state.txt",obsdir); file=fopen(fname,"w"); @@ -211,8 +220,6 @@ void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname) } // Set camera - // camera.txt control file with complete line from data/cameras.txt describing the scheduled camera - read_cameras(camname,datadir,camera); // search for camera name sprintf(fname,"%s/control/camera.txt",obsdir); file=fopen(fname,"w"); if (file!=NULL) { diff --git a/skymap.c b/skymap.c index eb5e6f4..79f852a 100644 --- a/skymap.c +++ b/skymap.c @@ -2223,6 +2223,8 @@ void skymap_plotsun(void) int read_camera(int no) { int i=0; + float f,f2; + char s[31]; FILE *file; char line[LIM],filename[LIM]; @@ -2237,7 +2239,15 @@ int read_camera(int no) if (strstr(line,"#")!=NULL) continue; if (i==no) { - sscanf(line,"%s %f %f", m.camera, &m.fw, &m.fh); + f2=-90; + // Retrieve complete line of selected camera parameters + sscanf(line,"%s %f %f %f %f %s %s %f %f", m.camera, &m.fw, &m.fh, &f, &f, s, s, &f, &f2); + if(f2>=0){ + // if Elevation is set, center map on cameras aim + m.azi0=(double)f; + m.alt0=(double)f2; + horizontal2equatorial(m.mjd,m.azi0,m.alt0,&m.ra0,&m.de0); + } m.fw*=0.5; m.fh*=0.5; return 0; From 7a07b6c371a9da6945ff7c06ea125ea230256533 Mon Sep 17 00:00:00 2001 From: fmederos Date: Mon, 24 Jul 2017 00:40:04 -0300 Subject: [PATCH 09/53] Correct map center to camera orientation for fixed cameras --- skymap.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/skymap.c b/skymap.c index 79f852a..147db84 100644 --- a/skymap.c +++ b/skymap.c @@ -2243,7 +2243,7 @@ int read_camera(int no) // Retrieve complete line of selected camera parameters sscanf(line,"%s %f %f %f %f %s %s %f %f", m.camera, &m.fw, &m.fh, &f, &f, s, s, &f, &f2); if(f2>=0){ - // if Elevation is set, center map on cameras aim + // if Elevation is set, center map to camera position m.azi0=(double)f; m.alt0=(double)f2; horizontal2equatorial(m.mjd,m.azi0,m.alt0,&m.ra0,&m.de0); @@ -2269,6 +2269,12 @@ int plot_skymap(void) double ra,de,azi,alt,rx,ry; xyz_t sunpos; + status=read_camera(fov); + if (status==-1) { + fov=0; + status=read_camera(fov); + } + for (;;) { if (redraw>0) { // Get present mjd @@ -2319,12 +2325,6 @@ int plot_skymap(void) if (fov>=0) { cpgsfs(2); - status=read_camera(fov); - if (status==-1) { - fov=0; - status=read_camera(fov); - } - cpgrect(-m.fw,m.fw,-m.fh,m.fh); cpgsfs(1); } @@ -2589,6 +2589,11 @@ int plot_skymap(void) // Toggle focal length if (c=='F') { fov++; + status=read_camera(fov); + if (status==-1) { + fov=0; + status=read_camera(fov); + } redraw=1; } From 2c564cc8c844efc896aa3b72644b54c625c4d9ed Mon Sep 17 00:00:00 2001 From: fmederos Date: Wed, 16 Aug 2017 02:00:31 -0300 Subject: [PATCH 10/53] Testing auto-selectrion of calibration stars. --- data/cameras.txt | 2 +- plotfits.c | 427 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 326 insertions(+), 103 deletions(-) diff --git a/data/cameras.txt b/data/cameras.txt index 5c23ef3..256afd8 100644 --- a/data/cameras.txt +++ b/data/cameras.txt @@ -1,6 +1,6 @@ # List of available cameras # Camera mnemonic (Camera/Optics), field width, field height, horiz resolution (neg.to mirror), vert resolution (neg.to mirror), mount type (AltAz/Eq/XY/Fixed), video device , Azimuth (for fixed, south is zero), Altitude (for fixed) -S25H 15 12 -720 576 Fixed /dev/video1 35 42.5 +S25H 20.3 16.2 -720 576 Fix /dev/video-S25H 32 29.5 W50H 7.21 5.31 -720 576 AltAz /dev/video1 W28H 13.10 7.97 D85V 9.97 14.96 diff --git a/plotfits.c b/plotfits.c index 9dd9ad2..850e353 100644 --- a/plotfits.c +++ b/plotfits.c @@ -7,23 +7,25 @@ #include "qfits.h" #include #include +#include #define LIM 256 #define D2R M_PI/180.0 #define R2D 180.0/M_PI #define NMAX 4096 -#define MAXPOINTERR 40 // Maximum pointing error (pixels) +#define MAXPOINTERR 200 // Maximum pointing error (pixels) // Algorithm will not choose reference stars closer than this amount to any edge (in pixels) // because matching star may fall outside astrometric field. // This should change to arcseconds in the future and be used to widen // the astrometric catalog so that it's scale is grater than that of the imaged catalog just enough // to be sure it includes all imaged stars even at the worst pointing error. #define MAXROT 10*D2R // Maximum expected rotation error (radians) -#define MAXSCALERR 1.05 // Expected scaling error -#define DISTMATCHTOL 4 // Distance tolerance between matching stars after aplying scale error -#define MAXMAGERR 2.5 // Expected magnitude error between imaged stars and corresponding astometric catalog star -#define MAGMATCHTOL 0.5 // Relative magnitude between mathing stars tolerance -#define DEBUG 3 +#define MAXSCALERR 1.05 // Expected image to astrometric map scaling error +#define DISTMATCHTOL 6 // Distance tolerance in pixels between matching stars after aplying scale and rotation +#define MAXMAGERR 2.5 // Expected magnitude error between imaged stars and corresponding astometric catalog stars +#define MAGMATCHTOL 0.5 // Relative magnitude between matching stars tolerance +#define MATCHVALRATIO 0.30 // Ratio of imaged stars that must fit into astrometric catalog after applying matching transformation +#define DEBUG 0 struct star { double ra,de; @@ -295,13 +297,16 @@ void get_site(int site_id) // Identify matching triangles in imaged and astrometric catalogs void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, int tricat[3], int triast[3]) { - float r,d,d2; - float mmax,mmin,matchscale; + float r,d,d2,x,y; + float mag12,mag13,mag23,ang12,ang13,dis12,dis13,dis23,cenX,cenY; + float mmax,mmin,matchscale,matchrot,matchXtras,matchYtras; float error=MAXPOINTERR; // maximum expected pointing error in pixels - int i,s1,s2,s3,m1,m2,m3; + int i,j,n,n2,s1,s2,s3,m1,m2,m3; static int nmatch; static float mave,size; + clock_t start_t, end_t; + start_t=clock(); // Form a triangle of reference stars from imaged catalog. The following criteria is used: // Triangle should cover as much area of FOV as possible. @@ -314,27 +319,28 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // In the future min distance between stars and estimated pointing error should be given in arcsecs and converted // to pixels - // if no reference triangle has been previousely selected begin star selection from max size and min magnitude - if(*nselect==0){ - size=img.naxis2-4*error; - // Compute magnitude average - mave=0; - for (i=0;in;i++) { - r=cat->mag[i]; - if(r > mmax) - mmax=r; - if(r < mmin) - mmin=r; - mave+=r; - } - mave/=cat->n; +// size=(img.naxis2-error)/2; + size=(img.naxis2-error)/3; + // Compute magnitude average + mave=0; + for (i=0;in;i++) { + r=cat->mag[i]; + if(r > mmax) + mmax=r; + if(r < mmin) + mmin=r; + mave+=r; } + mave/=cat->n; +#if DEBUG>2 + fprintf(stdout,"Image height: %d, Expected error: %f, Ref.Tria.Size: %f\n",img.naxis2,error,size); +#endif if(size<0){ fprintf(stdout,"Warning: Pointing inaccuracy too high\n"); size=10; } -#if DEBUG>1 +#if DEBUG>0 fprintf(stdout,"Stars in imaged catalog: %d, stars in astrometric catalog: %d.\n", cat->n, ast->n); fprintf(stdout,"MMin:%2.1f,MMax:%2.1f,MAve.:%2.1f \n",mmin,mmax,mave); #endif @@ -351,14 +357,15 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, } else{ // no match was found for last suitable triangle - // so search nor another reference triangle starting from the following 3rd star - tricat[2]++; + // so search for another reference triangle starting from the following 3rd star + // commented for testing... + //tricat[2]++; // erase matching triangle triast[0]=0; triast[1]=0; triast[2]=0; #if DEBUG>2 - fprintf(stdout,"Try different triangle.\n"); + fprintf(stdout,"Try different triangle. Size: %f\n",size); #endif } } @@ -383,13 +390,13 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, continue; } // discard if too close to any edge - if((cat->x[s1] < error) || (cat->x[s1] > (img.naxis1-error))){ + if((cat->x[s1] < error/2) || (cat->x[s1] > (img.naxis1-error/2))){ #if DEBUG>2 fprintf(stdout,"Star %d discarded for close to edge.\n",s1); #endif continue; } - if((cat->y[s1] < error) || (cat->y[s1] > (img.naxis2-error))){ + if((cat->y[s1] < error/2) || (cat->y[s1] > (img.naxis2-error/2))){ #if DEBUG>2 fprintf(stdout,"Star %d discarded for close to edge.\n",s1); #endif @@ -416,13 +423,13 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, continue; } // discard if too close to any edge - if((cat->x[s2] < error) || (cat->x[s2] > (img.naxis1-error))){ + if((cat->x[s2] < error/2) || (cat->x[s2] > (img.naxis1-error/2))){ #if DEBUG>2 fprintf(stdout,"Star %d discarded for close to edge.\n",s2); #endif continue; } - if((cat->y[s2] < error) || (cat->y[s2] > (img.naxis2-error))){ + if((cat->y[s2] < error/2) || (cat->y[s2] > (img.naxis2-error/2))){ #if DEBUG>2 fprintf(stdout,"Star %d discarded for close to edge.\n",s2); #endif @@ -457,13 +464,13 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, continue; } // discard if too close to any edge - if((cat->x[s3] < error) || (cat->x[s3] > (img.naxis1-error))){ + if((cat->x[s3] < error/2) || (cat->x[s3] > (img.naxis1-error/2))){ #if DEBUG>2 fprintf(stdout,"Star %d discarded for close to edge.\n",s3); #endif continue; } - if((cat->y[s3] < error) || (cat->y[s3] > (img.naxis2-error))){ + if((cat->y[s3] < error/2) || (cat->y[s3] > (img.naxis2-error/2))){ #if DEBUG>2 fprintf(stdout,"Star %d discarded for close to edge.\n",s3); #endif @@ -488,6 +495,8 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // s3 is viable candidate for 3rd star #if DEBUG>1 fprintf(stdout,"Candidate star 3: %d, magnitude: %.1f, distance to star 2: %.1f \n",s3,cat->mag[s3],r); +#endif +#if DEBUG>0 fprintf(stdout,"\n"); fprintf(stdout,"Reference triangle: %d, %d, %d\n",s1,s2,s3); fprintf(stdout,"Magnitudes: %f, %f, %f\n",cat->mag[s1],cat->mag[s2],cat->mag[s3]); @@ -497,10 +506,10 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // ************************************************************ // Calibration triangle candidate found! - // time to look for matching triangle in astrometric catalog... + // now look for matching triangle in astrometric catalog... // ************************************************************ - // at this point we got 3 reference stars forming suitable triangle, will look for matching triangle in astrometric catalog + // at this point we have got 3 reference stars forming suitable triangle, will look for matching triangle in astrometric catalog // will search by testing relative magnitude and relative distance between suspect matching stars // a scale tolerance is given as a ratio for distances (triangle size) and is assumed as affecting the whole image, // this tolerance could be high. @@ -508,12 +517,55 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // // relative distance between stars of astrometric catalog should closely match relative distances between stars of imaged catalog // a tolerance for this match is given also as a ratio and should be low - // also magnitude difference between stars of astrometric cat should closely match magn diff between stars of img cat. - // a tolerance for this magnitude match is given and should not be high (0.5 magn) + // also magnitude difference between stars of matching triangle should closely match magn diff between stars of imaged + // reference triangle, tolerance for this magnitude match should not be high (0.5 magn or so) -//persiste un problema con la identificacion de triangulos y el fit -//el fit da mal con el segundo triangulo pero da bien con el cuarto que es el mismo triangulo con el orden de 2da y 3er estrellas intercambiadas + //74 + //392 + //107 + //316 + //111 + //319 + //261 stars matched + if(s1==74 && s2==107 && s3==111){ + end_t=clock(); + fprintf(stdout,"Special reference triangle found\n"); + d=(float)(end_t - start_t)/CLOCKS_PER_SEC; + fprintf(stdout,"Seconds elapsed: %f\n",d); +// m1=392; +// m2=316; +// m3=319; +// nmatch=3; +// continue; + start_t=clock(); + } + //74 + //392 + //111 + //319 + //154 + //338 + //252 stars matched + if(s1==74 && s2==111 && s3==154){ + end_t=clock(); + fprintf(stdout,"Special reference triangle found\n"); + d=(float)(end_t - start_t)/CLOCKS_PER_SEC; + fprintf(stdout,"Seconds elapsed: %f\n",d); +// m1=392; +// m2=319; +// m3=338; +// nmatch=3; +// continue; + start_t=clock(); + } +// else{ +// s3++; +// *nselect=2; +// continue; +// } +// con mapa magnitud 8 demora 33 seg. en encontrar el tri{angulo especial +// con precalculo paso a demorar 20seg! nmatch=0; // Search for candidate 1st match star @@ -528,61 +580,61 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, continue; } r=ast->mag[m1]; - // m1 is viable candidate for match to 1st star + // m1 is viable candidate for match to 1st reference star #if DEBUG>1 fprintf(stdout,"Candidate match star 1: %d, magnitude: %.1f \n",m1,r); #endif triast[0]=m1; nmatch=1; + // Calculate some values that will be repeatedly used during match check loop + mag12=cat->mag[s2] - cat->mag[s1]; + dis12=sqrt(pow(cat->x[s2]-cat->x[s1],2)+pow(cat->y[s2]-cat->y[s1],2)); + ang12=atan((cat->y[s2]-cat->y[s1]) / (cat->x[s2]-cat->x[s1])); + if((cat->x[s2]-cat->x[s1]) < 0){ + if(ang12 >= 0) ang12 -= M_PI; + else ang12 += M_PI; + } // Search candidate for 2nd star for(m2=triast[1];(nmatch<3) && (m2<=ast->n);m2++){ - // magn difference between star 1 and star 2 should be very close to magn diff between matching star 1 and matching star 2 + // magn difference between ref stars 1 and 2 should be very close to magn diff between matching stars 1 and 2 // discard if difference is outside match tolerance - r=fabs(cat->mag[s2] - cat->mag[s1]); - if((r - fabs(ast->mag[m2] - ast->mag[m1])) > MAGMATCHTOL){ + if(fabs(mag12 - (ast->mag[m2] - ast->mag[m1])) > MAGMATCHTOL){ #if DEBUG>2 fprintf(stdout,"Match 2nd star %d discarded for mag. match tolerance.\n",m2); #endif continue; } - // distance from star 1 to star 2 should resemble distance from matching star 1 to matching star 2 allowing for + // distance between ref stars 1 and 2 should resemble distance from matching stars 1 and star 2 allowing for // scale tolerance - r=sqrt(pow(cat->x[s2]-cat->x[s1],2)+pow(cat->y[s2]-cat->y[s1],2)); + d=sqrt(pow(ast->x[m2]-ast->x[m1],2)+pow(ast->y[m2]-ast->y[m1],2)) / dis12; // discard if distance between m2 and m1 is too far from distance between s2 and s1 - if(sqrt(pow(ast->x[m2]-ast->x[m1],2)+pow(ast->y[m2]-ast->y[m1],2)) / r > MAXSCALERR){ + if((d > MAXSCALERR) || (1/d > MAXSCALERR)){ #if DEBUG>2 fprintf(stdout,"Match 2nd star %d discarded for distance to 1st match star error.\n",m2); #endif continue; } - if(r / sqrt(pow(ast->x[m2]-ast->x[m1],2)+pow(ast->y[m2]-ast->y[m1],2)) > MAXSCALERR){ -#if DEBUG>2 - fprintf(stdout,"Match 2nd star %d discarded for distance to 1st match star error.\n",m2); + // keep scale to later check for coherence with third matching star + // this scale was obtained from distance ratio between ref stars 1 & 2 and match stars 1 & 2 + matchscale=d; +#if DEBUG>1 + fprintf(stdout,"Triangle size match scale: %f.2.\n",matchscale); #endif - continue; - } // check angle - d=atan((cat->y[s2]-cat->y[s1]) / (cat->x[s2]-cat->x[s1])); - if((cat->x[s2]-cat->x[s1]) < 0){ - if(d >= 0) d -= M_PI; - else d += M_PI; - } d2=atan((ast->y[m2]-ast->y[m1]) / (ast->x[m2]-ast->x[m1])); if((ast->x[m2]-ast->x[m1]) < 0){ if(d2 >= 0) d2 -= M_PI; else d2 += M_PI; } - if(fabs(d - d2) > MAXROT){ + if(fabs(d2 - ang12) > MAXROT){ #if DEBUG>2 fprintf(stdout,"Match 2nd star %d discarded for rotation error.\n",m2); #endif continue; } - // keep scale to check for coherence with third matching star - matchscale=sqrt(pow(ast->x[m2]-ast->x[m1],2)+pow(ast->y[m2]-ast->y[m1],2)) / r; -#if DEBUG>1 - fprintf(stdout,"Triangle size match scale: %f.2.\n",matchscale); -#endif + // keep rotation for later checks + // this rotation was obtained from angle between ref stars 1 & 2 and match stars 1 & 2 + matchrot=d2-d; // m2 is viable candidate for match to 2nd star r=ast->mag[m2]; #if DEBUG>1 @@ -597,13 +649,28 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, #endif triast[1]=m2; nmatch=2; + // calculate values that will be used repeatedly + mag13=cat->mag[s3] - cat->mag[s1]; + mag23=cat->mag[s3] - cat->mag[s2]; + cenX=(cat->x[s1] + cat->x[s2] + cat->x[s3]) / 3; + cenY=(cat->y[s1] + cat->y[s2] + cat->y[s3]) / 3; + dis13=matchscale * sqrt(pow(cat->x[s3]-cat->x[s1],2)+pow(cat->y[s3]-cat->y[s1],2)); + dis23=matchscale * sqrt(pow(cat->x[s3]-cat->x[s2],2)+pow(cat->y[s3]-cat->y[s2],2)); + ang13=atan((cat->y[s3]-cat->y[s1]) / (cat->x[s3]-cat->x[s1])); + if((cat->x[s3]-cat->x[s1]) < 0){ + if(ang13 >= 0) ang13 -= M_PI; + else ang13 += M_PI; + } // Search candidate for 3rd star - // start from the following star that was found as viable candidate last time this routine was run - // this allows for selecting a new match each time operator launches auto-calibrate for(m3=triast[2];(nmatch<3) && (m3<=ast->n);m3++){ // discard if magn difference is outside match tolerance - r=fabs(cat->mag[s3] - cat->mag[s1]); - if((r - fabs(ast->mag[m3] - ast->mag[m1])) > MAGMATCHTOL){ + if(fabs(mag13 - (ast->mag[m3] - ast->mag[m1])) > MAGMATCHTOL){ +#if DEBUG>2 + fprintf(stdout,"Match 3rd star %d discarded for mag. match tolerance.\n",m3); +#endif + continue; + } + if(fabs(mag23 - (ast->mag[m3] - ast->mag[m2])) > MAGMATCHTOL){ #if DEBUG>2 fprintf(stdout,"Match 3rd star %d discarded for mag. match tolerance.\n",m3); #endif @@ -612,18 +679,16 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // discard this star if matching triangle center is too far from reference triangle center // check pointing error along X axis - r=(cat->x[s1] + cat->x[s2] + cat->x[s3]) / 3; d=(ast->x[m1] + ast->x[m2] + ast->x[m3]) / 3; - if((d2=fabs(d - r)) > error){ + if((d2=fabs(d - cenX)) > error){ #if DEBUG>2 fprintf(stdout,"Match 3rd star %d discarded for excesive X pointing error: %f.\n",m3,d2); #endif continue; } // check pointing error along Y axis - r=(cat->y[s1] + cat->y[s2] + cat->y[s3]) / 3; d=(ast->y[m1] + ast->y[m2] + ast->y[m3]) / 3; - if((d2=fabs(d - r)) > error){ + if((d2=fabs(d - cenY)) > error){ #if DEBUG>2 fprintf(stdout,"Match 3rd star %d discarded for excesive Y pointing error: %f.\n",m3,d2); #endif @@ -632,34 +697,27 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // scale was fixed when found 2nd match candidate, no different scale error is allowed for 3rd matching star // discard if distance between m3 and m1 is not very similar to distance between s3 and s1 - r=matchscale * sqrt(pow(cat->x[s3]-cat->x[s1],2)+pow(cat->y[s3]-cat->y[s1],2)); d=sqrt(pow(ast->x[m3]-ast->x[m1],2)+pow(ast->y[m3]-ast->y[m1],2)); - if(fabs(d - r) > DISTMATCHTOL){ + if(fabs(d - dis13) > DISTMATCHTOL){ #if DEBUG>2 fprintf(stdout,"Match 3rd star %d discarded for distance to 1st match star error: %f against %f.\n",m3,r,d); #endif continue; } // discard if distance between m3 and m2 is not very similar to distance between s3 and s2 - r=matchscale * sqrt(pow(cat->x[s3]-cat->x[s2],2)+pow(cat->y[s3]-cat->y[s2],2)); - if(fabs(sqrt(pow(ast->x[m3]-ast->x[m2],2)+pow(ast->y[m3]-ast->y[m2],2)) - r) > DISTMATCHTOL){ + if(fabs(sqrt(pow(ast->x[m3]-ast->x[m2],2)+pow(ast->y[m3]-ast->y[m2],2)) - dis23) > DISTMATCHTOL){ #if DEBUG>2 fprintf(stdout,"Match 3rd star %d discarded for distance to 2nd match star error.\n",m3); #endif continue; } // check angle - d=atan((cat->y[s3]-cat->y[s1]) / (cat->x[s3]-cat->x[s1])); - if((cat->x[s3]-cat->x[s1]) < 0){ - if(d >= 0) d -= M_PI; - else d += M_PI; - } d2=atan((ast->y[m3]-ast->y[m1]) / (ast->x[m3]-ast->x[m1])); if((ast->x[m3]-ast->x[m1]) < 0){ if(d2 >= 0) d2 -= M_PI; else d2 += M_PI; } - if(fabs(d - d2) > MAXROT){ + if(fabs(d2 - ang13) > MAXROT){ #if DEBUG>2 fprintf(stdout,"Match 3rd star %d discarded for rotation error.\n",m3); #endif @@ -667,10 +725,148 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, } // m3 is viable candidate for match to 3rd star r=ast->mag[m3]; -#if DEBUG>1 +#if DEBUG>0 fprintf(stdout,"Match found with 3rd match star: %d, magnitude: %.1f \n",m3,r); #endif triast[2]=m3; + + // ************************************************************************************************************ + // At this point a viable candidate triangle is found to match the selected reference triangle + // will try to validate this candidate by calculating the tranformation between the ref triangle and this candidate + // We will need to calculate scale, rotation and translation + + end_t=clock(); +#if DEBUG>0 + fprintf(stdout,"\n"); + fprintf(stdout,"Match triangle found: %d,%d,%d\n",m1,m2,m3); + fprintf(stdout,"Magnitudes: %f, %f, %f\n",ast->mag[m1],ast->mag[m2],ast->mag[m3]); + fprintf(stdout,"Reference triangle: %d, %d, %d\n",s1,s2,s3); + fprintf(stdout,"Magnitudes: %f, %f, %f\n",cat->mag[s1],cat->mag[s2],cat->mag[s3]); + + d=(float)(end_t - start_t)/CLOCKS_PER_SEC; + fprintf(stdout,"Seconds elapsed: %f\n",d); +#endif + start_t=clock(); + + if(m1==101 && m2==80 && m3==87){ + end_t=clock(); + fprintf(stdout,"Special match triangle found\n"); + } + + // Scale transformation calculation + // scaling from ref 1-2 to match 1-2 was previously calculated in matchscale, now we average with + // ref 2-3 to match 2-3 and ref 3-1 to match 3-1 + r=sqrt(pow(cat->x[s3]-cat->x[s2],2)+pow(cat->y[s3]-cat->y[s2],2)); + d=sqrt(pow(ast->x[m3]-ast->x[m2],2)+pow(ast->y[m3]-ast->y[m2],2)) / r; + matchscale += d; + r=sqrt(pow(cat->x[s1]-cat->x[s3],2)+pow(cat->y[s1]-cat->y[s3],2)); + d=sqrt(pow(ast->x[m1]-ast->x[m3],2)+pow(ast->y[m1]-ast->y[m3],2)) / r; + matchscale += d; + matchscale /= 3; + + // Rotation calculation + // matchrot was obtained from angle between ref stars 1-2 and match stars 1-2 + // now average with angle ref 2-3 to match 2-3 and angle ref 3-1 to match 3-1 + d2=atan((ast->y[m2]-ast->y[m1]) / (ast->x[m2]-ast->x[m1])); + if((ast->x[m2]-ast->x[m1]) < 0){ + if(d2 >= 0) d2 -= M_PI; + else d2 += M_PI; + } + matchrot = d2-ang12; + d=atan((cat->y[s3]-cat->y[s2]) / (cat->x[s3]-cat->x[s2])); + if((cat->x[s3]-cat->x[s2]) < 0){ + if(d >= 0) d -= M_PI; + else d += M_PI; + } + d2=atan((ast->y[m3]-ast->y[m2]) / (ast->x[m3]-ast->x[m2])); + if((ast->x[m3]-ast->x[m2]) < 0){ + if(d2 >= 0) d2 -= M_PI; + else d2 += M_PI; + } + matchrot += d2-d; + d=atan((cat->y[s1]-cat->y[s3]) / (cat->x[s1]-cat->x[s3])); + if((cat->x[s1]-cat->x[s3]) < 0){ + if(d >= 0) d -= M_PI; + else d += M_PI; + } + d2=atan((ast->y[m1]-ast->y[m3]) / (ast->x[m1]-ast->x[m3])); + if((ast->x[m1]-ast->x[m3]) < 0){ + if(d2 >= 0) d2 -= M_PI; + else d2 += M_PI; + } + matchrot += d2-d; + matchrot /= 3; + + // traslation calculation + // we apply averaged matchscale and matchrotation to reference stars and then + // average reference 1 to match 1 vector, ref2 to match2 vector and ref3 to match3 vector + r=sqrt(pow(cat->x[s1],2)+pow(cat->y[s1],2)); + d=atan(cat->y[s1] / cat->x[s1]); + r *= matchscale; + d += matchrot; + matchXtras = ast->x[m1] - r*cos(d); + matchYtras = ast->y[m1] - r*sin(d); + r=sqrt(pow(cat->x[s2],2)+pow(cat->y[s2],2)); + d=atan(cat->y[s2] / cat->x[s2]); + r *= matchscale; + d += matchrot; + matchXtras += ast->x[m2] - r*cos(d); + matchYtras += ast->y[m2] - r*sin(d); + r=sqrt(pow(cat->x[s3],2)+pow(cat->y[s3],2)); + d=atan(cat->y[s3] / cat->x[s3]); + r *= matchscale; + d += matchrot; + matchXtras += ast->x[m3] - r*cos(d); + matchYtras += ast->y[m3] - r*sin(d); + matchXtras /= 3; + matchYtras /= 3; + +#if DEBUG>0 + fprintf(stdout,"Transformation:\nScale: %f\nRotation: %f\nXTraslat: %f\nYTraslat: %f\n",matchscale,matchrot,matchXtras,matchYtras); +#endif + + // At this point we've determined the transformation function to convert our reference triangle in the image + // to a matching triangle in the astrometric catalog + // Now it's time to check if this tranformation effectively maps our imaged stars catalog into the astrometric catalog + // For this we apply the tranformation to every bright star in the imaged catalog and accumulate success count when + // a matching star is found in the astrometric catalog. This count is later used for validation. + n=0; + n2=0; +// d2=(mmin+mave)/2; +// d2=(mmax+mave)/2; + d2=mave; + for(i=0;i<=cat->n;i++){ + // skip faint stars from the match check + if(cat->mag[i] > d2) continue; + r=sqrt(pow(cat->x[i],2)+pow(cat->y[i],2)); + d=atan(cat->y[i] / cat->x[i]); + r *= matchscale; + d += matchrot; + x=r*cos(d) + matchXtras; + y=r*sin(d) + matchYtras; + n2++; // this star counts as a checked star + for(j=0;j<=ast->n;j++){ + // skip also faint stars from map + if(ast->mag[j] > (d2 + MAXMAGERR)) continue; + if((fabs(ast->x[j] - x) < DISTMATCHTOL) && (fabs(ast->y[j] - y) < DISTMATCHTOL)){ + n++; + break; + } + } + } + if(n < n2*MATCHVALRATIO){ +#if DEBUG>0 + fprintf(stdout,"Match discarded for insufficient match number: %d out of %d checked stars\n",n,n2); +#endif + if(m1==101 && m2==80 && m3==87){ + end_t=clock(); + fprintf(stdout,"Special match triangle was discarded, halting...\n"); + nmatch=3; + } + + continue; + } + fprintf(stdout,"Match count: %d out of %d checked stars\n",n,n2); nmatch=3; } // if no match found next try will search again for all possible 3rd match stars @@ -919,13 +1115,6 @@ int main(int argc,char *argv[]) if (c=='f' && nselect>=3) { fit_transformation(cat,ast,nselect); ast=reread_astrometric_catalog(starfile,mag+1); - tricat[0]=0; - triast[0]=0; - tricat[1]=0; - triast[1]=0; - tricat[2]=0; - triast[2]=-1; - nselect=0; redraw=1; } @@ -937,13 +1126,13 @@ int main(int argc,char *argv[]) for (i=0;i=3) && (triast[2] > 0)){ @@ -1008,6 +1198,18 @@ int main(int argc,char *argv[]) redraw=1; } + // Reset reference stars selection + if (c=='I' && nselect>=3) { + tricat[0]=0; + triast[0]=0; + tricat[1]=0; + triast[1]=0; + tricat[2]=0; + triast[2]=-1; + nselect=0; + redraw=1; + } + // Plot identified stars if (c=='p') { if (plotstars==1) @@ -1045,7 +1247,7 @@ int main(int argc,char *argv[]) } // Zoom - if (c=='z' || c=='+' || c=='=') { + if (c=='z') { width/=1.25; xmin=x-0.5*width; xmax=x+0.5*width; @@ -1056,7 +1258,7 @@ int main(int argc,char *argv[]) } // Unzoom - if (c=='x' || c=='-') { + if (c=='x') { width*=1.25; xmin=x-0.5*width; xmax=x+0.5*width; @@ -1066,6 +1268,26 @@ int main(int argc,char *argv[]) continue; } + // More astrometric map stars + if (c=='+' || c=='=') { + mag += 0.25; + fprintf(stdout,"Astrometric map magnitude limit: %2.2f\n",mag); + ast=read_astrometric_catalog(starfile,mag,sx,sy,-q); + fprintf(stdout,"Stars in map: %d, extracted imaged stars: %d\n",ast.n,cat.n); + redraw=1; + continue; + } + + // Less astrometric map stars + if (c=='-') { + mag -= 0.25; + fprintf(stdout,"Astrometric map magnitude limit: %2.2f\n",mag); + ast=read_astrometric_catalog(starfile,mag,sx,sy,-q); + fprintf(stdout,"Stars in map: %d, extracted imaged stars: %d\n",ast.n,cat.n); + redraw=1; + continue; + } + // Help if (c=='h') { printf("Calibrates astrometry. Initially requires manual matching of at least three stars. Use 'a' to select star on the image, then 'b' to select star from the catalog, then 'f' to fit"); @@ -1073,14 +1295,15 @@ int main(int argc,char *argv[]) printf("a Select star on image\n"); printf("b Select star from catalog\n"); printf("i Autoselect calibration stars from catalog\n"); + printf("I Reset calibration stars selection\n"); printf("c Center image on pixel\n"); printf("f Fit calibration\n"); printf("m Match stars using current calibration\n"); - printf("z/+ Zoom in on cursor\n"); - printf("x/- Zoom out on cursor\n"); + printf("z/x Zoom in/out on cursor\n"); + printf("+/- Increase/decrease astrometric map stars\n"); printf("p Plot sextractor catalog\n"); printf("r Reset zoom\n"); - printf("R Reset fit and star selections\n"); + printf("R Reset fit\n"); } redraw=1; continue; From eb30e485154051d6f5337275a9f750d4dcd5360f Mon Sep 17 00:00:00 2001 From: fmederos Date: Wed, 16 Aug 2017 02:14:02 -0300 Subject: [PATCH 11/53] Testing auto-selection of calibration stars. --- plotfits.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plotfits.c b/plotfits.c index 850e353..008b91d 100644 --- a/plotfits.c +++ b/plotfits.c @@ -1115,6 +1115,13 @@ int main(int argc,char *argv[]) if (c=='f' && nselect>=3) { fit_transformation(cat,ast,nselect); ast=reread_astrometric_catalog(starfile,mag+1); + for (i=0;i Date: Sun, 20 Aug 2017 04:14:38 -0300 Subject: [PATCH 12/53] Add new Readme --- README2.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 README2.md diff --git a/README2.md b/README2.md new file mode 100644 index 0000000..a8239d4 --- /dev/null +++ b/README2.md @@ -0,0 +1,39 @@ +Satellite Tracking Toolkit +========= + +Sattools is a collection of tools to facilitate Photographic and Video satellite tracking. + +Build +------ +* Clone locally the code repository +* Install common dependencies + * gfortran + * gcc + * libpng-dev + * libx11-dev + * libjpeg-dev + * libexif-dev +* Build & install required libraries + * qfits-5.2.0: ftp://ftp.eso.org/pub/qfits/qfits-5.2.0.tar.gz + * pgplot-5.2.2: http://www.astro.caltech.edu/~tjp/pgplot/ + * gsl-1.15: ftp://ftp.gnu.org/gnu/gsl/gsl-1.15.tar.gz + * wcslib-2.9: http://www.epta.eu.org/~bassa/wcslib-2.9.tar +* Run `make` on the sattools folder + +Run notes +--------- +* You will need to set the following environment variables to run sattools. + These vars are set with default values after running install_sattolls.sh. + `ST_COSPAR` COSPAR number + `ST_DATADIR` path to sattools directory + `ST_TLEDIR` path to TLE directory + `ST_OBSDIR` path to observations directory +* If you have different video capture devices you may add a /etc/udev/rules.d/99-server.rules file to + add symlinks and use them to address a particular camera. Otherwise video devices can get mixed. + You may use a command such as 'udevadm info -a -n /dev/video1' to get your capture device attributes. + A sample rules file is available as guide. +* You should install NTP support on the system and configure time/date to automatically +sinchronize to time servers. +* If you re-run install_sattools.sh you should previously rmdir sattools directory or otherwise souces +will not be fetched even if they are not present at that dir +* Modify stget.sh for your space-track.org login and password (--post-data='identity=login&password=password') From c199b55d50372f1d218aaa3493a996c68f544a87 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 20 Aug 2017 22:20:14 -0300 Subject: [PATCH 13/53] Add rules file for aliasing multiple video devices --- data/99-server.rules | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 data/99-server.rules diff --git a/data/99-server.rules b/data/99-server.rules new file mode 100644 index 0000000..7569b1c --- /dev/null +++ b/data/99-server.rules @@ -0,0 +1,2 @@ +KERNEL=="video[0-9]*", ATTR{name}=="Laptop_Integrated_Webcam_1.3M", SYMLINK+="video-Webcam" +KERNEL=="video[0-9]*", ATTR{name}=="AV TO USB2.0", SYMLINK+="video-S25H" From 8e5a6f8e5c021e24610945dc8fdb00c853aeb8a0 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 20 Aug 2017 23:51:58 -0300 Subject: [PATCH 14/53] Update process.sh into st_compress.sh --- README2.md | 3 ++- scripts/st_compress.sh | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README2.md b/README2.md index a8239d4..33b68a3 100644 --- a/README2.md +++ b/README2.md @@ -31,7 +31,8 @@ Run notes * If you have different video capture devices you may add a /etc/udev/rules.d/99-server.rules file to add symlinks and use them to address a particular camera. Otherwise video devices can get mixed. You may use a command such as 'udevadm info -a -n /dev/video1' to get your capture device attributes. - A sample rules file is available as guide. + A sample rules file is available as guide in data/. Note symlinks do not work, the file must be} + modified and copied to /etc/udev/rules.d/. * You should install NTP support on the system and configure time/date to automatically sinchronize to time servers. * If you re-run install_sattools.sh you should previously rmdir sattools directory or otherwise souces diff --git a/scripts/st_compress.sh b/scripts/st_compress.sh index eb0fb5b..a31e05f 100755 --- a/scripts/st_compress.sh +++ b/scripts/st_compress.sh @@ -25,6 +25,7 @@ while true; do echo "Moving to $ST_OBSDIR/$DIR" echo "observing" >$ST_OBSDIR/control/state.txt cp $ST_OBSDIR/control/position.txt . + cp $ST_OBSDIR/control/scale.txt . cp $ST_OBSDIR/control/camera.txt . fi From dd5a96a048d32263bb942448eb15cb3384d5eea5 Mon Sep 17 00:00:00 2001 From: fmederos Date: Thu, 24 Aug 2017 21:46:33 -0300 Subject: [PATCH 15/53] Add End observation scheduling and selective device capture process invocation --- runsched.c | 51 ++++++++++++++++++++++---- scripts/st_compress.sh | 82 ++++++++++++++++++++++++++---------------- skymap.c | 13 ++++--- 3 files changed, 104 insertions(+), 42 deletions(-) diff --git a/runsched.c b/runsched.c index 4a956c4..0087e14 100644 --- a/runsched.c +++ b/runsched.c @@ -24,13 +24,14 @@ // Observation struct contains observation time, celestial coords and camera name struct observation { - char stime[20],sra[15],sde[15],camname[15]; + char stime[20],sra[15],sde[15],camname[15],startstop[10]; time_t ptime; float dt; }; int fgetline(FILE *file,char *s,int lim); void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname); +void stop_obs(char *datadir,char *obsdir,char *camname); time_t decode_time(char *stm); int main(int argc, char *argv[]) @@ -66,7 +67,7 @@ int main(int argc, char *argv[]) i=0; file=fopen("schedule.txt","r"); while (fgetline(file,line,LIM)>0) { - sscanf(line,"%s %s %s %s",obs[i].stime,obs[i].sra,obs[i].sde,obs[i].camname); + sscanf(line,"%s %s %s %s %s",obs[i].stime,obs[i].sra,obs[i].sde,obs[i].camname,obs[i].startstop); obs[i].ptime=decode_time(obs[i].stime); i++; @@ -96,11 +97,15 @@ int main(int argc, char *argv[]) // Loop over observations for (i=0;i0.0) { - printf("%4.0f %s %s %s\n",obs[i].dt,obs[i].stime,obs[i].sra,obs[i].sde); - break; + printf("%4.0f %s %s %s %s\n",obs[i].dt,obs[i].stime,obs[i].sra,obs[i].sde,obs[i].startstop); + break; } else if (obs[i].dt==0) { - printf("Slewing to %s %s\n",obs[i].sra,obs[i].sde); - send_position(obs[i].sra,obs[i].sde,datadir,obsdir,obs[i].camname); + if(strstr(obs[i].startstop,"tart")!=NULL){ + //printf("Slewing to %s %s\n",obs[i].sra,obs[i].sde); + send_position(obs[i].sra,obs[i].sde,datadir,obsdir,obs[i].camname); + } else if(strstr(obs[i].startstop,"top")!=NULL){ + stop_obs(datadir,obsdir,obs[i].camname); + } } } @@ -167,7 +172,7 @@ void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname) // read complete line from data/cameras.txt describing the scheduled camera read_cameras(camname,datadir,camera); // search for camera name sscanf(camera,"%s %f %f %f %f %s", s, &f, &f, &f, &f, s); - // Look for "fix" string... + // Look for "fix" string to jump over slewing routines. if(strstr(s,"ix")==NULL){ // Old packet style @@ -176,6 +181,8 @@ void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname) // New packet style (as of 2013-08-20) sprintf(packet,"%s%s",sra,sde); + printf("Slewing to %s %s\n",sra,sde); + // Send TCP packet skt=socket(AF_INET,SOCK_STREAM,0); addr.sin_family=AF_INET; @@ -202,6 +209,8 @@ void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname) write(skt,packet,strlen(packet)); close(skt); } + + printf("Starting new observation\n"); // Set restart sprintf(fname,"%s/control/state.txt",obsdir); @@ -230,6 +239,34 @@ void send_position(char *sra,char *sde,char *datadir,char *obsdir,char *camname) return; } + +// Send stop observation signal +void stop_obs(char *datadir,char *obsdir,char *camname) +{ + FILE *file; + char camera[128],fname[128]; + float f; + char s[31]; + + // Retrieve Camera data + // read complete line from data/cameras.txt describing the scheduled camera + read_cameras(camname,datadir,camera); // search for camera name + sscanf(camera,"%s %f %f %f %f %s", s, &f, &f, &f, &f, s); + + printf("Stop observation\n"); + + // Set stop + sprintf(fname,"%s/control/state.txt",obsdir); + file=fopen(fname,"w"); + if (file!=NULL) { + fprintf(file,"stop"); + fclose(file); + } + + return; +} + + // Decode time time_t decode_time(char *stm) { diff --git a/scripts/st_compress.sh b/scripts/st_compress.sh index a31e05f..e394216 100755 --- a/scripts/st_compress.sh +++ b/scripts/st_compress.sh @@ -3,47 +3,67 @@ # Settings PGMDIR=/dev/shm N=250 +WAIT=10 +COUNT=0 # Force a restart echo "restart" >$ST_OBSDIR/control/state.txt +STATE="restart" # For ever loop while true; do - # Get number of files - NFILES=`ls -1 $PGMDIR/img*.pgm 2>/dev/null | wc -l` + # Get number of files + NFILES=`ls -1 $PGMDIR/img*.pgm 2>/dev/null | wc -l` - # If enough, process - if [ $NFILES -ge $N ]; then - # Get state - export STATE=`cat $ST_OBSDIR/control/state.txt` - - # Create new directory - if [ $STATE == "restart" ]; then - export DIR=`date -u +%FT%T | sed -e "s/-//g" -e "s/\://g" -e "s|T|/|g"` - mkdir -p $ST_OBSDIR/$DIR - cd $ST_OBSDIR/$DIR - echo "Moving to $ST_OBSDIR/$DIR" - echo "observing" >$ST_OBSDIR/control/state.txt - cp $ST_OBSDIR/control/position.txt . - cp $ST_OBSDIR/control/scale.txt . - cp $ST_OBSDIR/control/camera.txt . - fi + # If enough, process + if [ $NFILES -ge $N ]; then + # Get state + export STATE=`cat $ST_OBSDIR/control/state.txt` + + # Create new directory + if [ $STATE == "restart" ]; then + export DIR=`date -u +%FT%T | sed -e "s/-//g" -e "s/\://g" -e "s|T|/|g"` + mkdir -p $ST_OBSDIR/$DIR + cd $ST_OBSDIR/$DIR + echo "Moving to $ST_OBSDIR/$DIR" + echo "observing" >$ST_OBSDIR/control/state.txt + cp $ST_OBSDIR/control/position.txt . + cp $ST_OBSDIR/control/scale.txt . + cp $ST_OBSDIR/control/camera.txt . + export CAMERA=`cat $ST_OBSDIR/control/camera.txt` + fi - # Start point - M=`ls -1 $PGMDIR/img*.pgm | head -n1 | sed -e "s/[^0-9]*//g"` + # Process only if not stopped + if [ $STATE != "stop" ]; then + # Start point + M=`ls -1 $PGMDIR/img*.pgm | head -n1 | sed -e "s/[^0-9]*//g"` - # Run pgm2fits - pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N + # Run pgm2fits + pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N - # Remove files - ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("sudo rm -rf %s\n",$1)}' | sh + # Run viewer + viewer `ls -1 2*.fits | tail -n1` + cp avg.pgm $ST_OBSDIR + fi - # Run viewer - viewer `ls -1 2*.fits | tail -n1` - cp avg.pgm $ST_OBSDIR - echo "Finished" + # Remove files + ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("sudo rm -rf %s\n",$1)}' | sh + + echo "Finished" + # if not enough images are still available wait to re-launch capture process + else + echo "Waiting for images" + if [ $STATE == "observing" ]; then + COUNT=$(($COUNT+1)) + if [ $COUNT -ge $WAIT ]; then + COUNT=0 + echo "No images found, restarting capture script" + sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA& + # else + # echo $COUNT + fi fi - - # Sleep - sleep 1 + fi + # Sleep + sleep 1 done diff --git a/skymap.c b/skymap.c index 147db84..30154cd 100644 --- a/skymap.c +++ b/skymap.c @@ -862,7 +862,7 @@ void init_plot(char *psfile,float width,float aspect) } // Add to schedule -void schedule(char *nfd,double ra,double de) +void schedule(char *nfd,double ra,double de,char *startstop) { FILE *file; char sra[16],sde[16]; @@ -879,7 +879,7 @@ void schedule(char *nfd,double ra,double de) printf("Failed to create schedule.txt\n"); return; } - fprintf(file,"%s %s %s %s\n",nfd,sra,sde, m.camera); + fprintf(file,"%s %s %s %s %s\n",nfd,sra,sde, m.camera,startstop); fclose(file); return; @@ -2476,7 +2476,8 @@ int plot_skymap(void) printf("v Toggle visibility contours\n"); printf("F Toggle camera configuration (data/cameras.txt)\n"); printf("TAB Cycle IOD observations\n"); - printf("S Save position/time to schedule\n"); + printf("S Save observation position/time to schedule\n"); + printf("E Save observation end-time to schedule\n"); printf("a Select on age\n"); printf("Q Toggle plotting stars\n"); } @@ -2670,7 +2671,11 @@ int plot_skymap(void) // Add to schedule if (c=='S') - schedule(m.nfd,m.ra0,m.de0); + schedule(m.nfd,m.ra0,m.de0,"start"); + + // Add to schedule + if (c=='E') + schedule(m.nfd,m.ra0,m.de0,"stop"); // Polar if (c=='z') { From 0137911cc82445047543c70bb92535bb99b0c991 Mon Sep 17 00:00:00 2001 From: fmederos Date: Fri, 25 Aug 2017 00:14:30 -0300 Subject: [PATCH 16/53] Add auto-launch of capture process --- scripts/st_compress.sh | 74 +++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/scripts/st_compress.sh b/scripts/st_compress.sh index e394216..7829b17 100755 --- a/scripts/st_compress.sh +++ b/scripts/st_compress.sh @@ -3,22 +3,35 @@ # Settings PGMDIR=/dev/shm N=250 -WAIT=10 +# If no images are found during thisperiod, relaunch capture process +WAIT=20 COUNT=0 +# Start automatically capture process or not +AUTOSTART=0 -# Force a restart -echo "restart" >$ST_OBSDIR/control/state.txt -STATE="restart" +# Default camera to start imaging if no schedule is available +CAMERA="S25H" + +# if autostart force a restart +if [ $AUTOSTART == 1 ]; then + echo "restart" >$ST_OBSDIR/control/state.txt + STATE="restart" +else + echo "stop" >$ST_OBSDIR/control/state.txt + STATE="stop" +fi + +export CAMERA=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((1))}'` # For ever loop while true; do # Get number of files NFILES=`ls -1 $PGMDIR/img*.pgm 2>/dev/null | wc -l` - + + # Get state + export STATE=`cat $ST_OBSDIR/control/state.txt` # If enough, process if [ $NFILES -ge $N ]; then - # Get state - export STATE=`cat $ST_OBSDIR/control/state.txt` # Create new directory if [ $STATE == "restart" ]; then @@ -28,39 +41,70 @@ while true; do echo "Moving to $ST_OBSDIR/$DIR" echo "observing" >$ST_OBSDIR/control/state.txt cp $ST_OBSDIR/control/position.txt . - cp $ST_OBSDIR/control/scale.txt . +# cp $ST_OBSDIR/control/scale.txt . cp $ST_OBSDIR/control/camera.txt . - export CAMERA=`cat $ST_OBSDIR/control/camera.txt` + export CAMERA=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((1))}'` fi # Process only if not stopped if [ $STATE != "stop" ]; then + echo "Compressing captured frames" + # Start point M=`ls -1 $PGMDIR/img*.pgm | head -n1 | sed -e "s/[^0-9]*//g"` # Run pgm2fits - pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N +# pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N + pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N >/dev/null # Run viewer viewer `ls -1 2*.fits | tail -n1` cp avg.pgm $ST_OBSDIR + else + kill -9 $CAPTUREPID fi # Remove files - ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("sudo rm -rf %s\n",$1)}' | sh + echo "Removing captured frames" +# ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("sudo rm -rf %s\n",$1)}' | sh + ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("rm -rf %s\n",$1)}' | sh echo "Finished" - # if not enough images are still available wait to re-launch capture process else - echo "Waiting for images" - if [ $STATE == "observing" ]; then + # There are not enough images available + # Launch capture process or Wait to re-launch capture process + if [ $STATE != "stop" ]; then + echo "Waiting for images. Status: "$STATE COUNT=$(($COUNT+1)) if [ $COUNT -ge $WAIT ]; then COUNT=0 echo "No images found, restarting capture script" - sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA& + sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA > /dev/null& +# echo $! >$ST_OBSDIR/control/capture_pid.txt +# CAPTUREPID=`echo $!` + sleep 1 + CAPTUREPID=`pgrep -o -x ffmpeg` # else # echo $COUNT + + fi + if [ $STATE == "restart" ]; then + if [ $(($CAPTUREPID)) == 0 ]; then + sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA > /dev/null& + # echo $! >$ST_OBSDIR/control/capture_pid.txt + # CAPTUREPID=`echo $!` + sleep 1 + CAPTUREPID=`pgrep -o -x ffmpeg` + fi + fi + else + echo "Status: "$STATE +# CAPTUREPID=`pgrep -o -x ffmpeg` +# echo "Capture PID: "$CAPTUREPID + if [ $(($CAPTUREPID)) != 0 ]; then + # kill -9 `cat $ST_OBSDIR/control/capture_pid.txt` + kill -9 $CAPTUREPID + CAPTUREPID=0 fi fi fi From 9810e8e826491e79572f73ebdcc782fcf816a6ab Mon Sep 17 00:00:00 2001 From: fmederos Date: Fri, 25 Aug 2017 01:22:02 -0300 Subject: [PATCH 17/53] Added automatic capture preocess launch with selective video device --- scripts/st_capture.sh | 3 ++- scripts/st_compress.sh | 18 +++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/scripts/st_capture.sh b/scripts/st_capture.sh index 3e99436..fa57498 100755 --- a/scripts/st_capture.sh +++ b/scripts/st_capture.sh @@ -15,4 +15,5 @@ cd /dev/shm rm img*.pgm # Start capture -ffmpeg -f video4linux2 -i $device -s 720x576 -r 25 img%06d.pgm +#ffmpeg -f video4linux2 -i $device -s 720x576 -r 25 img%06d.pgm +ffmpeg -f video4linux2 -i $device -s 720x576 -r 25 img%06d.pgm >/dev/null diff --git a/scripts/st_compress.sh b/scripts/st_compress.sh index 7829b17..a1ef310 100755 --- a/scripts/st_compress.sh +++ b/scripts/st_compress.sh @@ -62,6 +62,7 @@ while true; do cp avg.pgm $ST_OBSDIR else kill -9 $CAPTUREPID + CAPTUREPID=0 fi # Remove files @@ -72,37 +73,28 @@ while true; do echo "Finished" else # There are not enough images available - # Launch capture process or Wait to re-launch capture process + # Launch capture process + # if time passes with still no images re-launch capture process if [ $STATE != "stop" ]; then echo "Waiting for images. Status: "$STATE COUNT=$(($COUNT+1)) if [ $COUNT -ge $WAIT ]; then COUNT=0 echo "No images found, restarting capture script" - sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA > /dev/null& -# echo $! >$ST_OBSDIR/control/capture_pid.txt -# CAPTUREPID=`echo $!` + sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA & sleep 1 CAPTUREPID=`pgrep -o -x ffmpeg` - # else - # echo $COUNT - fi if [ $STATE == "restart" ]; then if [ $(($CAPTUREPID)) == 0 ]; then - sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA > /dev/null& - # echo $! >$ST_OBSDIR/control/capture_pid.txt - # CAPTUREPID=`echo $!` + sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA & sleep 1 CAPTUREPID=`pgrep -o -x ffmpeg` fi fi else echo "Status: "$STATE -# CAPTUREPID=`pgrep -o -x ffmpeg` -# echo "Capture PID: "$CAPTUREPID if [ $(($CAPTUREPID)) != 0 ]; then - # kill -9 `cat $ST_OBSDIR/control/capture_pid.txt` kill -9 $CAPTUREPID CAPTUREPID=0 fi From 941b426891bad1a6f9d5e0de082cb15c9997113a Mon Sep 17 00:00:00 2001 From: fmederos Date: Fri, 25 Aug 2017 01:36:12 -0300 Subject: [PATCH 18/53] Update README file, add helper install scripts to scripts dir --- README2.md | 27 +++-- scripts/install_dependencies.sh | 180 ++++++++++++++++++++++++++++++++ scripts/install_sattools.sh | 54 ++++++++++ scripts/stget.sh | 34 ++++++ 4 files changed, 285 insertions(+), 10 deletions(-) create mode 100755 scripts/install_dependencies.sh create mode 100755 scripts/install_sattools.sh create mode 100755 scripts/stget.sh diff --git a/README2.md b/README2.md index 33b68a3..310801e 100644 --- a/README2.md +++ b/README2.md @@ -3,8 +3,8 @@ Satellite Tracking Toolkit Sattools is a collection of tools to facilitate Photographic and Video satellite tracking. -Build ------- +Install notes +------------- * Clone locally the code repository * Install common dependencies * gfortran @@ -20,6 +20,12 @@ Build * wcslib-2.9: http://www.epta.eu.org/~bassa/wcslib-2.9.tar * Run `make` on the sattools folder +* Helper scripts install_dependencies.sh and install_sattools.sh are available at scripts directory. + You can try run these scripts to install or use them as install guide. + +* If you re-run install_sattools.sh you should previously rmdir sattools directory or otherwise souces + will not be fetched even if they are not present at that dir + Run notes --------- * You will need to set the following environment variables to run sattools. @@ -28,13 +34,14 @@ Run notes `ST_DATADIR` path to sattools directory `ST_TLEDIR` path to TLE directory `ST_OBSDIR` path to observations directory -* If you have different video capture devices you may add a /etc/udev/rules.d/99-server.rules file to - add symlinks and use them to address a particular camera. Otherwise video devices can get mixed. - You may use a command such as 'udevadm info -a -n /dev/video1' to get your capture device attributes. - A sample rules file is available as guide in data/. Note symlinks do not work, the file must be} - modified and copied to /etc/udev/rules.d/. +* You will need to add a /etc/udev/rules.d/99-server.rules file to add symlinks and use them to + address a particular camera. + You may use a command such as 'udevadm info -a -n /dev/video0' to get your capture device attributes and + use that to create the rules file. + A sample rules file is available as guide in data/ + Note that symlinks to the rules file do not work, the rules file must be modified to suit your needs + and copied to /etc/udev/rules.d/ * You should install NTP support on the system and configure time/date to automatically -sinchronize to time servers. -* If you re-run install_sattools.sh you should previously rmdir sattools directory or otherwise souces -will not be fetched even if they are not present at that dir + sinchronize to time servers. * Modify stget.sh for your space-track.org login and password (--post-data='identity=login&password=password') + diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh new file mode 100755 index 0000000..184bfe4 --- /dev/null +++ b/scripts/install_dependencies.sh @@ -0,0 +1,180 @@ +#!/bin/bash + +echo "Step 1.1: install dependencies" +sleep 1 +apg-get update +apt-get install emacs gfortran libpng-dev libx11-dev libjpeg-dev libexif-dev git dos2unix sextractor + +echo "Step 1.2: goto /usr/local/src" +sleep 1 +cd /usr/local/src + +echo "Step 2.1: download pgplot" +sleep 1 +wget -c ftp://ftp.astro.caltech.edu/pub/pgplot/pgplot5.2.tar.gz + +echo "Step 2.2: unpack pgplot" +sleep 1 +gunzip -c pgplot5.2.tar.gz | tar xvf - + +echo "Step 2.3: create pgplot directory" +sleep 1 +mkdir -p /usr/local/src/pgplot-5.2.2 + +echo "Step 2.4: select drivers" +sleep 1 +# Selecting PNDRIV, PSDRIV and XWDRIV +sed -e "s/! PNDRIV/ PNDRIV/g" -e "s/! PSDRIV/ PSDRIV/g" -e "s/! XWDRIV/ XWDRIV/g" pgplot/drivers.list >pgplot-5.2.2/drivers.list + +echo "Step 2.5: create makefile" +sleep 1 +cd /usr/local/src/pgplot-5.2.2 +../pgplot/makemake ../pgplot linux g77_gcc + +echo "Step 2.6: adjusting makefile" +sleep 1 +sed -i -e "s/FCOMPL=g77/FCOMPL=gfortran/g" makefile +sed -i -e "s/FFLAGC=-u -Wall -fPIC -O/FFLAGC=-ffixed-form -ffixed-line-length-none -u -Wall -fPIC -O/g" makefile +sed -i -e "s|pndriv.o : ./png.h ./pngconf.h ./zlib.h ./zconf.h|pndriv.o : |g" makefile + +echo "Step 2.7: run make" +sleep 1 +make +make cpg + +echo "Step 2.8: place libraries and header files" +sleep 1 +rm -rf /usr/local/lib/libpgplot.a /usr/local/lib/libcpgplot.a /usr/local/lib/libpgplot.so /usr/local/include/cpgplot.h +ln -s /usr/local/src/pgplot-5.2.2/libpgplot.a /usr/local/lib/ +ln -s /usr/local/src/pgplot-5.2.2/libpgplot.so /usr/local/lib/ +ln -s /usr/local/src/pgplot-5.2.2/libcpgplot.a /usr/local/lib/ +ln -s /usr/local/src/pgplot-5.2.2/cpgplot.h /usr/local/include/ + +echo "Step 2.9: clean up" +sleep 1 +rm -rf /usr/local/src/pgplot5.2.tar.gz /usr/local/src/pgplot + +echo "Step 3.1: download qfits" +sleep 1 +cd /usr/local/src +wget -c ftp://ftp.eso.org/pub/qfits/qfits-5.2.0.tar.gz + +echo "Step 3.2: unpack qfits" +sleep 1 +gunzip -c qfits-5.2.0.tar.gz | tar xvf - + +echo "Step 3.3: fix xmemory.c" +sleep 1 +cd /usr/local/src/qfits-5.2.0 +chmod +w src/xmemory.c +sed -i -e "s/swapfd = open(fname, O_RDWR | O_CREAT);/swapfd = open(fname, O_RDWR | O_CREAT, 0644);/g" src/xmemory.c + +echo "Step 3.4: configure and make" +sleep 1 +./configure +make +make install + +echo "Step 3.5: clean up" +sleep 1 +rm /usr/local/src/qfits-5.2.0.tar.gz + +echo "Step 4.1: download wcslib-2.9" +sleep 1 +cd /usr/local/src +wget -c http://www.epta.eu.org/~bassa/wcslib-2.9.tar + +echo "Step 4.2: unpack wcslib" +sleep 1 +tar -xvf wcslib-2.9.tar + +echo "Step 4.3: compile wcslib" +sleep 1 +cd /usr/local/src/wcslib-2.9/C/ +make clean +rm libwcs_c.a +make + +echo "Step 4.4: place libraries and header files" +sleep 1 +rm -rf /usr/local/lib/libwcs_c.a /usr/local/include/proj.h /usr/local/include/cel.h +ln -s /usr/local/src/wcslib-2.9/C/libwcs_c.a /usr/local/lib/ +ln -s /usr/local/src/wcslib-2.9/C/proj.h /usr/local/include/ +ln -s /usr/local/src/wcslib-2.9/C/cel.h /usr/local/include/ + +echo "Step 4.5: clean up" +sleep 1 +rm -rf /usr/local/src/wcslib-2.9.tar + +echo "Step 5.1: download gsl" +sleep 1 +cd /usr/local/src +wget -c ftp://ftp.gnu.org/gnu/gsl/gsl-1.16.tar.gz + +echo "Step 5.2: unpack gsl" +sleep 1 +gunzip -c gsl-1.16.tar.gz | tar xvf - + +echo "Step 5.3: configure, make, make install" +sleep 1 +cd /usr/local/src/gsl-1.16/ +./configure +make +make install + +echo "Step 5.4: clean up" +sleep 1 +rm -rf /usr/local/src/gsl-1.16.tar.gz + +echo "Step 6.1: set ld.so.conf" +sleep 1 +echo "include /etc/ld.so.conf.d/*.conf" >/etc/ld.so.conf +echo "/usr/local/lib" >>/etc/ld.so.conf +ldconfig + +echo "Step 6.1: download fftw" +sleep 1 +cd /usr/local/src +wget http://www.fftw.org/fftw-3.3.4.tar.gz + +echo "Step 6.2: unpack fftw" +sleep 1 +gunzip -c fftw-3.3.4.tar.gz | tar xvf - + +echo "Step 6.3: configure, make,make install" +sleep 1 +cd /usr/local/src/fftw-3.3.4 +./configure --enable-float +make +make install + +echo "Step 6.4: clean up" +sleep 1 +rm -rf /usr/local/src/fftw-3.3.4.tar.gz + +echo "Step 7.1: download ffmpeg" +sleep 1 +cd /usr/local/src +wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 + +echo "Step 7.2: unpack ffmpeg" +sleep 1 +bzip2 -cd ffmpeg-snapshot.tar.bz2 | tar xvf - + +echo "Step 7.3: patch pgmenc.c" +sleep 1 +cd /usr/local/src/ffmpeg/libavcodec +wget https://dl.dropboxusercontent.com/u/52579487/pnmenc.c -O pnmenc.c + +echo "Step 7.4: configure, make,make install" +sleep 1 +cd /usr/local/src/ffmpeg +./configure --disable-yasm +make +make install + +echo "Step 7.5: clean up" +cd /usr/local/src +rm -rf ffmpeg-snapshot.tar.bz2 + +echo "Done installing dependencies" diff --git a/scripts/install_sattools.sh b/scripts/install_sattools.sh new file mode 100755 index 0000000..e25e8cc --- /dev/null +++ b/scripts/install_sattools.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +echo "Step 1.1: make directory" +sleep 1 +mkdir -p $HOME/code/c/satellite/ +cd $HOME/code/c/satellite + +echo "Step 1.2: clone sattools repository (may take a while)" +sleep 1 +#git clone https://github.com/cbassa/sattools.git +git clone https://github.com/fmederos/sattools.git + +echo "Step 1.3: make" +sleep 1 +cd $HOME/code/c/satellite/sattools +make + +echo "Step 1.4: clone strf repository" +sleep 1 +cd $HOME/code/c/satellite +git clone https://github.com/cbassa/strf.git + +echo "Step 1.5: make" +sleep 1 +cd $HOME/code/c/satellite/strf +make + +echo "Step 1.6: download classfd.tle" +sleep 1 +mkdir -p $HOME/code/c/satellite/sattools/tle +cd $HOME/code/c/satellite/sattools/tle +wget -c https://www.prismnet.com/~mmccants/tles/classfd.zip +unzip classfd.zip +dos2unix classfd.tle +rm classfd.zip + +echo "Step 2.1: set environment variables" +sleep 1 +cd +echo "export PGPLOT_DIR=/usr/local/src/pgplot-5.2.2" >>$HOME/.bashrc +#echo "export ST_COSPAR=4171" >>$HOME/.bashrc +echo "export ST_COSPAR=0531" >>$HOME/.bashrc +echo "export ST_DATADIR=$HOME/code/c/satellite/sattools" >>$HOME/.bashrc +echo "export ST_TLEDIR=$HOME/code/c/satellite/sattools/tle" >>$HOME/.bashrc +echo "export ST_OBSDIR=$HOME/satobs" >>$HOME/.bashrc +mkdir $ST_OBSDIR +mkdir $ST_OBSDIR/control + +echo "Step 2.2: set path" +sleep 1 +echo "PATH=$HOME/code/c/satellite/sattools:$HOME/code/c/satellite/sattools/scripts:$HOME/software/strf:\$PATH" >>$HOME/.profile + +echo "Final step: run" +echo "source $HOME/.profile" diff --git a/scripts/stget.sh b/scripts/stget.sh new file mode 100755 index 0000000..2ee9716 --- /dev/null +++ b/scripts/stget.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Get date +DATE=`date +%Y%m%d_%H%M%S` + +# Get cookie +wget --post-data='identity=yourlogin&password=yourpassword' --cookies=on --keep-session-cookies --save-cookies=/tmp/cookies.txt 'https://www.space-track.org/ajaxauth/login' -o /tmp/stget.log + +# Get data +wget --keep-session-cookies --load-cookies=/tmp/cookies.txt 'https://www.space-track.org/basicspacedata/query/class/tle_latest/ORDINAL/1/EPOCH/%3Enow-30/format/3le' -O $ST_TLEDIR/catalog.tle +dos2unix $ST_TLEDIR/catalog.tle +sed -i -e "s/^1 /1 0000/g" -e "s/^2 /2 0000/g" -e "s/^1 /1 000/g" -e "s/^2 /2 000/g" -e "s/^1 /1 00/g" -e "s/^2 /2 00/g" -e "s/^1 /1 0/g" -e "s/^2 /2 0/g" $ST_TLEDIR/catalog.tle +cp $ST_TLEDIR/catalog.tle $ST_TLEDIR/${DATE}_catalog.txt + +# Get classfd +wget http://www.prismnet.com/~mmccants/tles/classfd.zip --no-check-certificate -O $ST_TLEDIR/classfd.zip +unzip -o $ST_TLEDIR/classfd.zip +dos2unix $ST_TLEDIR/classfd.tle +cp $ST_TLEDIR/classfd.tle $ST_TLEDIR/${DATE}_classfd.txt +#mv $HOME/classfd.tle $ST_TLEDIR/classfd.tle +rm $ST_TLEDIR/classfd.zip + +# Get inttles +wget http://www.prismnet.com/~mmccants/tles/inttles.zip --no-check-certificate -O $ST_TLEDIR/inttles.zip +unzip -o $ST_TLEDIR/inttles.zip +dos2unix $ST_TLEDIR/inttles.tle +cp $ST_TLEDIR/inttles.tle $ST_TLEDIR/${DATE}_inttles.txt +#mv $HOME/inttles.tle $ST_TLEDIR/inttles.tle +rm $ST_TLEDIR/inttles.zip + +#rm $HOME/login + +# Create bulk file +cat $ST_TLEDIR/classfd.tle $ST_TLEDIR/catalog.tle >$ST_TLEDIR/bulk.tle From 580638ffdc790d79542c7c8ee48bb34288579aa5 Mon Sep 17 00:00:00 2001 From: fmederos Date: Fri, 25 Aug 2017 11:33:10 -0300 Subject: [PATCH 19/53] Automatic launch of capture process on the different capture devices --- README2.md | 4 ++-- scripts/st_compress.sh | 21 +++++++++++++-------- skymap.c | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/README2.md b/README2.md index 310801e..5307995 100644 --- a/README2.md +++ b/README2.md @@ -34,8 +34,8 @@ Run notes `ST_DATADIR` path to sattools directory `ST_TLEDIR` path to TLE directory `ST_OBSDIR` path to observations directory -* You will need to add a /etc/udev/rules.d/99-server.rules file to add symlinks and use them to - address a particular camera. +* If you have multiple capture devices you will need to add a /etc/udev/rules.d/99-server.rules file to add symlinks and use them to + address a particular camera. Sattools will automatically select the camera that is scheduled for each observation. You may use a command such as 'udevadm info -a -n /dev/video0' to get your capture device attributes and use that to create the rules file. A sample rules file is available as guide in data/ diff --git a/scripts/st_compress.sh b/scripts/st_compress.sh index a1ef310..9ca1dc9 100755 --- a/scripts/st_compress.sh +++ b/scripts/st_compress.sh @@ -3,14 +3,15 @@ # Settings PGMDIR=/dev/shm N=250 -# If no images are found during thisperiod, relaunch capture process +# If no images are found during this period (seconds), relaunch capture process WAIT=20 COUNT=0 # Start automatically capture process or not AUTOSTART=0 # Default camera to start imaging if no schedule is available -CAMERA="S25H" +CAMERADEV="/dev/video0" +CAPTUREPID=0 # if autostart force a restart if [ $AUTOSTART == 1 ]; then @@ -21,7 +22,7 @@ else STATE="stop" fi -export CAMERA=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((1))}'` +export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'` # For ever loop while true; do @@ -43,7 +44,7 @@ while true; do cp $ST_OBSDIR/control/position.txt . # cp $ST_OBSDIR/control/scale.txt . cp $ST_OBSDIR/control/camera.txt . - export CAMERA=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((1))}'` + export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'` fi # Process only if not stopped @@ -61,8 +62,10 @@ while true; do viewer `ls -1 2*.fits | tail -n1` cp avg.pgm $ST_OBSDIR else - kill -9 $CAPTUREPID - CAPTUREPID=0 + if [ $(($CAPTUREPID)) != 0 ]; then + kill -9 $CAPTUREPID + CAPTUREPID=0 + fi fi # Remove files @@ -81,13 +84,15 @@ while true; do if [ $COUNT -ge $WAIT ]; then COUNT=0 echo "No images found, restarting capture script" - sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA & +# sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA & + sh $ST_DATADIR/scripts/st_capture.sh $CAMERADEV & sleep 1 CAPTUREPID=`pgrep -o -x ffmpeg` fi if [ $STATE == "restart" ]; then if [ $(($CAPTUREPID)) == 0 ]; then - sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA & +# sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA & + sh $ST_DATADIR/scripts/st_capture.sh $CAMERADEV & sleep 1 CAPTUREPID=`pgrep -o -x ffmpeg` fi diff --git a/skymap.c b/skymap.c index 30154cd..715e52c 100644 --- a/skymap.c +++ b/skymap.c @@ -128,7 +128,7 @@ void usage() printf("R R.A.\n"); printf("D Decl.\n"); printf("A Azimuth\n"); - printf("E Elecation\n"); + printf("E Elevation\n"); printf("S All night\n"); printf("h this help\n"); printf("s site (COSPAR)\n"); From 46e2fe699a1e258dd6c85c300b6ef4c1e7c9f982 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sat, 26 Aug 2017 04:20:37 -0300 Subject: [PATCH 20/53] Add helper script st_reduce.sh --- plotfits.c | 2 +- scripts/st_compress.sh | 13 ++++++++----- scripts/st_reduce.sh | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) create mode 100755 scripts/st_reduce.sh diff --git a/plotfits.c b/plotfits.c index 008b91d..350b369 100644 --- a/plotfits.c +++ b/plotfits.c @@ -1297,7 +1297,7 @@ int main(int argc,char *argv[]) // Help if (c=='h') { - printf("Calibrates astrometry. Initially requires manual matching of at least three stars. Use 'a' to select star on the image, then 'b' to select star from the catalog, then 'f' to fit"); + printf("Calibrates astrometry.\nRequires matching of at least three stars. Use 'i' repeatedly for automatic selection of matching sets or 'a' to manually select a star from the image and 'b' to select the corresponding star from the catalog (tree sets needed). Then use 'f' to check fit, 'R' to start again.\nFinish with 'm' to match stars and 'q' writes calibration output\n"); printf("q Quit\n"); printf("a Select star on image\n"); printf("b Select star from catalog\n"); diff --git a/scripts/st_compress.sh b/scripts/st_compress.sh index 9ca1dc9..90ac47b 100755 --- a/scripts/st_compress.sh +++ b/scripts/st_compress.sh @@ -47,8 +47,8 @@ while true; do export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'` fi - # Process only if not stopped - if [ $STATE != "stop" ]; then + # Process only if not restarting + if [ $STATE != "restart" ]; then echo "Compressing captured frames" # Start point @@ -61,7 +61,10 @@ while true; do # Run viewer viewer `ls -1 2*.fits | tail -n1` cp avg.pgm $ST_OBSDIR - else + fi + + # kill capture process just when scheduler sends stop signal + if [ $STATE == "stop" ]; then if [ $(($CAPTUREPID)) != 0 ]; then kill -9 $CAPTUREPID CAPTUREPID=0 @@ -75,8 +78,8 @@ while true; do echo "Finished" else - # There are not enough images available - # Launch capture process + # There are not enough captured frames + # Launch capture process if state is not stop # if time passes with still no images re-launch capture process if [ $STATE != "stop" ]; then echo "Waiting for images. Status: "$STATE diff --git a/scripts/st_reduce.sh b/scripts/st_reduce.sh new file mode 100755 index 0000000..e029003 --- /dev/null +++ b/scripts/st_reduce.sh @@ -0,0 +1 @@ +for file in png/2*.fits; do reduce $file;done From 330fb965fcaf068ae02380f6cbd65856efa72881 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 27 Aug 2017 14:57:56 -0300 Subject: [PATCH 21/53] Add help to reduce.c --- reduce.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/reduce.c b/reduce.c index be630a4..1737890 100644 --- a/reduce.c +++ b/reduce.c @@ -731,7 +731,8 @@ int main(int argc,char *argv[]) sprintf(obs.desig,"%02d%03.0lfA",year-2000,doy+500); cpgopen("/xs"); - cpgpap(0.,1.0); +// cpgpap(0.,1.0); + cpgpap(7,0.75); cpgask(0); cpgsch(0.8); @@ -1101,6 +1102,38 @@ int main(int argc,char *argv[]) redraw=1; continue; } + + if (c=='h'){ + printf("Reduce Satellite tracks. "); + printf("q Quit\n"); + printf("TAB track and stack objects automatically (only classfd sats)\n"); + printf("w write IOD observation to observations.txt\n"); + printf("M/D measure stack and track position (also middle mouse button)\n"); + printf("e change fraction (0.0 to start, 0.5 for medium, 1.0 for the end)\n"); + printf("d provide NORAD satellite number\n"); + printf("C toggle IOD observing conditions G-Good F-Fair P-Poor B-Bad T-Terrible E-Excellent\n"); + printf("B toggle behavior of sat.: F-Flash I-Irregular R-Regular S-Steady X-Uspecified E-Extremely weak\n"); + printf("s select start of satellite track\n"); + printf("f select end of satellite track\n"); + printf("F fit satellite track\n"); + printf("+/= Increase level of masking pixels\n"); + printf("- Lower level for masking pixels (This does not seem to work)\n"); + printf("1 go to the mean pixel value FITS layer\n"); + printf("2 go to the FITS standard deviation layer\n"); + printf("3 go to the maximum pixel value FITS layer\n"); + printf("4 go to the frame number of the maximum pixel value FITS layer\n"); + printf("5 go to the stack and track layer (only after 't' or 'TAB')\n"); + printf("v lower dynamic range\n"); + printf("b increase dynamic range\n"); + printf("c center on cursor\n"); + printf("z zoom in at cursor\n"); + printf("x zoom out at cursor\n"); + printf("R/r reset to start\n"); + printf("m measure position of pixel\n"); + printf("t track & stack, give NORAD satellite number\n"); + printf("E change fraction in tenths\n"); + printf("X pixel mask (also with mouse scroll wheel)\n"); + } } cpgend(); From 3c8d6c3ddf31a00bbb4283ab3da74e946e073dc5 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 27 Aug 2017 14:58:40 -0300 Subject: [PATCH 22/53] Auto start/stop of capture process for each observation. --- scripts/st_compress.sh | 87 +++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/scripts/st_compress.sh b/scripts/st_compress.sh index 90ac47b..dd497ac 100755 --- a/scripts/st_compress.sh +++ b/scripts/st_compress.sh @@ -24,76 +24,83 @@ fi export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'` +echo "Status: "$STATE + # For ever loop while true; do - # Get number of files - NFILES=`ls -1 $PGMDIR/img*.pgm 2>/dev/null | wc -l` # Get state export STATE=`cat $ST_OBSDIR/control/state.txt` + + # Create new directory + if [ $STATE == "restart" ]; then + export DIR=`date -u +%FT%T | sed -e "s/-//g" -e "s/\://g" -e "s|T|/|g"` + mkdir -p $ST_OBSDIR/$DIR + cd $ST_OBSDIR/$DIR + echo "Moving to $ST_OBSDIR/$DIR" + echo "observing" >$ST_OBSDIR/control/state.txt + cp $ST_OBSDIR/control/position.txt . + # cp $ST_OBSDIR/control/scale.txt . + cp $ST_OBSDIR/control/camera.txt . + export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'` + # Remove old captured frames + echo "Removing all captured frames" + # ls -1 $PGMDIR/img*.pgm | awk '{printf("sudo rm -rf %s\n",$1)}' | sh + ls -1 $PGMDIR/img*.pgm | awk '{printf("rm -rf %s\n",$1)}' | sh + fi + + # kill capture process just when scheduler sends stop signal + if [ $STATE == "stop" ]; then + if [ $(($CAPTUREPID)) != 0 ]; then + echo "Stopping capture process" + kill -9 $CAPTUREPID + CAPTUREPID=0 + fi + fi + + # Get number of captured frames + NFILES=`ls -1 $PGMDIR/img*.pgm 2>/dev/null | wc -l` # If enough, process if [ $NFILES -ge $N ]; then - - # Create new directory - if [ $STATE == "restart" ]; then - export DIR=`date -u +%FT%T | sed -e "s/-//g" -e "s/\://g" -e "s|T|/|g"` - mkdir -p $ST_OBSDIR/$DIR - cd $ST_OBSDIR/$DIR - echo "Moving to $ST_OBSDIR/$DIR" - echo "observing" >$ST_OBSDIR/control/state.txt - cp $ST_OBSDIR/control/position.txt . -# cp $ST_OBSDIR/control/scale.txt . - cp $ST_OBSDIR/control/camera.txt . - export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'` - fi - # Process only if not restarting - if [ $STATE != "restart" ]; then - echo "Compressing captured frames" + echo "Compressing $N captured frames" - # Start point - M=`ls -1 $PGMDIR/img*.pgm | head -n1 | sed -e "s/[^0-9]*//g"` + # Start point + M=`ls -1 $PGMDIR/img*.pgm | head -n1 | sed -e "s/[^0-9]*//g"` - # Run pgm2fits + # Run pgm2fits # pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N - pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N >/dev/null + pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N >/dev/null - # Run viewer - viewer `ls -1 2*.fits | tail -n1` - cp avg.pgm $ST_OBSDIR - fi - - # kill capture process just when scheduler sends stop signal - if [ $STATE == "stop" ]; then - if [ $(($CAPTUREPID)) != 0 ]; then - kill -9 $CAPTUREPID - CAPTUREPID=0 - fi - fi + # Run viewer + viewer `ls -1 2*.fits | tail -n1` + cp avg.pgm $ST_OBSDIR # Remove files - echo "Removing captured frames" + echo "Removing $N captured frames" # ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("sudo rm -rf %s\n",$1)}' | sh ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("rm -rf %s\n",$1)}' | sh - echo "Finished" +# echo "Finished" else # There are not enough captured frames # Launch capture process if state is not stop # if time passes with still no images re-launch capture process if [ $STATE != "stop" ]; then - echo "Waiting for images. Status: "$STATE + echo "Waiting for frames. Status: "$STATE COUNT=$(($COUNT+1)) if [ $COUNT -ge $WAIT ]; then COUNT=0 - echo "No images found, restarting capture script" + echo "No frames found, restarting capture script" # sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA & sh $ST_DATADIR/scripts/st_capture.sh $CAMERADEV & sleep 1 CAPTUREPID=`pgrep -o -x ffmpeg` fi + # if restarting then relaunch capture script now if [ $STATE == "restart" ]; then if [ $(($CAPTUREPID)) == 0 ]; then + echo "Restarting capture script" # sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA & sh $ST_DATADIR/scripts/st_capture.sh $CAMERADEV & sleep 1 @@ -101,8 +108,10 @@ while true; do fi fi else - echo "Status: "$STATE + # we are stopped, check for bogus capture process +# echo "Status: "$STATE if [ $(($CAPTUREPID)) != 0 ]; then + echo "Stopping capture process" kill -9 $CAPTUREPID CAPTUREPID=0 fi From 5d4c40b1069eecafe411d347705393c04dda556d Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 27 Aug 2017 15:00:18 -0300 Subject: [PATCH 23/53] Smaller window size at startup. --- skymap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/skymap.c b/skymap.c index 715e52c..ba6de10 100644 --- a/skymap.c +++ b/skymap.c @@ -637,7 +637,8 @@ int main(int argc,char *argv[]) } } - init_plot("/xs",10,0.75); +// init_plot("/xs",10,0.75); + init_plot("/xs",8,0.75); plot_skymap(); From 09d20876d0c7e539e841dee21f59ae4150c5ef33 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 27 Aug 2017 15:54:16 -0300 Subject: [PATCH 24/53] Modded Runsched to enable mixed sequence scheduling. --- runsched.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/runsched.c b/runsched.c index 0087e14..6a10c0c 100644 --- a/runsched.c +++ b/runsched.c @@ -44,6 +44,7 @@ int main(int argc, char *argv[]) struct observation obs[NMAX]; char *env; char datadir[128],obsdir[128]; + int nextobs, dtnext; // Get environment variables env=getenv("ST_DATADIR"); @@ -91,14 +92,21 @@ int main(int argc, char *argv[]) // printf("%s\n",ctime(&rawtime)); // Compute time differences - for (i=0;i dtnext) dtnext=obs[i].dt; + } + nextobs=-1; // Loop over observations for (i=0;i0.0) { - printf("%4.0f %s %s %s %s\n",obs[i].dt,obs[i].stime,obs[i].sra,obs[i].sde,obs[i].startstop); - break; + if(obs[i].dt < dtnext){ + nextobs=i; + dtnext=obs[i].dt; + } +// printf("%4.0f %s %s %s %s\n",obs[i].dt,obs[i].stime,obs[i].sra,obs[i].sde,obs[i].startstop); +// break; } else if (obs[i].dt==0) { if(strstr(obs[i].startstop,"tart")!=NULL){ //printf("Slewing to %s %s\n",obs[i].sra,obs[i].sde); @@ -109,6 +117,10 @@ int main(int argc, char *argv[]) } } + if(nextobs>0){ + // print next observation data if any found + printf("%4.0f %s %s %s %s\n",obs[nextobs].dt,obs[nextobs].stime,obs[nextobs].sra,obs[nextobs].sde,obs[nextobs].startstop); + } // Sleep sleep(1); } From c8577c0fd216b7b4bd330e4c1f3f36a0d0aad631 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 27 Aug 2017 16:00:49 -0300 Subject: [PATCH 25/53] Polish console output --- scripts/st_compress.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/st_compress.sh b/scripts/st_compress.sh index dd497ac..8c107fb 100755 --- a/scripts/st_compress.sh +++ b/scripts/st_compress.sh @@ -52,6 +52,7 @@ while true; do # kill capture process just when scheduler sends stop signal if [ $STATE == "stop" ]; then if [ $(($CAPTUREPID)) != 0 ]; then + echo "" echo "Stopping capture process" kill -9 $CAPTUREPID CAPTUREPID=0 @@ -63,6 +64,7 @@ while true; do # If enough, process if [ $NFILES -ge $N ]; then + echo "" echo "Compressing $N captured frames" # Start point @@ -77,6 +79,7 @@ while true; do cp avg.pgm $ST_OBSDIR # Remove files + echo "" echo "Removing $N captured frames" # ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("sudo rm -rf %s\n",$1)}' | sh ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("rm -rf %s\n",$1)}' | sh @@ -87,10 +90,12 @@ while true; do # Launch capture process if state is not stop # if time passes with still no images re-launch capture process if [ $STATE != "stop" ]; then + echo "" echo "Waiting for frames. Status: "$STATE COUNT=$(($COUNT+1)) if [ $COUNT -ge $WAIT ]; then COUNT=0 + echo "" echo "No frames found, restarting capture script" # sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA & sh $ST_DATADIR/scripts/st_capture.sh $CAMERADEV & From 82bcc9f10e7086065ad2abe8d10dff9e6fb042df Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 27 Aug 2017 16:14:56 -0300 Subject: [PATCH 26/53] Add posibility of disordered scheduling. --- runsched.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runsched.c b/runsched.c index 6a10c0c..e03f824 100644 --- a/runsched.c +++ b/runsched.c @@ -92,6 +92,7 @@ int main(int argc, char *argv[]) // printf("%s\n",ctime(&rawtime)); // Compute time differences + dtnext=0; for (i=0;i dtnext) dtnext=obs[i].dt; @@ -117,7 +118,7 @@ int main(int argc, char *argv[]) } } - if(nextobs>0){ + if(nextobs>=0){ // print next observation data if any found printf("%4.0f %s %s %s %s\n",obs[nextobs].dt,obs[nextobs].stime,obs[nextobs].sra,obs[nextobs].sde,obs[nextobs].startstop); } From ceee3d463c1bb4a0a4d33f0794ded75d5c15845c Mon Sep 17 00:00:00 2001 From: fmederos Date: Mon, 28 Aug 2017 21:04:23 -0300 Subject: [PATCH 27/53] Posibility to calibrate with Nth fits image --- scripts/st_calibrate.sh | 10 +++++++++- scripts/stget.sh | 34 ---------------------------------- 2 files changed, 9 insertions(+), 35 deletions(-) delete mode 100755 scripts/stget.sh diff --git a/scripts/st_calibrate.sh b/scripts/st_calibrate.sh index 9f560d3..311c348 100755 --- a/scripts/st_calibrate.sh +++ b/scripts/st_calibrate.sh @@ -1,7 +1,15 @@ #!/bin/bash +if [ -z $1 ]; then + N=10 +else + echo "Using image $1 to calibrate" + N=$1 + rm test.fits +fi + if [ ! -e "test.fits" ]; then - ls -1 2*.fits | head -n10 | tail -n1 | awk '{printf("cp %s test.fits\n",$1)}' | sh + ls -1 2*.fits | head -n$N | tail -n1 | awk '{printf("cp %s test.fits\n",$1)}' | sh fi sextractor test.fits -c $ST_DATADIR/sextractor/default.sex mv test.cat test.fits.cat diff --git a/scripts/stget.sh b/scripts/stget.sh deleted file mode 100755 index 2ee9716..0000000 --- a/scripts/stget.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -# Get date -DATE=`date +%Y%m%d_%H%M%S` - -# Get cookie -wget --post-data='identity=yourlogin&password=yourpassword' --cookies=on --keep-session-cookies --save-cookies=/tmp/cookies.txt 'https://www.space-track.org/ajaxauth/login' -o /tmp/stget.log - -# Get data -wget --keep-session-cookies --load-cookies=/tmp/cookies.txt 'https://www.space-track.org/basicspacedata/query/class/tle_latest/ORDINAL/1/EPOCH/%3Enow-30/format/3le' -O $ST_TLEDIR/catalog.tle -dos2unix $ST_TLEDIR/catalog.tle -sed -i -e "s/^1 /1 0000/g" -e "s/^2 /2 0000/g" -e "s/^1 /1 000/g" -e "s/^2 /2 000/g" -e "s/^1 /1 00/g" -e "s/^2 /2 00/g" -e "s/^1 /1 0/g" -e "s/^2 /2 0/g" $ST_TLEDIR/catalog.tle -cp $ST_TLEDIR/catalog.tle $ST_TLEDIR/${DATE}_catalog.txt - -# Get classfd -wget http://www.prismnet.com/~mmccants/tles/classfd.zip --no-check-certificate -O $ST_TLEDIR/classfd.zip -unzip -o $ST_TLEDIR/classfd.zip -dos2unix $ST_TLEDIR/classfd.tle -cp $ST_TLEDIR/classfd.tle $ST_TLEDIR/${DATE}_classfd.txt -#mv $HOME/classfd.tle $ST_TLEDIR/classfd.tle -rm $ST_TLEDIR/classfd.zip - -# Get inttles -wget http://www.prismnet.com/~mmccants/tles/inttles.zip --no-check-certificate -O $ST_TLEDIR/inttles.zip -unzip -o $ST_TLEDIR/inttles.zip -dos2unix $ST_TLEDIR/inttles.tle -cp $ST_TLEDIR/inttles.tle $ST_TLEDIR/${DATE}_inttles.txt -#mv $HOME/inttles.tle $ST_TLEDIR/inttles.tle -rm $ST_TLEDIR/inttles.zip - -#rm $HOME/login - -# Create bulk file -cat $ST_TLEDIR/classfd.tle $ST_TLEDIR/catalog.tle >$ST_TLEDIR/bulk.tle From 830b8cd053a633ecd9774e2fd2bd42ca73a461f9 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sat, 9 Sep 2017 15:02:00 -0300 Subject: [PATCH 28/53] Debugging --- data/cameras.txt | 2 +- runsched.c | 3 +-- scripts/st_compress.sh | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data/cameras.txt b/data/cameras.txt index 256afd8..d42008c 100644 --- a/data/cameras.txt +++ b/data/cameras.txt @@ -1,6 +1,6 @@ # List of available cameras # Camera mnemonic (Camera/Optics), field width, field height, horiz resolution (neg.to mirror), vert resolution (neg.to mirror), mount type (AltAz/Eq/XY/Fixed), video device , Azimuth (for fixed, south is zero), Altitude (for fixed) -S25H 20.3 16.2 -720 576 Fix /dev/video-S25H 32 29.5 +S25H 19.7 15.7 -720 576 Fix /dev/video-S25H 37 43 W50H 7.21 5.31 -720 576 AltAz /dev/video1 W28H 13.10 7.97 D85V 9.97 14.96 diff --git a/runsched.c b/runsched.c index e03f824..5841366 100644 --- a/runsched.c +++ b/runsched.c @@ -92,13 +92,12 @@ int main(int argc, char *argv[]) // printf("%s\n",ctime(&rawtime)); // Compute time differences - dtnext=0; for (i=0;i dtnext) dtnext=obs[i].dt; } nextobs=-1; + dtnext=9999999; // Loop over observations for (i=0;i0.0) { diff --git a/scripts/st_compress.sh b/scripts/st_compress.sh index 8c107fb..8e9e68a 100755 --- a/scripts/st_compress.sh +++ b/scripts/st_compress.sh @@ -110,6 +110,7 @@ while true; do sh $ST_DATADIR/scripts/st_capture.sh $CAMERADEV & sleep 1 CAPTUREPID=`pgrep -o -x ffmpeg` + COUNT=0 fi fi else From 9da87b0765fd50abc702632138f81f60a19a6b1d Mon Sep 17 00:00:00 2001 From: fmederos Date: Sat, 9 Sep 2017 15:03:23 -0300 Subject: [PATCH 29/53] Helper scripts --- scripts/st_ristretto.sh | 1 + scripts/st_runsched.sh | 5 +++++ 2 files changed, 6 insertions(+) create mode 100755 scripts/st_ristretto.sh create mode 100755 scripts/st_runsched.sh diff --git a/scripts/st_ristretto.sh b/scripts/st_ristretto.sh new file mode 100755 index 0000000..4f6a882 --- /dev/null +++ b/scripts/st_ristretto.sh @@ -0,0 +1 @@ +ristretto png/*.png diff --git a/scripts/st_runsched.sh b/scripts/st_runsched.sh new file mode 100755 index 0000000..eb9b086 --- /dev/null +++ b/scripts/st_runsched.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +cd $ST_DATADIR + +runsched From e420fa2431b2d1352af362e134537f03abb719a7 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 24 Sep 2017 02:44:05 -0300 Subject: [PATCH 30/53] Update camera FOV and COSPAR id --- data/cameras.txt | 2 +- data/sites.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/cameras.txt b/data/cameras.txt index d42008c..71f6ed9 100644 --- a/data/cameras.txt +++ b/data/cameras.txt @@ -1,6 +1,6 @@ # List of available cameras # Camera mnemonic (Camera/Optics), field width, field height, horiz resolution (neg.to mirror), vert resolution (neg.to mirror), mount type (AltAz/Eq/XY/Fixed), video device , Azimuth (for fixed, south is zero), Altitude (for fixed) -S25H 19.7 15.7 -720 576 Fix /dev/video-S25H 37 43 +S25H 20.4 16.3 -720 576 Fix /dev/video-S25H 37 43 W50H 7.21 5.31 -720 576 AltAz /dev/video1 W28H 13.10 7.97 D85V 9.97 14.96 diff --git a/data/sites.txt b/data/sites.txt index 93d8b7c..f610f76 100644 --- a/data/sites.txt +++ b/data/sites.txt @@ -65,4 +65,4 @@ 9003 CP -24.6272 -70.4047 2638 Cerro Paranal 9004 LP 28.7622 -17.8775 2396 Isaac Newton 9999 GR 47.348 5.5151 100 Graves -0531 FM -34.8961 -56.1227 30 Fernando Mederos +0899 FM -34.8961 -56.1227 30 Fernando Mederos From 1a5ecb4ef1c8b71cebe852916097e80c26ab35d5 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 24 Sep 2017 02:51:04 -0300 Subject: [PATCH 31/53] Updated install script: modded pnmenc.c and wcslib retrieval and added eog and ntp to apt install. --- README2.md | 3 ++- scripts/install_dependencies.sh | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README2.md b/README2.md index 5307995..8e5dac5 100644 --- a/README2.md +++ b/README2.md @@ -21,7 +21,8 @@ Install notes * Run `make` on the sattools folder * Helper scripts install_dependencies.sh and install_sattools.sh are available at scripts directory. - You can try run these scripts to install or use them as install guide. + You can try run these scripts to install or use them as install guide. + Note that install_dependencies.sh needs to be run with admin privileges (sudo ./install_dependencies.sh). * If you re-run install_sattools.sh you should previously rmdir sattools directory or otherwise souces will not be fetched even if they are not present at that dir diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh index 184bfe4..1ad442c 100755 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -3,7 +3,7 @@ echo "Step 1.1: install dependencies" sleep 1 apg-get update -apt-get install emacs gfortran libpng-dev libx11-dev libjpeg-dev libexif-dev git dos2unix sextractor +apt-get install ntp eog emacs gfortran libpng-dev libx11-dev libjpeg-dev libexif-dev git dos2unix sextractor echo "Step 1.2: goto /usr/local/src" sleep 1 @@ -82,7 +82,8 @@ rm /usr/local/src/qfits-5.2.0.tar.gz echo "Step 4.1: download wcslib-2.9" sleep 1 cd /usr/local/src -wget -c http://www.epta.eu.org/~bassa/wcslib-2.9.tar +wget -c "https://drive.google.com/uc?export=download&id=0B-15JZVdjJi4QW0zZmZUM1ZXblU" -O wcslib-2.9.tar +#wget -c http://www.epta.eu.org/~bassa/wcslib-2.9.tar echo "Step 4.2: unpack wcslib" sleep 1 @@ -164,7 +165,8 @@ bzip2 -cd ffmpeg-snapshot.tar.bz2 | tar xvf - echo "Step 7.3: patch pgmenc.c" sleep 1 cd /usr/local/src/ffmpeg/libavcodec -wget https://dl.dropboxusercontent.com/u/52579487/pnmenc.c -O pnmenc.c +wget -c -O pnmenc.c "https://drive.google.com/uc?export=download&id=0B-15JZVdjJi4YnVEdXEzVmExVEU" +#wget https://dl.dropboxusercontent.com/u/52579487/pnmenc.c -O pnmenc.c echo "Step 7.4: configure, make,make install" sleep 1 From 41dbe04431a3d434119f3286bdf8be35c406a6f1 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 24 Sep 2017 02:55:17 -0300 Subject: [PATCH 32/53] Add .desktop files for automatic run at system startup. --- scripts/st_compress.desktop | 12 ++++++++++++ scripts/st_eog.desktop | 12 ++++++++++++ scripts/st_runsched.desktop | 12 ++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 scripts/st_compress.desktop create mode 100644 scripts/st_eog.desktop create mode 100644 scripts/st_runsched.desktop diff --git a/scripts/st_compress.desktop b/scripts/st_compress.desktop new file mode 100644 index 0000000..1d47580 --- /dev/null +++ b/scripts/st_compress.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=0.9.4 +Type=Application +Name=ST_Compress +Comment= +Exec=st_compress.sh +OnlyShowIn=XFCE; +StartupNotify=false +Terminal=true +Hidden=false + diff --git a/scripts/st_eog.desktop b/scripts/st_eog.desktop new file mode 100644 index 0000000..128539e --- /dev/null +++ b/scripts/st_eog.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=0.9.4 +Type=Application +Name=EOG +Comment= +Exec=st_eog.sh +OnlyShowIn=XFCE; +StartupNotify=false +Terminal=false +Hidden=false + diff --git a/scripts/st_runsched.desktop b/scripts/st_runsched.desktop new file mode 100644 index 0000000..3c2b546 --- /dev/null +++ b/scripts/st_runsched.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=0.9.4 +Type=Application +Name=Runshed +Comment= +Exec=st_runsched.sh +OnlyShowIn=XFCE; +StartupNotify=false +Terminal=true +Hidden=false + From 26d26e7568ceaaf6403a44595217473370e3d840 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 24 Sep 2017 02:56:52 -0300 Subject: [PATCH 33/53] Mod compress and runsched scripts for system startup compatibility. --- scripts/st_compress.sh | 18 ++++++++++++++++-- scripts/st_runsched.sh | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/st_compress.sh b/scripts/st_compress.sh index 8e9e68a..ebe8d1f 100755 --- a/scripts/st_compress.sh +++ b/scripts/st_compress.sh @@ -1,5 +1,7 @@ #!/bin/bash +source ~/.bashrc + # Settings PGMDIR=/dev/shm N=250 @@ -13,6 +15,15 @@ AUTOSTART=0 CAMERADEV="/dev/video0" CAPTUREPID=0 +# Check obsdir exists +if [ ! -d $ST_OBSDIR ]; then + mkdir $ST_OBSDIR +fi +if [ ! -d $ST_OBSDIR/control ]; then + mkdir $ST_OBSDIR/control +fi + + # if autostart force a restart if [ $AUTOSTART == 1 ]; then echo "restart" >$ST_OBSDIR/control/state.txt @@ -46,7 +57,8 @@ while true; do # Remove old captured frames echo "Removing all captured frames" # ls -1 $PGMDIR/img*.pgm | awk '{printf("sudo rm -rf %s\n",$1)}' | sh - ls -1 $PGMDIR/img*.pgm | awk '{printf("rm -rf %s\n",$1)}' | sh + #ls -1 $PGMDIR/img*.pgm | awk '{printf("rm -rf %s\n",$1)}' | sh + find $PGMDIR -type f -name './img*.pgm' | awk '{printf("rm -rf %s\n",$1)}' | sh fi # kill capture process just when scheduler sends stop signal @@ -61,9 +73,10 @@ while true; do # Get number of captured frames NFILES=`ls -1 $PGMDIR/img*.pgm 2>/dev/null | wc -l` + #NFILES=`find $PGMDIR -type f -name 'img*.pgm' |wc -l` # If enough, process if [ $NFILES -ge $N ]; then - + COUNT=0 echo "" echo "Compressing $N captured frames" @@ -83,6 +96,7 @@ while true; do echo "Removing $N captured frames" # ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("sudo rm -rf %s\n",$1)}' | sh ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("rm -rf %s\n",$1)}' | sh + #find $PGMDIR -type f -name 'img*.pgm' | head -n$N | awk '{printf("rm -rf %s\n",$1)}' | sh # echo "Finished" else diff --git a/scripts/st_runsched.sh b/scripts/st_runsched.sh index eb9b086..a1b7ac5 100755 --- a/scripts/st_runsched.sh +++ b/scripts/st_runsched.sh @@ -1,5 +1,7 @@ #!/bin/bash +source ~/.bashrc + cd $ST_DATADIR runsched From f63c8e9b516cfe47f52f03cf0028bf2cc93ad66b Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 24 Sep 2017 03:01:40 -0300 Subject: [PATCH 34/53] Move environment vars setup to .xsessionrc instead of .bashrc for run at system startup. --- scripts/install_sattools.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/install_sattools.sh b/scripts/install_sattools.sh index e25e8cc..cfea301 100755 --- a/scripts/install_sattools.sh +++ b/scripts/install_sattools.sh @@ -37,12 +37,11 @@ rm classfd.zip echo "Step 2.1: set environment variables" sleep 1 cd -echo "export PGPLOT_DIR=/usr/local/src/pgplot-5.2.2" >>$HOME/.bashrc -#echo "export ST_COSPAR=4171" >>$HOME/.bashrc -echo "export ST_COSPAR=0531" >>$HOME/.bashrc -echo "export ST_DATADIR=$HOME/code/c/satellite/sattools" >>$HOME/.bashrc -echo "export ST_TLEDIR=$HOME/code/c/satellite/sattools/tle" >>$HOME/.bashrc -echo "export ST_OBSDIR=$HOME/satobs" >>$HOME/.bashrc +echo "export PGPLOT_DIR=/usr/local/src/pgplot-5.2.2" >>$HOME/.xsessionrc +echo "export ST_COSPAR=4171" >>$HOME/.xsessionrc +echo "export ST_DATADIR=$HOME/code/c/satellite/sattools" >>$HOME/.xsessionrc +echo "export ST_TLEDIR=$HOME/code/c/satellite/sattools/tle" >>$HOME/.xsessionrc +echo "export ST_OBSDIR=$HOME/satobs" >>$HOME/.xsessionrc mkdir $ST_OBSDIR mkdir $ST_OBSDIR/control From aa3fcd64dfc303f611c3befa68c6ce114bcddb22 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 24 Sep 2017 03:03:40 -0300 Subject: [PATCH 35/53] Added to scripts dir --- scripts/stget.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 scripts/stget.sh diff --git a/scripts/stget.sh b/scripts/stget.sh new file mode 100755 index 0000000..2ee9716 --- /dev/null +++ b/scripts/stget.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Get date +DATE=`date +%Y%m%d_%H%M%S` + +# Get cookie +wget --post-data='identity=yourlogin&password=yourpassword' --cookies=on --keep-session-cookies --save-cookies=/tmp/cookies.txt 'https://www.space-track.org/ajaxauth/login' -o /tmp/stget.log + +# Get data +wget --keep-session-cookies --load-cookies=/tmp/cookies.txt 'https://www.space-track.org/basicspacedata/query/class/tle_latest/ORDINAL/1/EPOCH/%3Enow-30/format/3le' -O $ST_TLEDIR/catalog.tle +dos2unix $ST_TLEDIR/catalog.tle +sed -i -e "s/^1 /1 0000/g" -e "s/^2 /2 0000/g" -e "s/^1 /1 000/g" -e "s/^2 /2 000/g" -e "s/^1 /1 00/g" -e "s/^2 /2 00/g" -e "s/^1 /1 0/g" -e "s/^2 /2 0/g" $ST_TLEDIR/catalog.tle +cp $ST_TLEDIR/catalog.tle $ST_TLEDIR/${DATE}_catalog.txt + +# Get classfd +wget http://www.prismnet.com/~mmccants/tles/classfd.zip --no-check-certificate -O $ST_TLEDIR/classfd.zip +unzip -o $ST_TLEDIR/classfd.zip +dos2unix $ST_TLEDIR/classfd.tle +cp $ST_TLEDIR/classfd.tle $ST_TLEDIR/${DATE}_classfd.txt +#mv $HOME/classfd.tle $ST_TLEDIR/classfd.tle +rm $ST_TLEDIR/classfd.zip + +# Get inttles +wget http://www.prismnet.com/~mmccants/tles/inttles.zip --no-check-certificate -O $ST_TLEDIR/inttles.zip +unzip -o $ST_TLEDIR/inttles.zip +dos2unix $ST_TLEDIR/inttles.tle +cp $ST_TLEDIR/inttles.tle $ST_TLEDIR/${DATE}_inttles.txt +#mv $HOME/inttles.tle $ST_TLEDIR/inttles.tle +rm $ST_TLEDIR/inttles.zip + +#rm $HOME/login + +# Create bulk file +cat $ST_TLEDIR/classfd.tle $ST_TLEDIR/catalog.tle >$ST_TLEDIR/bulk.tle From 3111f76481bec7330634c0e6cd7c75d001ada086 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 24 Sep 2017 03:04:56 -0300 Subject: [PATCH 36/53] Helper scripts --- scripts/st_calbulk.sh | 27 +++++++++++++++++++++++++++ scripts/st_eog.sh | 7 +++++++ 2 files changed, 34 insertions(+) create mode 100755 scripts/st_calbulk.sh create mode 100755 scripts/st_eog.sh diff --git a/scripts/st_calbulk.sh b/scripts/st_calbulk.sh new file mode 100755 index 0000000..7d7733d --- /dev/null +++ b/scripts/st_calbulk.sh @@ -0,0 +1,27 @@ +#./bin/bash + +CALFRAME=1 + +# Loop into every directory +for obsdir in *; do + if [ -d $obsdir ]; then + echo $obsdir + cd $obsdir + while true; do + # calibrate Nth image captured + st_calibrate.sh $CALFRAME + # check if no calibration data was output + if [ ! -e "out.dat" ]; then + read -p "Delete observation?" yn + case $yn in + [Yy]* ) cd ..; rm -rf $obsdir; break;; + [Nn]* ) CALFRAME=$(($CALFRAME+1)); continue;; + * ) echo "Please answer y or n.";; + esac + else + cd .. + break + fi + done + fi +done diff --git a/scripts/st_eog.sh b/scripts/st_eog.sh new file mode 100755 index 0000000..cd5af9c --- /dev/null +++ b/scripts/st_eog.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +source ~/.bashrc + +cd $ST_OBSDIR + +eog avg.pgm From d57cd9536b690a1877116665259f5b2cb458dc55 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 1 Oct 2017 02:20:24 -0300 Subject: [PATCH 37/53] Add helper script to sequentially calibrate all observations in a day --- scripts/st_calbulk.sh | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/scripts/st_calbulk.sh b/scripts/st_calbulk.sh index 7d7733d..909bf38 100755 --- a/scripts/st_calbulk.sh +++ b/scripts/st_calbulk.sh @@ -1,27 +1,31 @@ #./bin/bash -CALFRAME=1 - # Loop into every directory for obsdir in *; do if [ -d $obsdir ]; then echo $obsdir cd $obsdir - while true; do - # calibrate Nth image captured - st_calibrate.sh $CALFRAME - # check if no calibration data was output - if [ ! -e "out.dat" ]; then - read -p "Delete observation?" yn - case $yn in - [Yy]* ) cd ..; rm -rf $obsdir; break;; - [Nn]* ) CALFRAME=$(($CALFRAME+1)); continue;; - * ) echo "Please answer y or n.";; - esac - else - cd .. - break - fi - done + # check if observation is calibrated + if [ ! -e "out.dat" ]; then + CALFRAME=1 + while true; do + # calibrate Nth image captured + st_calibrate.sh $CALFRAME + # check if no calibration data was output + if [ ! -e "out.dat" ]; then + read -p "Delete observation?" yn + case $yn in + [Yy]* ) cd ..; rm -rf $obsdir; break;; + [Nn]* ) CALFRAME=$(($CALFRAME+1)); continue;; + * ) echo "Please answer y or n.";; + esac + else + cd .. + break + fi + done + else + cd .. + fi fi done From d957abd5ba031bb38bc25787c432b5687d99f78c Mon Sep 17 00:00:00 2001 From: fmederos Date: Sun, 1 Oct 2017 02:21:31 -0300 Subject: [PATCH 38/53] Debug automatic matching triangles routine. --- plotfits.c | 252 +++++++++++++++++++++++++---------------------------- 1 file changed, 119 insertions(+), 133 deletions(-) diff --git a/plotfits.c b/plotfits.c index 350b369..bfd1492 100644 --- a/plotfits.c +++ b/plotfits.c @@ -22,10 +22,11 @@ #define MAXROT 10*D2R // Maximum expected rotation error (radians) #define MAXSCALERR 1.05 // Expected image to astrometric map scaling error #define DISTMATCHTOL 6 // Distance tolerance in pixels between matching stars after aplying scale and rotation -#define MAXMAGERR 2.5 // Expected magnitude error between imaged stars and corresponding astometric catalog stars -#define MAGMATCHTOL 0.5 // Relative magnitude between matching stars tolerance -#define MATCHVALRATIO 0.30 // Ratio of imaged stars that must fit into astrometric catalog after applying matching transformation -#define DEBUG 0 +#define MAXMAGERR 3 // Expected magnitude error between imaged stars and corresponding astometric catalog stars +#define MAGMATCHTOL 1 // Relative magnitude between matching stars tolerance +#define DEFMATCHVALRATIO 0.3 // Default ratio of imaged stars that must fit into astrometric catalog after applying matching transformation (can be adjusted at runtime) +#define AUTOMAGLIM 1 // Automatically set astrometric catalog magnitude limit +#define DEBUG 1 struct star { double ra,de; @@ -64,6 +65,8 @@ double gmst(double mjd); double modulo(double x,double y); void precess(double mjd0,double ra0,double de0,double mjd,double *ra,double *de); double sex2dec(char *s); +float matchvalratio=DEFMATCHVALRATIO; + // Read astrometric catalog struct catalog read_astrometric_catalog(char *filename,float mmin,float sx,float sy,float angle) @@ -301,10 +304,10 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, float mag12,mag13,mag23,ang12,ang13,dis12,dis13,dis23,cenX,cenY; float mmax,mmin,matchscale,matchrot,matchXtras,matchYtras; float error=MAXPOINTERR; // maximum expected pointing error in pixels - int i,j,n,n2,s1,s2,s3,m1,m2,m3; + int i,j,n,n2,s1,s2,s3,m1,m2,m3; static int nmatch; - static float mave,size; clock_t start_t, end_t; + static float mave,size; start_t=clock(); @@ -318,69 +321,71 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // Acceptable minimum distance from stars in triangle is set as image width minus pointing error // In the future min distance between stars and estimated pointing error should be given in arcsecs and converted // to pixels - -// size=(img.naxis2-error)/2; - size=(img.naxis2-error)/3; - // Compute magnitude average - mave=0; - for (i=0;in;i++) { - r=cat->mag[i]; - if(r > mmax) - mmax=r; - if(r < mmin) - mmin=r; - mave+=r; - } - mave/=cat->n; -#if DEBUG>2 - fprintf(stdout,"Image height: %d, Expected error: %f, Ref.Tria.Size: %f\n",img.naxis2,error,size); -#endif - if(size<0){ - fprintf(stdout,"Warning: Pointing inaccuracy too high\n"); - size=10; - } + + // if a reference triangle match was already found, we want to find another one, so we don't start + // from zero + if((triast[0]!=0) || (triast[1]!=0) || (triast[2]!=0)){ + // this time search for another match beginning with the following 3rd star + triast[2]++; #if DEBUG>0 - fprintf(stdout,"Stars in imaged catalog: %d, stars in astrometric catalog: %d.\n", cat->n, ast->n); - fprintf(stdout,"MMin:%2.1f,MMax:%2.1f,MAve.:%2.1f \n",mmin,mmax,mave); + fprintf(stdout,"Try different match.\n"); #endif - - // if last time a suitable reference triangle was found - if(*nselect>=3){ - // and also a match was found - if(nmatch==3){ - // this time search for another match beginning with the following 3rd star - triast[2]++; -#if DEBUG>2 - fprintf(stdout,"Try different match.\n"); -#endif - } - else{ - // no match was found for last suitable triangle - // so search for another reference triangle starting from the following 3rd star - // commented for testing... - //tricat[2]++; - // erase matching triangle - triast[0]=0; - triast[1]=0; - triast[2]=0; -#if DEBUG>2 - fprintf(stdout,"Try different triangle. Size: %f\n",size); -#endif - } } - + else{ + // Either no match was found or this is the first time the routine is launched so + // we calculate reference triangle parameters... + // size=(img.naxis2-error)/2; + size=(img.naxis2-error)/3; + // Compute magnitude average + mave=0; + mmax=0; + mmin=10; + for (i=0;in;i++) { + r=cat->mag[i]; + if(r > mmax) + mmax=r; + if(r < mmin) + mmin=r; + mave+=r; + } + mave/=cat->n; + #if DEBUG>2 + fprintf(stdout,"Image height: %d, Expected error: %f, Ref.Tria.Size: %f\n",img.naxis2,error,size); + #endif + + if(size<0){ + fprintf(stdout,"Warning: Pointing inaccuracy too high\n"); + size=10; + } + #if DEBUG>0 + fprintf(stdout,"Stars in imaged catalog: %d, stars in astrometric catalog: %d.\n", cat->n, ast->n); + fprintf(stdout,"MMin:%2.1f,MMax:%2.1f,MAve.:%2.1f \n",mmin,mmax,mave); + #endif + + triast[0]=0; + triast[1]=0; + triast[2]=0; +#if DEBUG>2 + fprintf(stdout,"Try different triangle. Size: %f\n",size); +#endif + } + + *nselect=0; + nmatch=0; // search for candidate triangles satisfying size minimum and stars magnitude, later we can fall back to smaller size if no suitable triangle // is found - while((*nselect<3) && (size > 10)){ +// while((*nselect<3) && (size > 10)){ + while((nmatch<3) && (size > 10)){ +// *nselect=0; #if DEBUG>1 fprintf(stdout,"Looking for triangles with min size %4.0f\n",size); #endif // Search candidate for 1st star - for(s1=tricat[0];(*nselect<3) && (s1 <= cat->n);s1++){ + for(s1=tricat[0];(nmatch<3) && (s1 <= cat->n);s1++){ // discard if outside high magnitude range r=cat->mag[s1]; if(r > mave){ @@ -413,7 +418,7 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, fprintf(stdout,"Looking for 2nd star of triangle.\n"); #endif // Search candidate for 2nd star - for(s2=tricat[1];(*nselect<3) && (s2 <= cat->n);s2++){ + for(s2=tricat[1];(nmatch<3) && (s2 <= cat->n);s2++){ // discard candidate if outside magnitude range r=cat->mag[s2]; if(r > mave){ @@ -454,7 +459,7 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, fprintf(stdout,"Looking for 3rd star of triangle.\n"); #endif // Search candidate for 3rd star beginning from the last candidate found - for(s3=tricat[2];(*nselect<3) && (s3 <= cat->n);s3++){ + for(s3=tricat[2];(nmatch<3) && (s3 <= cat->n);s3++){ // discard candidate if outside magnitude range r=cat->mag[s3]; if(r > mave){ @@ -496,7 +501,8 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, #if DEBUG>1 fprintf(stdout,"Candidate star 3: %d, magnitude: %.1f, distance to star 2: %.1f \n",s3,cat->mag[s3],r); #endif -#if DEBUG>0 + +#if DEBUG>1 fprintf(stdout,"\n"); fprintf(stdout,"Reference triangle: %d, %d, %d\n",s1,s2,s3); fprintf(stdout,"Magnitudes: %f, %f, %f\n",cat->mag[s1],cat->mag[s2],cat->mag[s3]); @@ -520,52 +526,6 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // also magnitude difference between stars of matching triangle should closely match magn diff between stars of imaged // reference triangle, tolerance for this magnitude match should not be high (0.5 magn or so) - //74 - //392 - //107 - //316 - //111 - //319 - //261 stars matched - if(s1==74 && s2==107 && s3==111){ - end_t=clock(); - fprintf(stdout,"Special reference triangle found\n"); - d=(float)(end_t - start_t)/CLOCKS_PER_SEC; - fprintf(stdout,"Seconds elapsed: %f\n",d); -// m1=392; -// m2=316; -// m3=319; -// nmatch=3; -// continue; - start_t=clock(); - } - //74 - //392 - //111 - //319 - //154 - //338 - //252 stars matched - if(s1==74 && s2==111 && s3==154){ - end_t=clock(); - fprintf(stdout,"Special reference triangle found\n"); - d=(float)(end_t - start_t)/CLOCKS_PER_SEC; - fprintf(stdout,"Seconds elapsed: %f\n",d); -// m1=392; -// m2=319; -// m3=338; -// nmatch=3; -// continue; - start_t=clock(); - } -// else{ -// s3++; -// *nselect=2; -// continue; -// } - -// con mapa magnitud 8 demora 33 seg. en encontrar el tri{angulo especial -// con precalculo paso a demorar 20seg! nmatch=0; // Search for candidate 1st match star @@ -725,8 +685,12 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, } // m3 is viable candidate for match to 3rd star r=ast->mag[m3]; -#if DEBUG>0 +#if DEBUG>1 fprintf(stdout,"Match found with 3rd match star: %d, magnitude: %.1f \n",m3,r); +#endif +#if DEBUG>0 + fprintf(stdout,"Reference triangle: %d, %d, %d\n",s1,s2,s3); + fprintf(stdout,"Match found with stars: %d, %d, %d\n",m1,m2,m3); #endif triast[2]=m3; @@ -736,7 +700,7 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // We will need to calculate scale, rotation and translation end_t=clock(); -#if DEBUG>0 +#if DEBUG>1 fprintf(stdout,"\n"); fprintf(stdout,"Match triangle found: %d,%d,%d\n",m1,m2,m3); fprintf(stdout,"Magnitudes: %f, %f, %f\n",ast->mag[m1],ast->mag[m2],ast->mag[m3]); @@ -748,11 +712,6 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, #endif start_t=clock(); - if(m1==101 && m2==80 && m3==87){ - end_t=clock(); - fprintf(stdout,"Special match triangle found\n"); - } - // Scale transformation calculation // scaling from ref 1-2 to match 1-2 was previously calculated in matchscale, now we average with // ref 2-3 to match 2-3 and ref 3-1 to match 3-1 @@ -821,7 +780,7 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, matchXtras /= 3; matchYtras /= 3; -#if DEBUG>0 +#if DEBUG>1 fprintf(stdout,"Transformation:\nScale: %f\nRotation: %f\nXTraslat: %f\nYTraslat: %f\n",matchscale,matchrot,matchXtras,matchYtras); #endif @@ -854,15 +813,15 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, } } } - if(n < n2*MATCHVALRATIO){ + if(n < n2*matchvalratio){ #if DEBUG>0 fprintf(stdout,"Match discarded for insufficient match number: %d out of %d checked stars\n",n,n2); #endif - if(m1==101 && m2==80 && m3==87){ - end_t=clock(); - fprintf(stdout,"Special match triangle was discarded, halting...\n"); - nmatch=3; - } +// if(m1==101 && m2==80 && m3==87){ +// end_t=clock(); +// fprintf(stdout,"Special match triangle was discarded, halting...\n"); +// nmatch=3; +// } continue; } @@ -877,9 +836,8 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, } if(nmatch<3){ triast[0]=0; - triast[1]=0; - triast[2]=0; - // try new 3rd star + // if no match was found for this ref triangle continue looking for ref triangles + // next try with following 3rd star *nselect=2; #if DEBUG>1 fprintf(stdout,"No match found for this triangle\n"); @@ -887,37 +845,43 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, } } // if no triangle selected we will try next 2nd star and try again all possible 3rd stars - if(*nselect<3){ + if(nmatch<3){ tricat[2]=0; + *nselect=1; #if DEBUG>2 - fprintf(stdout,"Try next 2nd star.\n"); + fprintf(stdout,"Try next 3rd star.\n"); #endif } } // if no triangle selected we will try next 1st star and try again all possible 2nd stars - if(*nselect<3){ + if(nmatch<3){ tricat[1]=0; + *nselect=0; #if DEBUG>2 - fprintf(stdout,"Try next 1st star.\n"); + fprintf(stdout,"Try next 2nd star.\n"); #endif } } // at this point either found 3 candidate stars or already tried all candidate stars without success - // if loop continues will look for smaller triangles and accept higher magnitudes next iteration - if(*nselect<3){ + // if loop continues will look for smaller triangles, accept higher magnitude stars and + // accept lower match ratio for next iteration + if(nmatch<3){ size/=1.25; - mave+=0.25; -#if DEBUG>1 - fprintf(stdout,"Decrased minimum size and increase max magnitude for next search.\n"); + mave+=0.25; + // relax match constraint + matchvalratio/=1.25; + tricat[0]=0; +#if DEBUG>0 + fprintf(stdout,"Catalog completely parsed with no suitable reference triangle found. Decrasing minimum size, increase max magnitude for next search.\n"); #endif } } // if we could not find suitable triplet erase triange in catalog tricat[] - if(*nselect<3){ + if(nmatch<3){ tricat[0]=0; tricat[1]=0; tricat[2]=0; -#if DEBUG>1 +#if DEBUG>0 fprintf(stdout,"Did not find any suitable reference triangle.\n"); #endif } @@ -1011,6 +975,20 @@ int main(int argc,char *argv[]) // Read catalogs cat=read_pixel_catalog(filename); ast=read_astrometric_catalog(starfile,mag,sx,sy,-q); + + // Adjust magnitude limit if configured for so + if (AUTOMAGLIM){ + while (ast.n > cat.n){ + mag -= 0.5; + ast=read_astrometric_catalog(starfile,mag,sx,sy,-q); + } + while (ast.n < cat.n){ + mag += 0.25; + ast=read_astrometric_catalog(starfile,mag,sx,sy,-q); + } + fprintf(stdout,"Astrometric map magnitude limit: %2.2f\n",mag); + fprintf(stdout,"Stars in map: %d, extracted imaged stars: %d\n",ast.n,cat.n); + } // Open PGPlot server cpgopen("/xs"); @@ -1142,6 +1120,14 @@ int main(int argc,char *argv[]) // triast[2]=-1; ast=read_astrometric_catalog(starfile,mag,sx,sy,-q); //ast=reread_astrometric_catalog(starfile,mag); + matchvalratio=DEFMATCHVALRATIO; + tricat[0]=0; + tricat[1]=0; + tricat[2]=0; + triast[0]=0; + triast[1]=0; + triast[2]=0; + redraw=1; nselect=0; } From e8c3f2aa09872cb725e8ae23a121ef603a407462 Mon Sep 17 00:00:00 2001 From: fmederos Date: Mon, 16 Oct 2017 02:45:56 -0300 Subject: [PATCH 39/53] Debugging auto selection of calibration stars --- plotfits.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plotfits.c b/plotfits.c index bfd1492..6002482 100644 --- a/plotfits.c +++ b/plotfits.c @@ -22,11 +22,11 @@ #define MAXROT 10*D2R // Maximum expected rotation error (radians) #define MAXSCALERR 1.05 // Expected image to astrometric map scaling error #define DISTMATCHTOL 6 // Distance tolerance in pixels between matching stars after aplying scale and rotation -#define MAXMAGERR 3 // Expected magnitude error between imaged stars and corresponding astometric catalog stars -#define MAGMATCHTOL 1 // Relative magnitude between matching stars tolerance -#define DEFMATCHVALRATIO 0.3 // Default ratio of imaged stars that must fit into astrometric catalog after applying matching transformation (can be adjusted at runtime) +#define MAXMAGERR 2.5 // Expected magnitude error between imaged stars and corresponding astometric catalog stars +#define MAGMATCHTOL 0.75 // Relative magnitude between matching stars tolerance +#define DEFMATCHVALRATIO 0.35 // Default ratio of imaged stars that must fit into astrometric catalog after applying matching transformation (can be adjusted at runtime) #define AUTOMAGLIM 1 // Automatically set astrometric catalog magnitude limit -#define DEBUG 1 +#define DEBUG 0 struct star { double ra,de; From 65434c14eb136dd0150165a6bc03cc869a1cf452 Mon Sep 17 00:00:00 2001 From: fmederos Date: Mon, 16 Oct 2017 02:47:48 -0300 Subject: [PATCH 40/53] Increased max observations in schedule --- runsched.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runsched.c b/runsched.c index 5841366..63ded4e 100644 --- a/runsched.c +++ b/runsched.c @@ -16,7 +16,7 @@ #define MAXPORT 7274 #define IP "127.0.0.1" #define LIM 2048 -#define NMAX 128 +#define NMAX 256 #define SCHEDULED 0 #define STARTED 1 From a1a46fe0701ab352f45a0c3717ba8c38e04e800c Mon Sep 17 00:00:00 2001 From: fmederos Date: Mon, 16 Oct 2017 02:48:45 -0300 Subject: [PATCH 41/53] Correct long-listings deletion was buggy --- scripts/st_compress.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/st_compress.sh b/scripts/st_compress.sh index ebe8d1f..9b8e748 100755 --- a/scripts/st_compress.sh +++ b/scripts/st_compress.sh @@ -53,6 +53,8 @@ while true; do cp $ST_OBSDIR/control/position.txt . # cp $ST_OBSDIR/control/scale.txt . cp $ST_OBSDIR/control/camera.txt . + # Register time offset against NTP server + ntpdate -q uy.pool.ntp.org > ntpresult.txt & export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'` # Remove old captured frames echo "Removing all captured frames" From 2cae263bf94e7c66a20815e8bf100ba215694c07 Mon Sep 17 00:00:00 2001 From: fmederos Date: Mon, 16 Oct 2017 02:49:56 -0300 Subject: [PATCH 42/53] Add magnitude limit to addwcs invocation --- scripts/st_process_offline.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/st_process_offline.sh b/scripts/st_process_offline.sh index ffd7abf..a9fcc8b 100755 --- a/scripts/st_process_offline.sh +++ b/scripts/st_process_offline.sh @@ -7,7 +7,12 @@ for file in 2*.fits; do mv test.cat $file.cat # Run addwcs - addwcs -f $file -r test.fits + if [ -z $1 ]; then + addwcs -f $file -r test.fits + else + echo "Limiting magnitude of star catalog to $1" + addwcs -f $file -r test.fits -m $1 + fi # Run satid satid $file $file.png/png 2>/dev/null @@ -15,3 +20,4 @@ for file in 2*.fits; do # Move calibrated file mv $file.cat $file.cal $file.id $file $file.png png/ done + From 198c974428ee9cfde87ebd620fdc3a48340bffd4 Mon Sep 17 00:00:00 2001 From: fmederos Date: Mon, 16 Oct 2017 02:50:52 -0300 Subject: [PATCH 43/53] St_catobs.sh script to help manage observations. --- scripts/st_catobs.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 scripts/st_catobs.sh diff --git a/scripts/st_catobs.sh b/scripts/st_catobs.sh new file mode 100755 index 0000000..7d6da8f --- /dev/null +++ b/scripts/st_catobs.sh @@ -0,0 +1,26 @@ +#!/bin/bash + + +# Check obsdir exists +if [ ! -d $ST_OBSDIR ]; then + mkdir $ST_OBSDIR +fi +if [ ! -d $ST_OBSDIR/control ]; then + mkdir $ST_OBSDIR/control +fi + +# look for observations in every subdir +# catenate each one to lastobs.txt in obsdir +find $ST_OBSDIR -iname 'observations.txt' | awk '{printf ("cat %s\n",$1)}' | sh > $ST_OBSDIR/lastobs.txt +# and rename each original obs files to *.txt.used +find $ST_OBSDIR -iname 'observations.txt' | awk '{printf ("mv %s %s.used\n",$1,$1)}' | sh + + +# catenate lastobs.txt to allobs.txt and count the new observations +cat $ST_OBSDIR/lastobs.txt >> $ST_OBSDIR/allobs.txt +# count total observations +NOBS=`cat $ST_OBSDIR/lastobs.txt | wc -l` +NALLOBS=`cat $ST_OBSDIR/allobs.txt | wc -l` + +echo "$NOBS new observations in lastobs.txt, total observations in allobs.txt: $NALLOBS" + From 18f77e2c2f089cf5ca8688a3d47b4809228cecf1 Mon Sep 17 00:00:00 2001 From: fmederos Date: Mon, 16 Oct 2017 02:51:36 -0300 Subject: [PATCH 44/53] St_process_bulk.sh to process a whole night of observations. --- scripts/st_process_bulk.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 scripts/st_process_bulk.sh diff --git a/scripts/st_process_bulk.sh b/scripts/st_process_bulk.sh new file mode 100755 index 0000000..e690e68 --- /dev/null +++ b/scripts/st_process_bulk.sh @@ -0,0 +1,18 @@ +#./bin/bash + +# Loop into every directory +for obsdir in *; do + if [ -d $obsdir ]; then + echo $obsdir + cd $obsdir + # check if observation is not already processed + N=`ls -1 ./2*.fits 2>/dev/null | wc -l` + if [ $N -ge 1 ]; then + # process observation frames in directory + st_process_offline.sh $1 + fi + cd .. + fi +done + + From 9127f4fb1cdeb87d450f18b991fd5cb90e7a35c6 Mon Sep 17 00:00:00 2001 From: fmederos Date: Thu, 26 Oct 2017 19:11:17 -0300 Subject: [PATCH 45/53] Add start/stop report while scheduling observations --- skymap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skymap.c b/skymap.c index ba6de10..0f57fbf 100644 --- a/skymap.c +++ b/skymap.c @@ -872,8 +872,8 @@ void schedule(char *nfd,double ra,double de,char *startstop) dec2sex(ra/15.0,sra,0,5); dec2sex(de,sde,0,4); - printf("%s %s %s\n",nfd,sra,sde); - + printf("%s %s %s %s\n",nfd,sra,sde,startstop); + // Open file file=fopen("schedule.txt","a"); if (file==NULL) { From 47dcc272601819c9241490f047db7bb68ef29183 Mon Sep 17 00:00:00 2001 From: fmederos Date: Thu, 26 Oct 2017 19:12:01 -0300 Subject: [PATCH 46/53] Update orientation --- data/cameras.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/cameras.txt b/data/cameras.txt index 71f6ed9..85c12fd 100644 --- a/data/cameras.txt +++ b/data/cameras.txt @@ -1,6 +1,6 @@ # List of available cameras # Camera mnemonic (Camera/Optics), field width, field height, horiz resolution (neg.to mirror), vert resolution (neg.to mirror), mount type (AltAz/Eq/XY/Fixed), video device , Azimuth (for fixed, south is zero), Altitude (for fixed) -S25H 20.4 16.3 -720 576 Fix /dev/video-S25H 37 43 +S25H 16.3 20.4 -720 576 Fix /dev/video-S25H 37 43 W50H 7.21 5.31 -720 576 AltAz /dev/video1 W28H 13.10 7.97 D85V 9.97 14.96 From 5d5c5f58e96dea07451093ad920f526c246256d9 Mon Sep 17 00:00:00 2001 From: fmederos Date: Sat, 4 Nov 2017 02:25:56 -0300 Subject: [PATCH 47/53] Correct h/v pixel scale swap bug --- plotfits.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plotfits.c b/plotfits.c index 6002482..45de2c6 100644 --- a/plotfits.c +++ b/plotfits.c @@ -19,10 +19,10 @@ // This should change to arcseconds in the future and be used to widen // the astrometric catalog so that it's scale is grater than that of the imaged catalog just enough // to be sure it includes all imaged stars even at the worst pointing error. -#define MAXROT 10*D2R // Maximum expected rotation error (radians) +#define MAXROT 15*D2R // Maximum expected rotation error (radians) #define MAXSCALERR 1.05 // Expected image to astrometric map scaling error #define DISTMATCHTOL 6 // Distance tolerance in pixels between matching stars after aplying scale and rotation -#define MAXMAGERR 2.5 // Expected magnitude error between imaged stars and corresponding astometric catalog stars +#define MAXMAGERR 3 // Expected magnitude error between imaged stars and corresponding astometric catalog stars #define MAGMATCHTOL 0.75 // Relative magnitude between matching stars tolerance #define DEFMATCHVALRATIO 0.35 // Default ratio of imaged stars that must fit into astrometric catalog after applying matching transformation (can be adjusted at runtime) #define AUTOMAGLIM 1 // Automatically set astrometric catalog magnitude limit @@ -697,7 +697,7 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // ************************************************************************************************************ // At this point a viable candidate triangle is found to match the selected reference triangle // will try to validate this candidate by calculating the tranformation between the ref triangle and this candidate - // We will need to calculate scale, rotation and translation + // We will need to calculate scale, rotation and traslation end_t=clock(); #if DEBUG>1 @@ -758,7 +758,7 @@ void identify_triangles(struct catalog *cat, struct catalog *ast, int *nselect, // traslation calculation // we apply averaged matchscale and matchrotation to reference stars and then - // average reference 1 to match 1 vector, ref2 to match2 vector and ref3 to match3 vector + // average reference1 to match1 vector, ref2 to match2 vector and ref3 to match3 vector r=sqrt(pow(cat->x[s1],2)+pow(cat->y[s1],2)); d=atan(cat->y[s1] / cat->x[s1]); r *= matchscale; @@ -958,7 +958,7 @@ int main(int argc,char *argv[]) } else{ // Obtain FOV and image resolution from camera file - fscanf(file,"%s %f %f %d %d %s",cam,&fw,&fh,&nx,&ny,mount); + fscanf(file,"%s %f %f %d %d %s",cam,&fh,&fw,&nx,&ny,mount); fclose(file); sx=fw/nx*3600; sy=fh/ny*3600; @@ -1289,6 +1289,7 @@ int main(int argc,char *argv[]) printf("b Select star from catalog\n"); printf("i Autoselect calibration stars from catalog\n"); printf("I Reset calibration stars selection\n"); + printf("S Save calibration params. to cal.dat\n"); printf("c Center image on pixel\n"); printf("f Fit calibration\n"); printf("m Match stars using current calibration\n"); From f16fa1e9d4669a46a971f474df1507a27b2c92c3 Mon Sep 17 00:00:00 2001 From: Cees Bassa Date: Fri, 17 Nov 2017 22:12:20 +0100 Subject: [PATCH 48/53] Removed fixed pointing --- data/cameras.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/data/cameras.txt b/data/cameras.txt index 85c12fd..095afe4 100644 --- a/data/cameras.txt +++ b/data/cameras.txt @@ -1,6 +1,5 @@ # List of available cameras # Camera mnemonic (Camera/Optics), field width, field height, horiz resolution (neg.to mirror), vert resolution (neg.to mirror), mount type (AltAz/Eq/XY/Fixed), video device , Azimuth (for fixed, south is zero), Altitude (for fixed) -S25H 16.3 20.4 -720 576 Fix /dev/video-S25H 37 43 W50H 7.21 5.31 -720 576 AltAz /dev/video1 W28H 13.10 7.97 D85V 9.97 14.96 From fad96cd09703e8505774a05dd42574a14831d1dd Mon Sep 17 00:00:00 2001 From: Cees Bassa Date: Fri, 17 Nov 2017 22:13:05 +0100 Subject: [PATCH 49/53] Keep ffmpeg output --- scripts/st_capture.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/st_capture.sh b/scripts/st_capture.sh index fa57498..318dfb3 100755 --- a/scripts/st_capture.sh +++ b/scripts/st_capture.sh @@ -15,5 +15,5 @@ cd /dev/shm rm img*.pgm # Start capture -#ffmpeg -f video4linux2 -i $device -s 720x576 -r 25 img%06d.pgm -ffmpeg -f video4linux2 -i $device -s 720x576 -r 25 img%06d.pgm >/dev/null +ffmpeg -f video4linux2 -i $device -s 720x576 -r 25 img%06d.pgm + From 0ce570760230301b80a425e7b0d05a1410453ddb Mon Sep 17 00:00:00 2001 From: Cees Bassa Date: Fri, 17 Nov 2017 22:13:52 +0100 Subject: [PATCH 50/53] Split compression script into older version and an automatically relaunching one --- scripts/st_compress.sh | 152 +++++----------------------- scripts/st_compress_and_relaunch.sh | 144 ++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 124 deletions(-) mode change 100755 => 100644 scripts/st_compress.sh create mode 100755 scripts/st_compress_and_relaunch.sh diff --git a/scripts/st_compress.sh b/scripts/st_compress.sh old mode 100755 new mode 100644 index 9b8e748..f7f93ea --- a/scripts/st_compress.sh +++ b/scripts/st_compress.sh @@ -1,144 +1,48 @@ #!/bin/bash -source ~/.bashrc - # Settings PGMDIR=/dev/shm N=250 -# If no images are found during this period (seconds), relaunch capture process -WAIT=20 -COUNT=0 -# Start automatically capture process or not -AUTOSTART=0 -# Default camera to start imaging if no schedule is available -CAMERADEV="/dev/video0" -CAPTUREPID=0 - -# Check obsdir exists -if [ ! -d $ST_OBSDIR ]; then - mkdir $ST_OBSDIR -fi -if [ ! -d $ST_OBSDIR/control ]; then - mkdir $ST_OBSDIR/control -fi - - -# if autostart force a restart -if [ $AUTOSTART == 1 ]; then - echo "restart" >$ST_OBSDIR/control/state.txt - STATE="restart" -else - echo "stop" >$ST_OBSDIR/control/state.txt - STATE="stop" -fi - -export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'` - -echo "Status: "$STATE +# Force a restart +echo "restart" >$ST_OBSDIR/control/state.txt # For ever loop while true; do - + # Get number of files + NFILES=`ls -1 $PGMDIR/img*.pgm 2>/dev/null | wc -l` + + # If enough, process + if [ $NFILES -ge $N ]; then # Get state export STATE=`cat $ST_OBSDIR/control/state.txt` - + # Create new directory if [ $STATE == "restart" ]; then - export DIR=`date -u +%FT%T | sed -e "s/-//g" -e "s/\://g" -e "s|T|/|g"` - mkdir -p $ST_OBSDIR/$DIR - cd $ST_OBSDIR/$DIR - echo "Moving to $ST_OBSDIR/$DIR" - echo "observing" >$ST_OBSDIR/control/state.txt - cp $ST_OBSDIR/control/position.txt . - # cp $ST_OBSDIR/control/scale.txt . - cp $ST_OBSDIR/control/camera.txt . - # Register time offset against NTP server - ntpdate -q uy.pool.ntp.org > ntpresult.txt & - export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'` - # Remove old captured frames - echo "Removing all captured frames" - # ls -1 $PGMDIR/img*.pgm | awk '{printf("sudo rm -rf %s\n",$1)}' | sh - #ls -1 $PGMDIR/img*.pgm | awk '{printf("rm -rf %s\n",$1)}' | sh - find $PGMDIR -type f -name './img*.pgm' | awk '{printf("rm -rf %s\n",$1)}' | sh + export DIR=`date -u +%FT%T | sed -e "s/-//g" -e "s/\://g" -e "s|T|/|g"` + mkdir -p $ST_OBSDIR/$DIR + cd $ST_OBSDIR/$DIR + echo "Moving to $ST_OBSDIR/$DIR" + echo "observing" >$ST_OBSDIR/control/state.txt + cp $ST_OBSDIR/control/position.txt . + cp $ST_OBSDIR/control/camera.txt . fi - # kill capture process just when scheduler sends stop signal - if [ $STATE == "stop" ]; then - if [ $(($CAPTUREPID)) != 0 ]; then - echo "" - echo "Stopping capture process" - kill -9 $CAPTUREPID - CAPTUREPID=0 - fi - fi + # Start point + M=`ls -1 $PGMDIR/img*.pgm | head -n1 | sed -e "s/[^0-9]*//g"` - # Get number of captured frames - NFILES=`ls -1 $PGMDIR/img*.pgm 2>/dev/null | wc -l` - #NFILES=`find $PGMDIR -type f -name 'img*.pgm' |wc -l` - # If enough, process - if [ $NFILES -ge $N ]; then - COUNT=0 - echo "" - echo "Compressing $N captured frames" + # Run pgm2fits + pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N - # Start point - M=`ls -1 $PGMDIR/img*.pgm | head -n1 | sed -e "s/[^0-9]*//g"` + # Remove files + ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("rm -rf %s\n",$1)}' | sh - # Run pgm2fits -# pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N - pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N >/dev/null - - # Run viewer - viewer `ls -1 2*.fits | tail -n1` - cp avg.pgm $ST_OBSDIR - - # Remove files - echo "" - echo "Removing $N captured frames" -# ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("sudo rm -rf %s\n",$1)}' | sh - ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("rm -rf %s\n",$1)}' | sh - #find $PGMDIR -type f -name 'img*.pgm' | head -n$N | awk '{printf("rm -rf %s\n",$1)}' | sh - -# echo "Finished" - else - # There are not enough captured frames - # Launch capture process if state is not stop - # if time passes with still no images re-launch capture process - if [ $STATE != "stop" ]; then - echo "" - echo "Waiting for frames. Status: "$STATE - COUNT=$(($COUNT+1)) - if [ $COUNT -ge $WAIT ]; then - COUNT=0 - echo "" - echo "No frames found, restarting capture script" -# sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA & - sh $ST_DATADIR/scripts/st_capture.sh $CAMERADEV & - sleep 1 - CAPTUREPID=`pgrep -o -x ffmpeg` - fi - # if restarting then relaunch capture script now - if [ $STATE == "restart" ]; then - if [ $(($CAPTUREPID)) == 0 ]; then - echo "Restarting capture script" -# sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA & - sh $ST_DATADIR/scripts/st_capture.sh $CAMERADEV & - sleep 1 - CAPTUREPID=`pgrep -o -x ffmpeg` - COUNT=0 - fi - fi - else - # we are stopped, check for bogus capture process -# echo "Status: "$STATE - if [ $(($CAPTUREPID)) != 0 ]; then - echo "Stopping capture process" - kill -9 $CAPTUREPID - CAPTUREPID=0 - fi + # Run viewer + viewer `ls -1 2*.fits | tail -n1` + cp avg.pgm $ST_OBSDIR + echo "Finished" fi - fi - # Sleep - sleep 1 + + # Sleep + sleep 1 done diff --git a/scripts/st_compress_and_relaunch.sh b/scripts/st_compress_and_relaunch.sh new file mode 100755 index 0000000..2b51390 --- /dev/null +++ b/scripts/st_compress_and_relaunch.sh @@ -0,0 +1,144 @@ +#!/bin/bash + +source ~/.bashrc + +# Settings +PGMDIR=/dev/shm +N=250 +# If no images are found during this period (seconds), relaunch capture process +WAIT=20 +COUNT=0 +# Start automatically capture process or not +AUTOSTART=1 + +# Default camera to start imaging if no schedule is available +CAMERADEV="/dev/video1" +CAPTUREPID=0 + +# Check obsdir exists +if [ ! -d $ST_OBSDIR ]; then + mkdir $ST_OBSDIR +fi +if [ ! -d $ST_OBSDIR/control ]; then + mkdir $ST_OBSDIR/control +fi + + +# if autostart force a restart +if [ $AUTOSTART == 1 ]; then + echo "restart" >$ST_OBSDIR/control/state.txt + STATE="restart" +else + echo "stop" >$ST_OBSDIR/control/state.txt + STATE="stop" +fi + +export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'` + +echo "Status: "$STATE + +# For ever loop +while true; do + + # Get state + export STATE=`cat $ST_OBSDIR/control/state.txt` + + # Create new directory + if [ $STATE == "restart" ]; then + export DIR=`date -u +%FT%T | sed -e "s/-//g" -e "s/\://g" -e "s|T|/|g"` + mkdir -p $ST_OBSDIR/$DIR + cd $ST_OBSDIR/$DIR + echo "Moving to $ST_OBSDIR/$DIR" + echo "observing" >$ST_OBSDIR/control/state.txt + cp $ST_OBSDIR/control/position.txt . + # cp $ST_OBSDIR/control/scale.txt . + cp $ST_OBSDIR/control/camera.txt . + # Register time offset against NTP server + ntpdate -q uy.pool.ntp.org > ntpresult.txt & + export CAMERADEV=`cat $ST_OBSDIR/control/camera.txt | awk '{print $((7))}'` + # Remove old captured frames + echo "Removing all captured frames" + # ls -1 $PGMDIR/img*.pgm | awk '{printf("sudo rm -rf %s\n",$1)}' | sh + #ls -1 $PGMDIR/img*.pgm | awk '{printf("rm -rf %s\n",$1)}' | sh + find $PGMDIR -type f -name './img*.pgm' | awk '{printf("rm -rf %s\n",$1)}' | sh + fi + + # kill capture process just when scheduler sends stop signal + if [ $STATE == "stop" ]; then + if [ $(($CAPTUREPID)) != 0 ]; then + echo "" + echo "Stopping capture process" + kill -9 $CAPTUREPID + CAPTUREPID=0 + fi + fi + + # Get number of captured frames + NFILES=`ls -1 $PGMDIR/img*.pgm 2>/dev/null | wc -l` + #NFILES=`find $PGMDIR -type f -name 'img*.pgm' |wc -l` + # If enough, process + if [ $NFILES -ge $N ]; then + COUNT=0 + echo "" + echo "Compressing $N captured frames" + + # Start point + M=`ls -1 $PGMDIR/img*.pgm | head -n1 | sed -e "s/[^0-9]*//g"` + + # Run pgm2fits +# pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N + pgm2fits -p $PGMDIR/img -w 720 -h 576 -s $M -n $N >/dev/null + + # Run viewer + viewer `ls -1 2*.fits | tail -n1` + cp avg.pgm $ST_OBSDIR + + # Remove files + echo "" + echo "Removing $N captured frames" +# ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("sudo rm -rf %s\n",$1)}' | sh + ls -1 $PGMDIR/img*.pgm | head -n$N | awk '{printf("rm -rf %s\n",$1)}' | sh + #find $PGMDIR -type f -name 'img*.pgm' | head -n$N | awk '{printf("rm -rf %s\n",$1)}' | sh + +# echo "Finished" + else + # There are not enough captured frames + # Launch capture process if state is not stop + # if time passes with still no images re-launch capture process + if [ $STATE != "stop" ]; then + echo "" + echo "Waiting for frames. Status: "$STATE + COUNT=$(($COUNT+1)) + if [ $COUNT -ge $WAIT ]; then + COUNT=0 + echo "" + echo "No frames found, restarting capture script" +# sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA & + sh $ST_DATADIR/scripts/st_capture.sh $CAMERADEV & + sleep 1 + CAPTUREPID=`pgrep -o -x ffmpeg` + fi + # if restarting then relaunch capture script now + if [ $STATE == "restart" ]; then + if [ $(($CAPTUREPID)) == 0 ]; then + echo "Restarting capture script" +# sh $ST_DATADIR/scripts/st_capture.sh /dev/video-$CAMERA & + sh $ST_DATADIR/scripts/st_capture.sh $CAMERADEV & + sleep 1 + CAPTUREPID=`pgrep -o -x ffmpeg` + COUNT=0 + fi + fi + else + # we are stopped, check for bogus capture process +# echo "Status: "$STATE + if [ $(($CAPTUREPID)) != 0 ]; then + echo "Stopping capture process" + kill -9 $CAPTUREPID + CAPTUREPID=0 + fi + fi + fi + # Sleep + sleep 1 +done From 74f14dc95622a261c0977405a895cf2f443eb772 Mon Sep 17 00:00:00 2001 From: Cees Bassa Date: Fri, 17 Nov 2017 22:14:11 +0100 Subject: [PATCH 51/53] Patch for ffmpeg/libavcodec/pnmenc.c --- pnmenc.patch | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pnmenc.patch diff --git a/pnmenc.patch b/pnmenc.patch new file mode 100644 index 0000000..d6d4e38 --- /dev/null +++ b/pnmenc.patch @@ -0,0 +1,34 @@ +--- pnmenc.c 2015-10-23 19:20:02.000000000 +0200 ++++ good_pnmenc.c 2017-11-17 21:26:31.638503445 +0100 +@@ -23,6 +23,8 @@ + #include "libavutil/pixdesc.h" + #include "avcodec.h" + #include "internal.h" ++#include ++#include + + static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, + const AVFrame *p, int *got_packet) +@@ -32,7 +34,13 @@ + uint8_t *ptr, *ptr1, *ptr2; + int size = av_image_get_buffer_size(avctx->pix_fmt, + avctx->width, avctx->height, 1); ++ struct timeval tv; ++ char tbuf[30]; + ++ // Get time ++ gettimeofday(&tv,NULL); ++ strftime(tbuf,30,"%Y-%m-%dT%T",gmtime(&tv.tv_sec)); ++ + if ((ret = ff_alloc_packet2(avctx, pkt, size + 200, 0)) < 0) + return ret; + +@@ -81,7 +89,7 @@ + return -1; + } + snprintf(bytestream, bytestream_end - bytestream, +- "P%c\n%d %d\n", c, avctx->width, h1); ++ "P%c\n# %s.%03ld\n%d %d\n", c, tbuf, tv.tv_usec/1000, avctx->width, h1); + bytestream += strlen(bytestream); + if (avctx->pix_fmt != AV_PIX_FMT_MONOWHITE) { + int maxdepth = (1 << av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth) - 1; From 45d4caa6455ddd001b4e9db57cff417f40a94817 Mon Sep 17 00:00:00 2001 From: Cees Bassa Date: Fri, 17 Nov 2017 22:39:43 +0100 Subject: [PATCH 52/53] Rudimentary python implementation of capture and compress. --- python/capture.py | 75 +++++++++++++++++++++++++ python/compress.py | 135 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 python/capture.py create mode 100644 python/compress.py diff --git a/python/capture.py b/python/capture.py new file mode 100644 index 0000000..e641549 --- /dev/null +++ b/python/capture.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python + +import numpy as np +import cv2 +import time +import subprocess +import os + +# Make directory +if not os.path.exists("/dev/shm/video0"): + os.mkdir("/dev/shm/video0") + +# Get sunset and sunrise times (sattools allnight program) +tsolar=subprocess.check_output(['allnight']).replace("\n","").split(" ") + +# Convert to time structs +tset=time.strptime(tsolar[0]+" UTC", "%Y-%m-%dT%H:%M:%S %Z") +trise=time.strptime(tsolar[1]+" UTC", "%Y-%m-%dT%H:%M:%S %Z") +tnow=time.gmtime() +dtset=time.mktime(tset)-time.mktime(tnow) +dtrise=time.mktime(trise)-time.mktime(tnow) + +# Wait for sunset +#if dtset>0: +# print time.strftime("%FT%T",time.gmtime())+" waiting for sunset (%ds)"%dtset +# time.sleep(dtset) + +# Settings +device=cv2.VideoCapture(0) +device.set(3,720) +device.set(4,576) + +# Set counter +iframe=1 + +# Start capture +print time.strftime("%FT%T",time.gmtime())+" start capture" +while dtrise>0: + # Get frame + ret,frame=device.read() + + # Skip lost frames + if ret==True: + # Get time + t=float(time.time()) + + # Format time + nfd="%s.%03d"%(time.strftime("%Y-%m-%dT%T", time.gmtime(t)),int((t-np.floor(t))*1000)) + + # Get Size + ny,nx=frame.shape[0],frame.shape[1] + + # Convert image to grayscale + gray=np.asarray(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)).astype(np.int8) + + # Open output file + f=open("/dev/shm/video0/img%06d.pgm"%iframe,"w") + f.write("P5\n# %s\n%d %d\n255\n"%(nfd,nx,ny)) + f.write(gray) + f.close() + + # Log + if iframe%250==1: + print "%06d: %s %dx%d"%(iframe,nfd,nx,ny) + + # Increment + iframe+=1 + + # Refresh time + tnow=time.gmtime() + dtrise=time.mktime(trise)-time.mktime(tnow) + + +# End capture +print time.strftime("%FT%T",time.gmtime())+" end capture" diff --git a/python/compress.py b/python/compress.py new file mode 100644 index 0000000..1f8be92 --- /dev/null +++ b/python/compress.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python +import numpy as np +from astropy.time import Time +from astropy.io import fits +import time +import glob +import os + +def read_pgm(fname): + # Open file + f=open(fname,"r") + + # Read lines + line1=f.readline() + line2=f.readline() + line3=f.readline() + line4=f.readline() + + # Read parameters + nfd=line2.split(" ")[1] + nx,ny=int(line3.split(" ")[0]),int(line3.split(" ")[1]) + + # Read image + z=np.fromfile(f,dtype='uint8',count=nx*ny).astype('float32') + + # Close file + f.close() + + return z,nfd + +# Create fits file +def create_fits_file(nx,ny,nz,path,iframe): + # Allocate + z=np.empty(nz*ny*nx,dtype='float32').reshape(nz,nx*ny) + mjd=np.empty(nz,dtype='float64') + dt=np.empty(nz,dtype='float32') + + # Loop over frames + tstart=time.time() + for i in xrange(nz): + z[i],nfd=read_pgm(path+"/img%06d.pgm"%(iframe+i)) + + # Format time + t=Time(nfd,format='isot') + if i==0: + t0=t + mjd[i]=t.mjd + dt[i]=86400.0*(mjd[i]-mjd[0]) + print "Files read in %.3f s"%(time.time()-tstart) + + # Compute statistics + tstart=time.time() + zmax=np.max(z,axis=0) + znum=np.argmax(z,axis=0) + z1=np.sum(z,axis=0)-zmax + z2=np.sum(z*z,axis=0)-zmax*zmax + zavg=z1/float(nz-1) + zstd=np.sqrt((z2-z1*zavg)/float(nz-2)) + print "Statistics in %.3f s"%(time.time()-tstart) + + # Reshape, reformat and flip + tstart=time.time() + zmax=np.flipud(zmax.astype('float32').reshape(ny,nx)) + znum=np.flipud(znum.astype('float32').reshape(ny,nx)) + zavg=np.flipud(zavg.astype('float32').reshape(ny,nx)) + zstd=np.flipud(zstd.astype('float32').reshape(ny,nx)) + z=np.array([zavg,zstd,zmax,znum]) + print "Reshape in %.3f s"%(time.time()-tstart) + + # Filename + fname="%s.fits"%t0 + + # Format header + hdr=fits.Header() + hdr['DATE-OBS']="%s"%t0 + hdr['MJD-OBS']=t0.mjd + hdr['EXPTIME']=dt[-1]-dt[0] + hdr['NFRAMES']=nz + hdr['CRPIX1']=float(nx)/2.0 + hdr['CRPIX2']=float(ny)/2.0 + hdr['CRVAL1']=0.0 + hdr['CRVAL2']=0.0 + hdr['CD1_1']=1.0 + hdr['CD1_2']=0.0 + hdr['CD2_1']=0.0 + hdr['CD2_2']=1.0 + hdr['CTYPE1']="RA---TAN" + hdr['CTYPE2']="DEC--TAN" + hdr['CUNIT1']="deg" + hdr['CUNIT2']="deg" + hdr['CRRES1']=0.0 + hdr['CRRES2']=0.0 + hdr['EQUINIX']=2000.0 + hdr['RADECSYS']="ICRS" + hdr['COSPAR']=4171 + hdr['OBSERVER']="Cees Bassa" + for i in xrange(nz): + hdr['DT%04d'%i]=dt[i] + for i in xrange(10): + hdr['DUMY%03d'%i]=0.0 + + # Write fits file + hdu=fits.PrimaryHDU(data=z,header=hdr) + hdu.writeto(fname,clobber=True) + + return fname + +# Main function +if __name__ == '__main__': + # Settings + nx=720 + ny=576 + nz=250 + path="/dev/shm/video0" + + # Start forever loop + while True: + # Find files + files=sorted(glob.glob(path+"/img??????.pgm")) + + # Enough files + if len(files)>nz: + # Get first frame + iframe=int(files[0].replace(path+"/img","").replace(".pgm","")) + + tstart=time.time() + fname=create_fits_file(nx,ny,nz,path,iframe) + tend=time.time() + print "Created %s in %.2f"%(fname,tend-tstart) + + # Remove files + for i in xrange(nz): + os.remove(path+"/img%06d.pgm"%(iframe+i)) + else: + time.sleep(1) From ecd66a640c5dae77a81f8d8238a407bd68b3cca3 Mon Sep 17 00:00:00 2001 From: Cees Bassa Date: Sat, 18 Nov 2017 14:45:14 +0100 Subject: [PATCH 53/53] Fixed image size in reduce --- reduce.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reduce.c b/reduce.c index 1737890..4e87502 100644 --- a/reduce.c +++ b/reduce.c @@ -731,8 +731,8 @@ int main(int argc,char *argv[]) sprintf(obs.desig,"%02d%03.0lfA",year-2000,doy+500); cpgopen("/xs"); -// cpgpap(0.,1.0); - cpgpap(7,0.75); + cpgpap(0.,1.0); + //cpgpap(7,0.75); cpgask(0); cpgsch(0.8);