Exemple #1
0
/* Input file is stdin if fname==NULL */
int
read_radec(OBSERVATION obsarray[], char *fname, int *nobs)
{
  FILE *fptr;
  OBSERVATION  *obs;
  int  i;
  char	inbuff[256];
  double jd,ra,dec,elat,elon;

  if (fname==NULL)
    fptr = stdin;
  else if ( (fptr=fopen(fname,"r"))==NULL) {
    fprintf(stderr,"Error opening observations file %s\n",fname);
    exit(1);
  }

  *nobs=0;
  while ( fgets_nocomment(inbuff,255,fptr,NULL)!=NULL) {
    if ( scan_observation(inbuff, &(obsarray[*nobs]))) {
      fprintf(stderr,"Quitting on format error\n");
      exit(1);
    }

    obs = &(obsarray[*nobs]);
    (*nobs)++;

    eq_to_ec(obs->thetax,obs->thetay,&elat,&elon,NULL);

    if (*nobs==1) {
      double xec, yec, zec;
      /* Use first observation to set the reference frame */
      jd0 = obs->obstime;
      lat0 = elat;
      lon0 = elon;
      
      /* Find location of SSBARY wrt observatory at zero time */
      earth_ssbary(jd0, obs->obscode, &xBary, &yBary, &zBary);

      /* Negate the vector to make it earth->SSBARY*/
      /* And rotate equatorial into the tangent-point coords */
      xBary *= -1.;  yBary *= -1.;  zBary *= -1.;
      xyz_eq_to_ec(xBary, yBary, zBary, &xec, &yec, &zec,NULL);
      xyz_ec_to_proj(xec, yec, zec, &xBary, &yBary, &zBary, lat0, lon0, NULL);
    }

    /* Set time to years after jd0, rotate to tangent plane coords */
    obs->obstime = (obs->obstime-jd0)*DAY;
    ec_to_proj(elat,elon,&(obs->thetax),&(obs->thetay),
	       lat0,lon0,NULL);
    /* Calculate the position of Earth at this time to avoid doing
     * it many times later: */
    earth3d(obs->obstime, obs->obscode,
	    &(obs->xe),&(obs->ye),&(obs->ze));
		
  }
  if (fname!=NULL) fclose(fptr);
  return(0);
}
Exemple #2
0
/* Input file is stdin if fname==NULL */
int
read_radec(OBSERVATION obsarray[], char *fname, int *nobs)
{
  FILE *fptr;
  OBSERVATION  *obs;
  int  scan_status_flag;
  int  i;
  char	inbuff[256];
  double jd,ra,dec,elat,elon;

  if (fname==NULL)
    fptr = stdin;
  else if ( (fptr=fopen(fname,"r"))==NULL) {
    fprintf(stderr,"Error opening observations file %s\n",fname);
    exit(1);
  }

  *nobs=0;
  while ( fgets_nocomment(inbuff,255,fptr,NULL)!=NULL) {

    // obs refers to the previous observation, after the first loop.
    scan_status_flag = scan_observation(inbuff, &(obsarray[*nobs]), obs);

    // scanned line was 2nd line of two line format so don't advance nobs as all we did was reset the observer x/y
    if (scan_status_flag == -1) {
      mpc3d(obs->obstime, &(obs->xe), &(obs->ye), &(obs->ze));
      continue;
    }

    // all other non-zero status values indicate an error.
    if ( scan_status_flag == 1) {
      fprintf(stderr,"Quitting on format error\n");
      exit(1);
    }

    obs = &(obsarray[*nobs]);
    (*nobs)++;

    eq_to_ec(obs->thetax,obs->thetay,&elat,&elon,NULL);


    if (*nobs==1) {
      double xec, yec, zec;
      /* Use first observation to set the reference frame */
      jd0 = obs->obstime;
      lat0 = elat;
      lon0 = elon;


      /* fprintf(stderr, "%f %f %f %d\n", elat, elon, obs->obstime, obs->obscode); */

      /* Find location of SSBARY wrt observatory at zero time */
      earth_ssbary(jd0, obs->obscode, &xBary, &yBary, &zBary);

      /* fprintf(stderr, "%f %f %f %d\n", elat, elon, obs->obstime, obs->obscode); */

      /* Negate the vector to make it earth->SSBARY*/
      /* And rotate equatorial into the tangent-point coords */
      xBary *= -1.;  yBary *= -1.;  zBary *= -1.;
      xyz_eq_to_ec(xBary, yBary, zBary, &xec, &yec, &zec,NULL);
      xyz_ec_to_proj(xec, yec, zec, &xBary, &yBary, &zBary, lat0, lon0, NULL);
    }
    /* fprintf(stderr,"%f %f", lat0, lon0); */
    /* Set time to years after jd0, rotate to tangent plane coords */
    obs->obstime = (obs->obstime-jd0)*DAY;
    ec_to_proj(elat,elon,&(obs->thetax),&(obs->thetay),
	       lat0,lon0,NULL);
    /* Calculate the position of Earth at this time to avoid doing
     * it many times later: */
    if (scan_status_flag == -2) {
      mpc3d(obs->obstime, &(obs->xe), &(obs->ye), &(obs->ze));
    } else {
      earth3d(obs->obstime, obs->obscode,
              &(obs->xe), &(obs->ye), &(obs->ze));
    }
  }
  if (fname!=NULL) fclose(fptr);
  return(0);
}
Exemple #3
0
int
main(int argc, char *argv[])
{
  PBASIS ptrue, pfit, ptry;
  OBSERVATION	futobs, obsarray[MAXOBS], *obs;
  int nobs;
  double tt;

  ORBIT  orbit;
  XVBASIS xv;

  double **covar, **covar_aei, **covar_xyz;
  double chisq;
  int dof;

  char	inbuff[256];
  double **sigxy,a,b,PA,**derivs;
  double lat,lon,**covecl;
  double ra,dec, **coveq;
  double xx,yy,xy,bovasqrd,det;
  double now, threshold, timestart, timespan, timeend;
  double besttime, bestvara, elong;
  int i, refit;

  if (argc!=4 || *argv[1]=='^') print_help();


  /* echo the command line to output */
  printf("#");
  for (i=0; i<argc; i++) printf(" %s",argv[i]);
  {
#include <time.h>
    time_t timettt;
    time(&timettt);
    /* note that ctime returns string with newline at end */
    printf("\n#---%s",ctime(&timettt));
  }

  sigxy = dmatrix(1,2,1,2);
  derivs = dmatrix(1,6,1,6);
  covar = dmatrix(1,6,1,6);
  covar_xyz = dmatrix(1,6,1,6);
  covar_aei = dmatrix(1,6,1,6);
  covecl = dmatrix(1,2,1,2);
  coveq = dmatrix(1,2,1,2);

  if (read_abg(argv[1],&ptrue,covar)) {
    fprintf(stderr, "Error input alpha/beta/gamma file %s\n",argv[1]);
    exit(1);
  }

  if ((threshold = atof(argv[2]))<=0.) {
    fprintf(stderr,"Bad observation threshold %s\n",argv[2]);
    print_help();
  }

  if ((timespan = atof(argv[3]))<=0.) {
    fprintf(stderr,"Bad time span %s\n",argv[3]);
    print_help();
  }

  /* Read in the initial observation times */
  nobs = 0;
  while (fgets_nocomment(inbuff, 255, stdin, stdout)!=NULL) {
    obs = &(obsarray[nobs]);
    if (scan_observation(inbuff, obs)) exit(1);
    /* Set time to years after jd0, don't care about coordinates here*/
    obs->obstime = (obs->obstime-jd0)*DAY;
    if (nobs==0) timestart = obs->obstime;
    /* Calculate the position of Earth at this time to avoid doing
     * it many times later: */
    earth3d(obs->obstime, obs->obscode,
	    &(obs->xe),&(obs->ye),&(obs->ze));
    /* replace with faked position */
    fake_observation(&ptrue, obs);
    print_radec(obs,stdout);
    printf("Reobserve time %.4f opp. angle %.2f\n", obs->obstime-timestart,
	   opposition_angle(obs)/DTOR);
    nobs++;
  }

  /* Get an orbit fit*/
  fit_observations(obsarray, nobs, &pfit, covar, &chisq, &dof, NULL);

  /*Save site and error limits to use in future */
  obsarray[nobs].obscode = obsarray[nobs-1].obscode;
  obsarray[nobs].dthetax = obsarray[nobs-1].dthetax;
  obsarray[nobs].dthetay = obsarray[nobs-1].dthetay;

  timeend = timestart + timespan;
  bestvara = 1e10;
  besttime = 0.;

  for (now = obsarray[nobs-1].obstime; now <= timeend;  ) {

    /*Advance observing time */
    if ( now-timestart < 2*MONTH) now+= DAY;
    else now+=MONTH;

    /*Get position and x uncertainty*/
    /* Predict position & examine uncertainty */
    obsarray[nobs].obstime = now;
    obsarray[nobs].xe = -999.;		/* Force evaluation of earth3d */

    predict_posn(&pfit,covar,&obsarray[nobs],sigxy);


    /* Compute a, b, theta of error ellipse for output */
    xx = sigxy[1][1];
    yy = sigxy[2][2];
    xy = sigxy[1][2];
    PA = 0.5 * atan2(2.*xy,(xx-yy)) * 180./PI;	/*go right to degrees*/
    /* Adjust for PA to be N through E, */
    PA = PA-90;
    if (PA<-90.) PA += 180.;
    bovasqrd  = (xx+yy-sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) 
      / (xx+yy+sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) ;
    det = xx*yy-xy*xy;
    b = pow(det*bovasqrd,0.25);
    a = pow(det/bovasqrd,0.25);

    /* See what uncertainty in a results from this obs.*/
    fit_observations(obsarray, nobs+1, &ptry, covar_aei, &chisq, &dof, NULL);

    pbasis_to_bary(&ptry, &xv, derivs);
    covar_map(covar_aei, derivs, covar_xyz,6,6);
    orbitElements(&xv, &orbit);
    aei_derivs(&xv, derivs);
    covar_map(covar_xyz, derivs, covar_aei,6,6);
    
    /* Report results of this test to output */
    printf("%7.4f %.2f %.2f %.2f %9.6f %.3g %5.1f  %5.1f %d\n", now-timestart,
	   obsarray[nobs].thetax/ARCSEC, obsarray[nobs].thetay/ARCSEC,
	   a/ARCSEC, sqrt(covar_aei[1][1]), sqrt(covar_aei[2][2]),
	   elong/DTOR, opposition_angle(&obsarray[nobs])/DTOR, nobs);
    
    /* Go to next date if Sun is too close */
    elong = elongation(&obsarray[nobs]);
    if (elong < MIN_ELONG) continue;

    if (a > threshold*ARCSEC) {
      /* object is lost.  See what prior observation was best
       * for constraining a, then add it and refit orbit, continue
       */
      if (besttime<=0) {
	fprintf(stderr,"Object is lost before observation\n");
	exit(1);
      }
      obsarray[nobs].obstime = besttime;
      obsarray[nobs].xe = -999.;
      fake_observation(&ptrue, &obsarray[nobs]);
      printf("Reobserve time %.4f opp. angle %.2f\n", besttime-timestart,
	    opposition_angle(&obsarray[nobs])/DTOR);
      print_radec(&obsarray[nobs],stdout);
      nobs++;
      fit_observations(obsarray, nobs, &pfit, covar, &chisq, &dof, NULL);
      now = besttime;
      besttime = 0.;
      bestvara = 1e10;
      obsarray[nobs].obscode = obsarray[nobs-1].obscode;
      obsarray[nobs].dthetax = obsarray[nobs-1].dthetax;
      obsarray[nobs].dthetay = obsarray[nobs-1].dthetay;
    } else {

      /* Is this the best observation so far? */
      if (covar_aei[1][1] < bestvara) {
	bestvara = covar_aei[1][1];
	besttime = now;
      }
    }
  }

  /*Do a final observation*/
  obsarray[nobs].obstime = besttime;
  obsarray[nobs].xe = -999.;
  fake_observation(&ptrue, &obsarray[nobs]);
  printf("Reobserve time %.4f opp. angle %.2f\n", besttime-timestart,
	 opposition_angle(&obsarray[nobs])/DTOR);
  print_radec(&obsarray[nobs],stdout);
  nobs++;
  fit_observations(obsarray, nobs, &pfit, covar_aei, &chisq, &dof, NULL);

  pbasis_to_bary(&pfit, &xv, derivs);
  covar_map(covar_aei, derivs, covar_xyz,6,6);
  orbitElements(&xv, &orbit);
  aei_derivs(&xv, derivs);
  covar_map(covar_xyz, derivs, covar_aei,6,6);
  printf("Final uncertainty in a: %.3g\n",
	 sqrt(covar_aei[1][1]));

   
  free_dmatrix(covar,1,6,1,6);
  free_dmatrix(covar_xyz,1,6,1,6);
  free_dmatrix(covar_aei,1,6,1,6);
  free_dmatrix(derivs,1,6,1,6);
  exit(0);
}
Exemple #4
0
int
main(int argc, char *argv[])
{
  PBASIS p;
  OBSERVATION	futobs, obs;
  struct date_time dt;
  char	inbuff[256],rastring[20],decstring[20];
  double **covar,**sigxy,a,b,PA,**derivs;
  double lat,lon,**covecl;
  double ra,dec, **coveq;
  double dx, dy, chisq, elat, elon;
  double xx,yy,xy,bovasqrd,det;
  int i,nfields;

  int iarg=1;
  if (argc>1 && *argv[1]=='^') print_help();
  if (read_options(&iarg, argc, argv)) print_help();
  if (argc-iarg!=1) print_help();
  

  /* echo the command line to output */
  printf("#");
  for (i=0; i<argc; i++) printf(" %s",argv[i]);
  {
#include <time.h>
    time_t timettt;
    time(&timettt);
    /* note that ctime returns string with newline at end */
    printf("\n#---%s",ctime(&timettt));
  }

  sigxy = dmatrix(1,2,1,2);
  derivs = dmatrix(1,2,1,2);
  covar = dmatrix(1,6,1,6);
  covecl = dmatrix(1,2,1,2);
  coveq = dmatrix(1,2,1,2);

  if (read_abg(argv[iarg],&p,covar)) {
    fprintf(stderr, "Error input alpha/beta/gamma file %s\n",argv[iarg]);
    exit(1);
  }

  while (fgets_nocomment(inbuff, 255, stdin, stdout)!=NULL) {
    if (scan_observation(inbuff, &obs)) exit(1);
    /* Set time to years after jd0, rotate to tangent plane coords */
    obs.obstime = (obs.obstime-jd0)*DAY;
    eq_to_ec(obs.thetax,obs.thetay,&elat,&elon,NULL);
    ec_to_proj(elat,elon,&(obs.thetax),&(obs.thetay),
	       lat0,lon0,NULL);
    /* Calculate the position of Earth at this time to avoid doing
     * it many times later: */
    earth3d(obs.obstime, obs.obscode,
	    &(obs.xe),&(obs.ye),&(obs.ze));

    futobs.obstime = obs.obstime;
    futobs.obscode = obs.obscode;
    futobs.xe = -999.;

    predict_posn(&p,covar,&futobs,sigxy);

    /* Errors: */
    dx = obs.thetax - futobs.thetax;
    dy = obs.thetay - futobs.thetay;
    /* Add observational errors into the uncertainty */
    sigxy[1][1] += pow(obs.dthetax,2.);
    sigxy[2][2] += pow(obs.dthetay,2.);
   
    chisq = dx*dx*sigxy[2][2] -2.*dx*dy*sigxy[1][2] + dy*dy*sigxy[1][1];
    chisq /= sigxy[1][1]*sigxy[2][2] - sigxy[1][2]*sigxy[2][1];

    /* Compute a, b, theta of error ellipse for output */
    xx = sigxy[1][1];
    yy = sigxy[2][2];
    xy = sigxy[1][2];
    PA = 0.5 * atan2(2.*xy,(xx-yy)) * 180./PI;	/*go right to degrees*/
    /* Adjust for PA to be N through E, */
    PA = PA-90;
    if (PA<-90.) PA += 180.;
    bovasqrd  = (xx+yy-sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) 
      / (xx+yy+sqrt(pow(xx-yy,2.)+pow(2.*xy,2.))) ;
    det = xx*yy-xy*xy;
    b = pow(det*bovasqrd,0.25);
    a = pow(det/bovasqrd,0.25);

    printf("%7.4f %9.2f %9.2f %8.3f %8.3f %8.2f %8.2f %7.2f %.2f\n",
	   futobs.obstime, futobs.thetax/ARCSEC, futobs.thetay/ARCSEC,
	   dx/ARCSEC, dy/ARCSEC,
	   a/ARCSEC,b/ARCSEC,PA, chisq
); 

  }
  exit(0);
}