1
0
Fork 0

Misc changes

pull/2/head
Cees Bassa 2013-10-23 16:41:01 +02:00
parent 7023cff1cc
commit 687d27c0cb
5 changed files with 102 additions and 51 deletions

View File

@ -6,13 +6,13 @@
struct image {
char filename[64];
int naxis1,naxis2,nframes;
float *zavg,*zstd,*zmax,*znum;
int naxis1,naxis2;
float *zavg;
double ra0,de0;
float x0,y0;
float a[3],b[3],xrms,yrms;
double mjd;
float *dt,exptime;
float exptime;
char nfd[32];
int cospar;
};
@ -29,10 +29,10 @@ int main(int argc,char *argv[])
// Compute statistics
for (i=0,zavg=0.0;i<img.naxis1*img.naxis2;i++)
zavg+=img.zmax[i];
zavg+=img.zavg[i];
zavg/=(float) img.naxis1*img.naxis2;
for (i=0,zstd=0.0;i<img.naxis1*img.naxis2;i++)
zstd+=pow(img.zmax[i]-zavg,2);
zstd+=pow(img.zavg[i]-zavg,2);
zstd=sqrt(zstd/(float) (img.naxis1*img.naxis2));
// Image scale
@ -54,11 +54,13 @@ struct image read_fits(char *filename)
char key[FITS_LINESZ+1];
char val[FITS_LINESZ+1];
struct image img;
int naxis;
// Copy filename
strcpy(img.filename,filename);
// Image size
naxis=atoi(qfits_query_hdr(filename,"NAXIS"));
img.naxis1=atoi(qfits_query_hdr(filename,"NAXIS1"));
img.naxis2=atoi(qfits_query_hdr(filename,"NAXIS2"));
@ -84,22 +86,9 @@ struct image read_fits(char *filename)
img.b[2]=3600.0*atof(qfits_query_hdr(filename,"CD2_2"));
img.xrms=3600.0*atof(qfits_query_hdr(filename,"CRRES1"));
img.yrms=3600.0*atof(qfits_query_hdr(filename,"CRRES2"));
img.nframes=atoi(qfits_query_hdr(filename,"NFRAMES"));
// Timestamps
img.dt=(float *) malloc(sizeof(float)*img.nframes);
for (i=0;i<img.nframes;i++) {
sprintf(key,"DT%04d",i);
strcpy(val,qfits_query_hdr(filename,key));
sscanf(val+1,"%f",&img.dt[i]);
// img.dt[i]=atof(qfits_query_hdr(filename,key));
}
// Allocate image memory
img.zavg=(float *) malloc(sizeof(float)*img.naxis1*img.naxis2);
img.zstd=(float *) malloc(sizeof(float)*img.naxis1*img.naxis2);
img.zmax=(float *) malloc(sizeof(float)*img.naxis1*img.naxis2);
img.znum=(float *) malloc(sizeof(float)*img.naxis1*img.naxis2);
// Set parameters
ql.xtnum=0;
@ -107,26 +96,24 @@ struct image read_fits(char *filename)
ql.filename=filename;
// Loop over planes
for (k=0;k<4;k++) {
ql.pnum=k;;
// Initialize load
if (qfitsloader_init(&ql) != 0)
printf("Error initializing data loading\n");
// Test load
if (qfits_loadpix(&ql) != 0)
printf("Error loading actual data\n");
// Fill z array
for (i=0,l=0;i<img.naxis1;i++) {
for (j=0;j<img.naxis2;j++) {
if (k==0) img.zavg[l]=ql.fbuf[l];
if (k==1) img.zstd[l]=ql.fbuf[l];
if (k==2) img.zmax[l]=ql.fbuf[l];
if (k==3) img.znum[l]=ql.fbuf[l];
l++;
}
if (naxis==3)
ql.pnum=2;
else
ql.pnum=0;
// Initialize load
if (qfitsloader_init(&ql) != 0)
printf("Error initializing data loading\n");
// Test load
if (qfits_loadpix(&ql) != 0)
printf("Error loading actual data\n");
// Fill z array
for (i=0,l=0;i<img.naxis1;i++) {
for (j=0;j<img.naxis2;j++) {
img.zavg[l]=ql.fbuf[l];
l++;
}
}

View File

@ -13,6 +13,7 @@ struct image {
struct image read_jpg(char *filename);
void write_jpg(char *filename,struct image img);
int main(int argc,char *argv[])
{
int i,j,flag,n;

View File

@ -391,6 +391,53 @@ void reduce_point(struct observation *obs,struct image img,float tmid,float x,fl
return;
}
struct image maximum_image(struct image *raw,int n)
{
int i,j,k,l;
float max,s1,s2;
struct image img;
printf("%d\n",n);
img.naxis1=raw[0].naxis1;
img.naxis2=raw[0].naxis2;
img.z=(float *) malloc(sizeof(float) * img.naxis1*img.naxis2);
for (i=0;i<img.naxis1*img.naxis2;i++) {
for (j=0,max=0.0;j<n;j++)
if (raw[j].z[i]>max)
max=raw[j].z[i];
img.z[i]=max;
}
// Get levels
for (i=0,s1=0.0,s2=0.0;i<img.naxis1*img.naxis2;i++)
s1+=img.z[i];
img.avg=s1/(float) (img.naxis1*img.naxis2);
for (i=0,s1=0.0,s2=0.0;i<img.naxis1*img.naxis2;i++)
s2+=pow(img.z[i]-img.avg,2);
img.std=sqrt(s2/(float) (img.naxis1*img.naxis2-1));
img.zmin=img.avg-4.0*img.std;
img.zmax=img.avg+12.0*img.std;
// Fake
strcpy(img.filename,"fake");
img.mjd=56000.0;
strcpy(img.nfd," 2013-01-01T00:00:00.000");
img.cospar=0;
img.exptime=0.0;
img.ra0=0.0;
img.de0=0.0;
img.x0=0.0;
img.y0=0.0;
for (i=0;i<3;i++) {
img.a[i]=0.0;
img.b[i]=0.0;
}
img.xrms=0.0;
img.yrms=0.0;
return img;
}
int main(int argc,char *argv[])
{
int i,iimg=0,nimg;
@ -419,14 +466,15 @@ int main(int argc,char *argv[])
env=getenv("ST_DATADIR");
// Number of images
nimg=argc-1;
nimg=argc;
// Allocate
img=(struct image *) malloc(sizeof(struct image)*nimg);
// Read image
for (i=0;i<nimg;i++)
for (i=0;i<nimg-1;i++)
img[i]=read_fits(argv[i+1],0);
img[nimg-1]=maximum_image(img,nimg-1);
// Set image aspect
fx=0.5;
@ -505,8 +553,15 @@ int main(int argc,char *argv[])
}
if (plotobj==1) {
sprintf(idfile,"%s.id",img[iimg].filename);
plot_objects(idfile);
if (iimg<nimg-2) {
sprintf(idfile,"%s.id",img[iimg].filename);
plot_objects(idfile);
} else if (iimg==nimg-1) {
for (i=0;i<nimg-1;i++) {
sprintf(idfile,"%s.id",img[i].filename);
plot_objects(idfile);
}
}
}
format_iod_line(&obs);
@ -573,7 +628,7 @@ int main(int argc,char *argv[])
// Cycle through images
if (c==']') {
iimg++;
if (iimg>=nimg)
if (iimg>=nimg-1)
iimg=0;
redraw=1;
continue;
@ -583,7 +638,14 @@ int main(int argc,char *argv[])
if (c=='[') {
iimg--;
if (iimg<0)
iimg=nimg-1;
iimg=nimg-2;
redraw=1;
continue;
}
// Maximum image
if (c=='o') {
iimg=nimg-1;
redraw=1;
continue;
}
@ -593,13 +655,13 @@ int main(int argc,char *argv[])
printf("%d %d\n",ix,iy);
// Set area
width=1000;
width=500;
x=width*(ix+0.5);
y=width*(iy+0.5);
xmin=x-fx*width;
xmax=x+fx*width;
ymin=y-fy*width;
ymax=y+fy*width;
xmin=x-1.5*fx*width;
xmax=x+1.5*fx*width;
ymin=y-1.5*fy*width;
ymax=y+1.5*fy*width;
// Increment
ix++;

View File

@ -8,7 +8,7 @@
#include "cel.h"
#include "sgdp4h.h"
#define LIM 128
#define LIM 384
#define NMAX 256
#define MMAX 1024
#define D2R M_PI/180.0
@ -1285,6 +1285,7 @@ void skymap_plotstars(char *filename)
struct star s;
if (strstr(filename,"tycho2.dat")!=NULL) {
file=fopen(m.starfile,"rb");
while (!feof(file)) {
fread(&s,sizeof(struct star),1,file);

View File

@ -10,7 +10,7 @@
#define LIM 256
#define D2R M_PI/180.0
#define R2D 180.0/M_PI
#define NMAX 1024
#define NMAX 2048
struct catalog {
int n;