コード例 #1
0
/*******************************************************************
 * meta_get_timeSlantDop:
 * Converts a given line and sample in image into time, slant-range,
 * and doppler.  Works with all image types.*/
void meta_get_timeSlantDop(meta_parameters *meta,
  double yLine,double xSample,double *time,double *slant,double *dop)
{
  // No effort has been made to make this routine work with
  // pseudoprojected images.
  assert (meta->projection == NULL
    || meta->projection->type != LAT_LONG_PSEUDO_PROJECTION);

  if (meta->transform)
  {
    double lat,lon;
    meta_get_latLon(meta,yLine,xSample,0.0,&lat,&lon);
    latLon2timeSlant(meta,lat,lon,time,slant,dop);
  }
  // just for testing
  else if (meta->sar->image_type=='S'||meta->sar->image_type=='G')
  { /*Slant or ground range.  These are easy.*/
    *slant = meta_get_slant(meta,yLine,xSample);
    *time  = meta_get_time(meta,yLine,xSample);
    if (dop != NULL)
    {
      if (meta->sar->deskewed == 1)
        *dop=0.0;
      else
        *dop=meta_get_dop(meta,yLine,xSample);
    }
  } else if (meta->sar->image_type=='P' ||
           meta->sar->image_type=='R')
  {
    double lat,lon;
    meta_get_latLon(meta,yLine,xSample,0.0,&lat,&lon);
    latLon2timeSlant(meta,lat,lon,time,slant,dop);
  } else
  {  /*Bogus image type.*/
    printf("Error! Invalid image type '%c' passed to meta_get_timeSlantDop!\n",
      meta->sar->image_type);
    exit(1);
  }
}
コード例 #2
0
ファイル: image_stats.c プロジェクト: khogenso/ASF_MapReady
/* Main program */
int main(int argc, char *argv[])
{
  FILE *fpLook=NULL, *fpIncid=NULL, *fpRange=NULL, *fpIn=NULL, *fpMask=NULL;
  meta_parameters *meta;
  stateVector stVec;
  int ii, kk, ll;
  char inFile[255], metaFile[255], dataFile[255], outLook[255], outIncid[255];
  char outRange[255], outBase[255], outFile[255], *maskFile=NULL; 
  char cmd[255], *bufMask=NULL;
  float *bufImage=NULL, *bufLook=NULL, *bufIncid=NULL, *bufRange=NULL;
  double latitude, longitude, time, doppler, earth_radius=0, satellite_height, range;
  double look_angle, incidence_angle, height;
  double line, sample, re=6378144.0, rp=6356754.9, px, py;
  double firstLook=0.0, firstIncid=0.0, firstRange=0.0;
  flag_indices_t flags[NUM_FLAGS];

  /* Set all flags to 'not set' */
  for (ii=0; ii<NUM_FLAGS; ii++) {
    flags[ii] = FLAG_NOT_SET;
  }
  
/**********************BEGIN COMMAND LINE PARSING STUFF**********************/
  /* Check to see if any options were provided */
  if (checkForOption("-help", argc, argv) != -1) /* Most important */
    help_page();
  flags[f_LOOK] = checkForOption("-look", argc, argv);
  flags[f_INCIDENCE] = checkForOption("-incidence", argc, argv);
  flags[f_RANGE] = checkForOption("-range", argc, argv);
  flags[f_LINE] = checkForOption("-line", argc, argv);
  flags[f_SAMPLE] = checkForOption("-sample", argc, argv);
  flags[f_MIN] = checkForOption("-min", argc, argv);
  flags[f_MAX] = checkForOption("-max", argc, argv);
  flags[f_BINS] = checkForOption("-bins", argc, argv);
  flags[f_INTERVAL] = checkForOption("-interval", argc, argv);

  /* Make sure to set log & quiet flags (for use in our libraries) */
  logflag = (flags[f_LOG]!=FLAG_NOT_SET) ? TRUE : FALSE;
  quietflag = (flags[f_QUIET]!=FLAG_NOT_SET) ? TRUE : FALSE;

  { /* We need to make sure the user specified the proper number of arguments */
    int needed_args = 4;/*command & in_base & out_base */
    if (flags[f_MIN] != FLAG_NOT_SET) needed_args += 2; /* option & value */
    if (flags[f_MAX] != FLAG_NOT_SET) needed_args += 2; /* option & value */
    if (flags[f_BINS] != FLAG_NOT_SET) needed_args += 2; /* option & value */
    if (flags[f_INTERVAL] != FLAG_NOT_SET) needed_args += 2; /* option & value */

    /*Make sure we have enough arguments*/
    if (argc != needed_args)
      usage();/*This exits with a failure*/
  }

  /* We must be close to good enough at this point...start filling in fields 
     as needed */
  if (flags[f_MIN] != FLAG_NOT_SET)
    min = atof(argv[flags[f_MIN] + 1]);
  if (flags[f_MAX] != FLAG_NOT_SET)
    max = atof(argv[flags[f_MAX] + 1]);
  if (flags[f_BINS] != FLAG_NOT_SET)
    bins = atoi(argv[flags[f_BINS] + 1]);
  if (flags[f_INTERVAL] != FLAG_NOT_SET)
    interval = atof(argv[flags[f_INTERVAL] + 1]);

  if (flags[f_QUIET] == FLAG_NOT_SET)
    /* display splash screen if not quiet */
    print_splash_screen(argc, argv);
  if (flags[f_LOG] != FLAG_NOT_SET)
    strcpy(logFile, argv[flags[f_LOG] + 1]);
  else
    /* default behavior: log to tmp<pid>.log */
    sprintf(logFile, "tmp%i.log", (int)getpid());
  fLog = FOPEN(logFile, "a");

  /* Fetch required arguments */
  strcpy(inFile,argv[argc - 2]);
  strcpy(outBase,argv[argc - 1]);
/***********************END COMMAND LINE PARSING STUFF***********************/

  create_name(metaFile, inFile, ".meta");
  create_name(dataFile, inFile, ".img");
  
  /* Read metadata */
  meta = meta_read(inFile);
  lines = meta->general->line_count;
  samples = meta->general->sample_count;

  /* Set some values */
  doppler = 0.0;

  /* Determine what kind of image it is */
  if (meta->sar->image_type=='P') {
    if (meta->projection->type==SCANSAR_PROJECTION)
      printf("   Detected ScanSAR ");
  }
  else if (meta->sar->image_type=='S')
    printf("   Detected slant range ");
  else if (meta->sar->image_type=='G')
    printf("   Detected ground range ");
/*
  switch (meta->general->image_data_type) 
    {
    case AMPLITUDE_IMAGE: 
      printf("amplitude image ...\n");
      break;
    case SIGMA_IMAGE:
      printf("sigma image ...\n");
      break;
    case GAMMA_IMAGE:
      printf("gamma image ...\n");
      break;
    case BETA_IMAGE:
      printf("beta image ...\n");
      break;
    case RAW_IMAGE:
    case COMPLEX_IMAGE:
    case PHASE_IMAGE:
    case POWER_IMAGE:
    case COHERENCE_IMAGE:
    case GEOREFERENCED_IMAGE:
    case GEOCODED_IMAGE:
    case POLARIMETRIC_IMAGE:
    case LUT_IMAGE:
    case ELEVATION:
    case DEM:
    case IMAGE:
    case MASK:
      break;
    }
*/
  /* Create a mask file for background fill - required only for ScanSAR */
  if (meta->sar->image_type=='P') {
    if (meta->projection->type==SCANSAR_PROJECTION) {
      fpIn = fopenImage(inFile, "rb");
      bufImage = (float *) MALLOC(samples * sizeof(float));
      printf("   Generating mask file ...\n");
      maskFile = (char *) MALLOC(255*sizeof(char));
      sprintf(maskFile, "tmp%i.mask", (int)getpid());
      fpMask = fopenImage(maskFile, "wb");
      bufMask = (unsigned char *) MALLOC(samples * sizeof(char));
      for (ii=0; ii<lines; ii++) {
	get_float_line(fpIn, meta, ii, bufImage);
	for (kk=0; kk<samples; kk++) {
	  if (bufImage[kk]>0.0)
	    bufMask[kk] = 1;
	  else
	    bufMask[kk] = 0;
	}      
	ASF_FWRITE(bufMask, sizeof(char), samples, fpMask);
      }
      FCLOSE(fpMask);
      FREE(bufMask);
      FCLOSE(fpIn);
      FREE(bufImage);
    }
  }

  /* Create grid for least square approach */
  printf("   Initialization ...\n");
  if (flags[f_LOOK] != FLAG_NOT_SET) {
    sprintf(outLook, "tmp%i.look", (int)getpid());
    fpLook = FOPEN(outLook, "w");
  }
  if (flags[f_INCIDENCE] != FLAG_NOT_SET) {
    sprintf(outIncid, "tmp%i.incid", (int)getpid());
    fpIncid = FOPEN(outIncid, "w");
  }
  if (flags[f_RANGE] != FLAG_NOT_SET) {
    sprintf(outRange, "tmp%i.range", (int)getpid());
    fpRange = FOPEN(outRange, "w");
  }

  if (flags[f_LOOK] != FLAG_NOT_SET || flags[f_INCIDENCE] != FLAG_NOT_SET ||
      flags[f_RANGE] != FLAG_NOT_SET) {
    for (ll=0; ll<=RES_X; ll++)
      for (kk=0; kk<=RES_Y; kk++) {
	line = ll * lines / RES_Y;
	sample = kk * samples / RES_X;
	
	if (meta->sar->image_type=='P') {
	  px = meta->projection->startX + meta->projection->perX * sample;
	  py = meta->projection->startY + meta->projection->perY * line;
	  proj_to_latlon(meta->projection, px, py, 0.0,
		     &latitude, &longitude, &height);
	  latLon2timeSlant(meta, latitude, longitude, &time, &range, &doppler);
	}
	else
	  time = meta_get_time(meta, line, sample);
	
	stVec = meta_get_stVec(meta, time);
	if (meta->sar->image_type=='P') {
	  if (meta->projection->type==SCANSAR_PROJECTION) 
	    earth_radius = meta->projection->param.atct.rlocal;
	  else
	    asfPrintError("Unable to determine earth radius.\n");
	}
	else
	  earth_radius = my_get_earth_radius(time, stVec, re, rp);
	satellite_height = my_get_satellite_height(time, stVec);
	range = my_get_slant_range(meta, earth_radius, satellite_height, line, sample);
	look_angle = my_get_look_angle(earth_radius, satellite_height, range);
	incidence_angle = my_get_incidence_angle(earth_radius, satellite_height, range);
	
	if (ll==0 && kk==0) {
	  firstLook = look_angle * R2D;
	  firstIncid = incidence_angle * R2D;
	  firstRange = range;
	}
	
	if (flags[f_LOOK] != FLAG_NOT_SET)
	  fprintf(fpLook, "%.18f %.12f %.12f\n", (float)look_angle*R2D, 
		  line, sample);
	if (flags[f_INCIDENCE] != FLAG_NOT_SET)
	  fprintf(fpIncid, "%.18f %.12f %.12f\n", (float)incidence_angle*R2D, 
		  line, sample);
	if (flags[f_RANGE] != FLAG_NOT_SET) 
	  fprintf(fpRange, "%.18f %.12f %.12f\n", (float)range, line, sample);
      }
  }
  
  /* Close files for now */
  if (flags[f_LOOK] != FLAG_NOT_SET) {
    FCLOSE(fpLook);
    FREE(bufLook);
  }
  if (flags[f_INCIDENCE] != FLAG_NOT_SET) {
    FCLOSE(fpIncid);
    FREE(bufIncid);
  }
  if (flags[f_RANGE] != FLAG_NOT_SET) {
    FCLOSE(fpRange);
    FREE(bufRange);
  }
  
  /* Calculate plots */
  if (flags[f_LOOK] != FLAG_NOT_SET) {
    create_name(outFile, outBase, "_look.plot");
    calculate_plot("Look angle", outLook, dataFile, maskFile, outFile, 
		   meta, firstLook);
  }
  if (flags[f_INCIDENCE] != FLAG_NOT_SET) {
    create_name(outFile, outBase, "_incid.plot");
    calculate_plot("Incidence angle", outIncid, dataFile, maskFile, outFile, 
		   meta, firstIncid);
  }
  if (flags[f_RANGE] != FLAG_NOT_SET) {
    create_name(outFile, outBase, "_range.plot");
    calculate_plot("Range", outRange, dataFile, maskFile, outFile, 
		   meta, firstRange);
  }
  if (flags[f_LINE] != FLAG_NOT_SET) {
    create_name(outFile, outBase, "_line.plot");
    calculate_plot("Line", NULL, dataFile, maskFile, outFile, 
		   meta, 0.0);
  }
  if (flags[f_SAMPLE] != FLAG_NOT_SET) {
    create_name(outFile, outBase, "_sample.plot");
    calculate_plot("Sample", NULL, dataFile, maskFile, outFile, 
		   meta, 0.0);
  }
  
  /* Clean up */
  sprintf(cmd, "rm -rf tmp*");
  system(cmd);
  
  exit(0);
}