예제 #1
0
void get_params(char *file,struct ARDOP_PARAMS *g,meta_parameters **meta_out)
{
  meta_parameters *meta;
  struct VFDRECV asf_facdr1;
  struct IOF_VFDR ifiledr;
  struct dataset_sum_rec dssr1;
  
  /* First, we set the hardcoded parameters: */
  g->rhww = 0.8;             /* Range Spectrum Weight - a little    */
  g->nlooks = 5;             /* Produces square pixels (5 X 1 look) */
  g->wavl = 0.0565646;       /* SAR wavelength, in meters.          */
  g->slope = 4.1913749E+11;  /* Chirp Frequency slope (Hz/Sec)      */
  g->azres = 8.0;            /* ERS-1 azimuth resolution, in meters */
  
  /* Get .meta metadata parameters */
  meta=meta_create(file);
  
  /* Read CEOS structures */
  get_asf_facdr(file,&asf_facdr1);
  get_ifiledr(file,&ifiledr);
  get_dssr(file,&dssr1);
  
  /* Extract parameters of interest from CEOS metadata */
  g->nla      = ifiledr.datgroup;                /* number of range bins*/
  g->re       = asf_facdr1.eradcntr*1000.0;      /* Radius of the Earth */
  g->ht       = asf_facdr1.scalt*1000.0;         /* Spacecraft Altitude */
  g->r00      = asf_facdr1.sltrngfp*1000.0;      /* Slant Range 1st Pix */
  g->prf      = asf_facdr1.prfreq;               /* Pulse Rep. Frequency*/
  g->fs       = dssr1.rng_samp_rate * 1000000.0; /* Range sampling rate */
  g->pulsedur = dssr1.rng_length / 1000000.0;    /* Beam pulse length   */
  g->wavl     = dssr1.wave_length;               /* Beam wavength       */
  
  /*Finally, add the computed parameters:*/
  
  /*Compute the spacecraft height from the state vector.*/
  g->ht=vecMagnitude(meta->state_vectors->vecs[0].vec.pos)-g->re;
  
  /*Magnitude of s/c orbital velocity (m/sec)*/
  g->vel=vecMagnitude(meta->state_vectors->vecs[0].vec.vel);
  
  g->nla-=g->pulsedur*g->fs;/*Subtract the (wasted) pulse length samples*/
  
  *meta_out=meta;
  
  return;
}
예제 #2
0
void create_cal_params(const char *inSAR, meta_parameters *meta, 
		       report_level_t level)
{
  int ii, kk;
  struct dataset_sum_rec dssr; // Data set summary record
  double *noise;
  char sarName[512], *facilityStr, *processorStr, *error;
  ceos_description *ceos; 
  meta->calibration = meta_calibration_init();

  strcpy (sarName, inSAR);

  if (isCEOS(sarName, &error)) {
    // Check for the various processors
    get_dssr(sarName, &dssr);
    facilityStr = trim_spaces(dssr.fac_id);
    processorStr = trim_spaces(dssr.sys_id);
    
    ceos = get_ceos_description_ext(inSAR, REPORT_LEVEL_NONE, FALSE);

    if (strncmp(facilityStr , "ASF"  , 3) == 0 &&
	strncmp(processorStr, "FOCUS", 5) != 0 &&
	((meta->projection && meta->projection->type == SCANSAR_PROJECTION) ||
	 (meta->projection &&
	  (strcmp_case(meta->general->mode, "SWA") == 0 || 
	   strcmp_case(meta->general->mode, "SWB") == 0))
	 )
	) {
      // ASF internal processor (PP or SSP), ScanSar data
      asf_scansar_cal_params *asf = MALLOC(sizeof(asf_scansar_cal_params));
      meta->calibration->type = asf_scansar_cal;
      meta->calibration->asf_scansar = asf;
      
      // Get values for calibration coefficients and LUT
      struct VRADDR rdr; // Radiometric data record
      get_raddr(sarName, &rdr);
      
      // hardcodings for not-yet-calibrated fields
      if (rdr.a[0] == -99.0 || rdr.a[1]==0.0 ) {
	asf->a0 = 1.1E4;
	asf->a1 = 2.2E-5;
	asf->a2 = 0.0;
      }
      else {
	asf->a0 = rdr.a[0];
	asf->a1 = rdr.a[1];
	asf->a2 = rdr.a[2];
      }
      
      // Set the Noise Correction Vector to correct version
      if (strncmp(dssr.cal_params_file,"SSPSWB010.CALPARMS",18)==0) {
	asfPrintStatus("\n   Substituting hardcoded noise vector sspswb010\n");
	noise = sspswb010_noise_vec;
      }
      else if (strncmp(dssr.cal_params_file,"SSPSWB011.CALPARMS",18)==0) {
	asfPrintStatus("\n   Substituting hardcoded noise vector sspswb011\n");
	noise = sspswb011_noise_vec;
      }
      else if (strncmp(dssr.cal_params_file,"SSPSWB013.CALPARMS",18)==0) {
	asfPrintStatus("\n   Substituting hardcoded noise vector sspswb013\n");
	noise = sspswb013_noise_vec;
      }
      else if (strncmp(dssr.cal_params_file,"SSPSWB014.CALPARMS",18)==0) {
	asfPrintStatus("\n   Substituting hardcoded noise vector sspswb014\n");
	noise = sspswb014_noise_vec;
      }
      else if (strncmp(dssr.cal_params_file,"SSPSWB015.CALPARMS",18)==0) {
	asfPrintStatus("\n   Substituting hardcoded noise vector sspswb015\n");
	noise = sspswb015_noise_vec;
      }
      else if (strncmp(dssr.cal_params_file,"SSPSWB016.CALPARMS",18)==0) {
	asfPrintStatus("\n   Substituting hardcoded noise vector sspswb016\n");
	noise = sspswb015_noise_vec;
	// 16 and 15 were identical antenna patterns, only metadata fields were
	// changed, so the noise vector for 16 is the same and that for 15. JBN
      }
      else
	noise = rdr.noise;
      
      for (kk=0; kk<256; ++kk)
	asf->noise[kk] = noise[kk];
      
    }
    else if (strncmp(facilityStr, "ASF", 3)== 0 &&
	     strncmp(processorStr, "FOCUS", 5) != 0) {
      // ASF internal processor (PP or SSP) (non-Scansar)
      asf_cal_params *asf = (asf_cal_params *) MALLOC(sizeof(asf_cal_params));
      meta->calibration->type = asf_cal;
      meta->calibration->asf = asf;
      
      // Get values for calibration coefficients and LUT
      struct VRADDR rdr; // Radiometric data record
      get_raddr(sarName, &rdr);
      
      // hardcodings for not-yet-calibrated fields
      if (rdr.a[0] == -99.0 || rdr.a[1]==0.0 ) {
	asf->a0 = 1.1E4;
	asf->a1 = 2.2E-5;
	asf->a2 = 0.0;
      }
      else {
	asf->a0 = rdr.a[0];
	asf->a1 = rdr.a[1];
	asf->a2 = rdr.a[2];
      }
      
      if (ceos->product == SLC && ceos->sensor == ERS &&
	  meta->general->radiometry > r_AMP &&
	  meta->general->radiometry < r_POWER) {
	asfPrintStatus("Applying calibration adjustment of x1.3 for SLC data."
		       "\n");
	asf->a1 *= 1.3;
      }
      
      // grab the noise vector
      for (kk=0; kk<256; ++kk)
	asf->noise[kk] = rdr.noise[kk];
      asf->sample_count = meta->general->sample_count;
    }
    else if ((strncmp(facilityStr, "ASF", 3) == 0 &&
	      strncmp(dssr.sys_id, "FOCUS", 5) == 0) ||
	     (strncmp(facilityStr, "CDPF", 4) == 0 ||
	      strncmp(facilityStr, "RSI", 3) == 0 ||
	      ((strncmp(facilityStr, "CSTARS", 6) == 0 ||
		strncmp(facilityStr, "TRNS", 4) == 0) &&
	       strncmp(dssr.mission_id, "RSAT", 4) == 0))) {
      // Radarsat style calibration
      rsat_cal_params *rsat =
	(rsat_cal_params *) MALLOC(sizeof(rsat_cal_params));
      meta->calibration->type = rsat_cal;
      meta->calibration->rsat = rsat;
      rsat->slc = FALSE;
      rsat->focus = FALSE;
      if (strncmp(dssr.product_type, "SLANT RANGE COMPLEX", 19) == 0 ||
	  strncmp(dssr.product_type,
		  "SPECIAL PRODUCT(SINGL-LOOK COMP)", 32) == 0) {
	rsat->slc = TRUE;
      }
      if (strncmp(dssr.sys_id, "FOCUS", 5) == 0)
	rsat->focus = TRUE;
      
      // Read lookup up table from radiometric data record
      struct RSI_VRADDR radr;
      get_rsi_raddr(sarName, &radr);
      rsat->n = radr.n_samp;
      //rsat->lut = (double *) MALLOC(sizeof(double) * rsat->n);
      for (ii=0; ii<rsat->n; ii++) {
	if (strncmp(dssr.sys_id, "FOCUS", 5) == 0)
	  rsat->lut[ii] = radr.lookup_tab[0];
	else
	  rsat->lut[ii] = radr.lookup_tab[ii];
      }
      rsat->samp_inc = radr.samp_inc;
      rsat->a3 = radr.offset;
      
    }
    else if (strncmp(facilityStr, "ES", 2)      == 0 ||
	     strncmp(facilityStr, "D-PAF", 5)   == 0 ||
	     strncmp(facilityStr, "I-PAF", 2)   == 0 ||
	     strncmp(facilityStr, "Beijing", 7) == 0 ||
	     (strncmp(facilityStr, "CSTARS", 6) == 0 &&
	      (strncmp(dssr.mission_id, "E", 1) == 0 ||
	       strncmp(dssr.mission_id, "J", 1) == 0))
	     ) {
      // ESA style calibration
      esa_cal_params *esa = (esa_cal_params *) MALLOC(sizeof(esa_cal_params));
      meta->calibration->type = esa_cal;
      meta->calibration->esa = esa;
      
      // Read calibration coefficient and reference incidence angle
      struct ESA_FACDR facdr;
      get_esa_facdr(sarName, &facdr);
      esa->k = facdr.abs_cal_const;
      esa->ref_incid = dssr.incident_ang;
    }
    else if (strncmp(facilityStr, "EOC", 3) == 0) {
      // ALOS processor
      struct alos_rad_data_rec ardr; // ALOS Radiometric Data record
      alos_cal_params *alos =
	(alos_cal_params *) MALLOC(sizeof(alos_cal_params));
      meta->calibration->type = alos_cal;
      meta->calibration->alos = alos;
      
      // Determine beam mode
      int beam = dssr.ant_beam_num;
      int beam_count = dssr.nchn;
      if (beam >= 0 && beam <= 35 && beam_count == 2)
	beam += 36; // actually dual-pol data (HH+HV or VV+VH)
      else if (beam == 3 && beam_count == 4)
	beam = 127; // actually PLR 21.5
      else if (beam_count == 1 && dssr.product_id[3] == 'S') {
	// some fine backwards engineering here to figure out the correct beam
	// number - off nadir angle and processing bandwidth required
	// don't care for the HH versus VV at the moment
	if (dssr.off_nadir_angle < 25.0) {
	  if (dssr.bnd_rng < 20000.0)
	    beam = 72; // WB1 HH3scan
	  else
	    beam = 73; // WB2 HH3scan
	}
	else if (dssr.off_nadir_angle > 25.0 && dssr.off_nadir_angle < 26.0) {
	  if (dssr.off_nadir_angle < 25.0) {
	    if (dssr.bnd_rng < 20000.0)
	      beam = 76; // WB1 HH4scan
	    else
	      beam = 77; // WB2 HH4scan
	  }
	}
	else {
	  if (dssr.bnd_rng < 20000.0)
	    beam = 80; // WB1 HH5scan
	  else
	    beam = 81; // WB2 HH5scan
	}
      }
      
      // Reading calibration coefficient
      get_ardr(sarName, &ardr);
      if (strncmp(dssr.lev_code, "1.1", 3) == 0) { // SLC
	// HH polarization
	if ((beam >=   0 && beam <=  17) || // FBS HH polarization
	    (beam >=  36 && beam <=  53) || // FBD HH+HV polarization
	    (beam >=  72 && beam <=  73) || // WB  HH3scan
	    (beam >=  76 && beam <=  77) || // WB  HH4scan
	    (beam >=  80 && beam <=  81) || // WB  HH5scan
	    (beam >=  84 && beam <= 101) || // DSN HH polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_hh = ardr.calibration_factor - 32;
	else
	  alos->cf_hh = MAGIC_UNSET_DOUBLE;
	// HV polarization
	if ((beam >=  36 && beam <=  53) || // FBD HH+HV polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_hv = ardr.calibration_factor - 32;
	else
	  alos->cf_hv = MAGIC_UNSET_DOUBLE;
	// VH polarization
	if ((beam >=  54 && beam <=  71) || // FBD VV+VH polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_vh = ardr.calibration_factor - 32;
	else
	  alos->cf_vh = MAGIC_UNSET_DOUBLE;
	// VV polarization
	if ((beam >=  18 && beam <=  35) || // FBS VV polarization
	    (beam >=  54 && beam <=  71) || // FBD VV+VH polarization
	    (beam >=  74 && beam <=  75) || // WB  VV3scan
	    (beam >=  78 && beam <=  79) || // WB  VV4scan
	    (beam >=  82 && beam <=  83) || // WB  VV5scan
	    (beam >= 102 && beam <= 119) || // DSN VV polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_vv = ardr.calibration_factor - 32;
	else
	  alos->cf_vv = MAGIC_UNSET_DOUBLE;
      }
      else if (strncmp(dssr.lev_code, "1.5", 3) == 0) { // regular detected
	// HH polarization
	if ((beam >=   0 && beam <=  17) || // FBS HH polarization
	    (beam >=  36 && beam <=  53) || // FBD HH+HV polarization
	    (beam >=  72 && beam <=  73) || // WB  HH3scan
	    (beam >=  76 && beam <=  77) || // WB  HH4scan
	    (beam >=  80 && beam <=  81) || // WB  HH5scan
	    (beam >=  84 && beam <= 101) || // DSN HH polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_hh = ardr.calibration_factor;
	else
	  alos->cf_hh = MAGIC_UNSET_DOUBLE;
	// HV polarization
	if ((beam >=  36 && beam <=  53) || // FBD HH+HV polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_hv = ardr.calibration_factor;
	else
	  alos->cf_hv = MAGIC_UNSET_DOUBLE;
	// VH polarization
	if ((beam >=  54 && beam <=  71) || // FBD VV+VH polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_vh = ardr.calibration_factor;
	else
	  alos->cf_vh = MAGIC_UNSET_DOUBLE;
	// VV polarization
	if ((beam >=  18 && beam <=  35) || // FBS VV polarization
	    (beam >=  54 && beam <=  71) || // FBD VV+VH polarization
	    (beam >=  74 && beam <=  75) || // WB  VV3scan
	    (beam >=  78 && beam <=  79) || // WB  VV4scan
	    (beam >=  82 && beam <=  83) || // WB  VV5scan
	    (beam >= 102 && beam <= 119) || // DSN VV polarization
	    (beam >= 120 && beam <= 131))   // PLR
	  alos->cf_vv = ardr.calibration_factor;
	else
	  alos->cf_vv = MAGIC_UNSET_DOUBLE;
      }
      
      // Check on processor version
      // Prior to processor version 9.02 some calibration parameters have been
      // determined again.
      double version;
      if (!get_alos_processor_version(inSAR, &version))
	asfReport(level, "Could not find workreport file!\n"
		  "Calibration parameters applied to the data might be "
		  "inaccurate!\n");
      else if (version < 9.02) {
	char str[512];
	
	switch (beam)
	  {
	  case 0: 
	    alos->cf_hh = -83.16; // FBS  9.9 HH
	    sprintf(str, "HH: %.2lf\n", alos->cf_hh);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0)
	      alos->cf_hh -= 32;
	    break;
	  case 3:
	    alos->cf_hh = -83.55; // FBS 21.5 HH
	    sprintf(str, "HH: %.2lf\n", alos->cf_hh);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0)
	      alos->cf_hh -= 32;
	    break;
	  case 7:
	    alos->cf_hh = -83.40; // FBS 34.3 HH
	    sprintf(str, "HH: %.2lf\n", alos->cf_hh);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0)
	      alos->cf_hh -= 32;
	    break;
	  case 10:
	    alos->cf_hh = -83.65; // FBS 41.5 HH
	    sprintf(str, "HH: %.2lf\n", alos->cf_hh);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0)
	      alos->cf_hh -= 32;
	    break;
	  case 35:
	    alos->cf_hh = -83.30; // FBS 50.8 HH
	    sprintf(str, "HH: %.2lf\n", alos->cf_hh);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0)
	      alos->cf_hh -= 32;
	    break;
	  case 43:
	    alos->cf_hh = -83.20; // FBD 34.3 HH
	    alos->cf_hv = -80.20; // FBD 34.3 HV
	    sprintf(str, "HH: %.2lf\nHV: %.2lf\n", alos->cf_hh, alos->cf_hv);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0) {
	      alos->cf_hh -= 32;
	      alos->cf_hv -= 32;
	    }
	    break;
	  case 46:
	    alos->cf_hh = -83.19; // FBD 41.5 HH
	    alos->cf_hv = -80.19; // FBD 41.5 HV
	    sprintf(str, "HH: %.2lf\nHV: %.2lf\n", alos->cf_hh, alos->cf_hv);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0) {
	      alos->cf_hh -= 32;
	      alos->cf_hv -= 32;
	    }
	    break;
	  case 127:
	    alos->cf_hh = -83.40; // PLR 21.5 HH
	    alos->cf_hv = -83.40; // PLR 21.5 HV
	    alos->cf_vh = -83.40; // PLR 21.5 VH
	    alos->cf_vv = -83.40; // PLR 21.5 VV
	    sprintf(str, "HH: %.2lf\nHV: %.2lf\nVH: %.2lf\nVV: %.2lf", 
		    alos->cf_hh, alos->cf_hv, alos->cf_vh, alos->cf_vv);
	    recalibration(str, level);
	    if (strncmp(dssr.lev_code, "1.1", 3) == 0) {
	      alos->cf_hh -= 32;
	      alos->cf_hv -= 32;
	      alos->cf_vh -= 32;
	      alos->cf_vv -= 32;
	    }
	    break;
	  }
      }
    }
  }
  else if (isTerrasar(sarName, &error)) {
    // TSX style calibration
    tsx_cal_params *tsx = (tsx_cal_params *) MALLOC(sizeof(tsx_cal_params));
    meta->calibration->type = tsx_cal;
    meta->calibration->tsx = tsx;

    terrasar_meta *terrasar = read_terrasar_meta(sarName);
    tsx->k = terrasar->cal_factor; // calibration factor in beta naught
    FREE(terrasar);
  }
  else
    // should never get here
    asfPrintWarning("Unknown calibration parameter scheme!\n");

}
예제 #3
0
// Main program body.
int
main (int argc, char *argv[])
{
  char *leader_file_list, *output_file, file[255];
  struct dataset_sum_rec *dssr;
  struct att_data_rec *atdr;
  struct VFDRECV *facdr;
  int currArg = 1;
  int NUM_ARGS = 2;

  // process log/quiet/license/etc options
  handle_common_asf_args(&argc, &argv, ASF_NAME_STRING);
  asfSplashScreen(argc, argv);

  if (argc<=1)
    usage(ASF_NAME_STRING);
  else if (strmatches(argv[1],"-help","--help",NULL))
    print_help();
  else if (argc<=2)
    usage(ASF_NAME_STRING);
  
  while (currArg < (argc-NUM_ARGS)) {
    char *key = argv[currArg++];
    if (strmatches(key,"-help","--help",NULL)) {
      print_help(); // doesn't return
    }
    else {
      --currArg;
      break;
    }
  }
  if ((argc-currArg) < NUM_ARGS) {
    printf("Insufficient arguments.\n");
    usage(argv[0]);
  } else if ((argc-currArg) > NUM_ARGS) {
    printf("Unknown argument: %s\n", argv[currArg]);
    usage(argv[0]);
  }
  
  leader_file_list = argv[currArg];
  output_file = argv[currArg+1];

  // Read granule information
  FILE *fpIn = FOPEN(leader_file_list, "r");
  FILE *fpOut = FOPEN(output_file, "w");
  fprintf(fpOut, "Leader_file, Yaw, Doppler_range, Doppler_azimuth\n");
  dssr = (struct dataset_sum_rec *) MALLOC(sizeof(struct dataset_sum_rec));
  atdr = (struct att_data_rec *) MALLOC(sizeof(struct att_data_rec));
  facdr = (struct VFDRECV *) MALLOC(sizeof(struct VFDRECV));
  double yaw;
  while (fgets(file, 1024, fpIn)) {
    file[strlen(file)-1] = '\0';
    if (get_dssr(file, dssr) < 0) {
      asfPrintWarning("Leader file (%s) does not contain data set summary"
		      " record\n", file);
      continue;
    }
    if (get_atdr(file, atdr) < 0) {
      asfPrintWarning("Leader file (%s) does not contain attitude data record",
		      "\n", file);
      continue;
    }
    if (get_asf_facdr(file, facdr) < 0) {
      asfPrintWarning("Leader file (%s) does not contain facility related data"
		      " record\n", file);
      continue;
    }
    yaw = facdr->scyaw;
    if (FLOAT_EQUIVALENT(yaw, 0.0))
      yaw = atdr->data->yaw;
    fprintf(fpOut, "%s, %.4lf, %.3lf, %.3lf\n", 
	    file, yaw, dssr->crt_dopcen[0], dssr->alt_dopcen[0]);
  }
  FCLOSE(fpIn);
  FCLOSE(fpOut);
  FREE(dssr);
  FREE(atdr);
  FREE(facdr);
  
  asfPrintStatus("Done.\n");
  return EXIT_SUCCESS;
}