Пример #1
0
void ceos_init_alos_stVec(const char *fName, ceos_description *ceos, 
			  meta_parameters *meta)
{
  struct pos_data_rec ppdr;

  // Read platform position record
  get_ppdr(fName,&ppdr);

  // Initialize state vector
  int vector_count=3;
  double data_int = meta->sar->original_line_count / 2
    * fabs(meta->sar->azimuth_time_per_pixel);
  while (fabs(data_int) > 15.0) {
    data_int /= 2;
    vector_count = vector_count*2-1;
  }
  meta->state_vectors = meta_state_vectors_init(vector_count);
  meta->state_vectors->vector_count = vector_count;

  // Determine image start time
  ymd_date imgDate;
  julian_date imgJD;
  hms_time imgTime;
  date_dssr2date(ceos->dssr.inp_sctim, &imgDate, &imgTime);
  date_ymd2jd(&imgDate, &imgJD);
  double imgSec = date2sec(&imgJD, &imgTime);
  imgSec -= ceos->dssr.sc_lin*fabs(meta->sar->azimuth_time_per_pixel);
  
  sec2date(imgSec, &imgJD, &imgTime);
  meta->state_vectors->year   = (int) imgJD.year;
  meta->state_vectors->julDay = (int) imgJD.jd;
  meta->state_vectors->second = date_hms2sec(&imgTime);

  // Assign position and velocity for center of image
  int n = (vector_count - 1)/2;
  double timeStart = get_timeDelta(ceos, &ppdr, meta);
  double time = timeStart + n*data_int;
  stateVector st;
  st.pos.x = ppdr.orbit_ele[0];
  st.pos.y = ppdr.orbit_ele[1];
  st.pos.z = ppdr.orbit_ele[2];
  st.vel.x = ppdr.orbit_ele[3];
  st.vel.y = ppdr.orbit_ele[4];
  st.vel.z = ppdr.orbit_ele[5];
  meta->state_vectors->vecs[n].vec = st;
  meta->state_vectors->vecs[n].time = time - timeStart;

  int ii;
  double newTime;
  for (ii=0; ii<n; ii++) {
    newTime = time - (n - ii)*data_int;
    meta->state_vectors->vecs[ii].time = newTime - timeStart;
    meta->state_vectors->vecs[ii].vec = propagate(st, time, newTime);
  }
  for (ii=n+1; ii<vector_count; ii++) {
    newTime = time + (vector_count - n - 1)*data_int;
    meta->state_vectors->vecs[ii].time = newTime - timeStart;
    meta->state_vectors->vecs[ii].vec = propagate(st, time, newTime);
  }
}
Пример #2
0
/*
   Compute the average ymd_date date and hms_time time
  -----------------------------------------------------*/
void average_ymdTimes(ymd_date *date1, ymd_date *date2,
                      hms_time *time1, hms_time *time2,
                      ymd_date *ave_date, hms_time *ave_time)
{
    double secs1, secs2, ave_secs;
    julian_date jd_1, jd_2, ave_jd;

    date_ymd2jd(date1, &jd_1); // Julian date contains year and day number within that year
    date_ymd2jd(date2, &jd_2);

    secs1 = date2sec(&jd_1, time1); // Seconds from midnight, Jan 1, 1900 to julian date plus seconds into that day
    secs2 = date2sec(&jd_2, time2);
    ave_secs = (secs1 + secs2) / 2.0;

    sec2date(ave_secs, &ave_jd, ave_time);
    date_jd2ymd(&ave_jd, ave_date);
}
Пример #3
0
/***************************************************************
 * Get_timeDelta:
 * Return the time difference, in seconds, between the start
 * of the state vectors (in the PPDR) and the start of the image
 * (as described in the DSSR).  Write this time to the given
 * meta_parameters->state_vectors structure.*/
double get_timeDelta(ceos_description *ceos,struct pos_data_rec *ppdr,meta_parameters *meta)
{
    ymd_date imgDate;
    julian_date imgJD,stJD;
    hms_time imgTime,stTime;
    double imgSec,stSec;/*Seconds since 1900 for start of image and start of state vectors*/

/*Read time of *start* of state vectors*/
    stJD.year = (int) ppdr->year;
    stJD.jd = (int) ppdr->gmt_day;
    date_sec2hms(ppdr->gmt_sec,&stTime);
    stSec=date2sec(&stJD,&stTime);

/*Compute the *scene* start time from the CEOS DSSR: */
    /* begin with scene center time */
    if (ceos->facility == BEIJING)
      date_dssr2time(ceos->dssr.inp_sctim,&imgDate,&imgTime);
    else
      date_dssr2date(ceos->dssr.inp_sctim,&imgDate,&imgTime);
    date_ymd2jd(&imgDate,&imgJD);
    imgSec=date2sec(&imgJD,&imgTime);

    if (ceos->processor==FOCUS && ceos->product==CCSD) {
        /* do nothing-- dssr "inp_sctim" already gives scene start time */
    }
    else if (0!=strcmp(ceos->dssr.az_time_first,""))
    { /* e.g., ESA data.  "az_time_first" field gives start of image */
        date_dssr2time(ceos->dssr.az_time_first,&imgDate,&imgTime);
        imgSec=date2sec(&imgJD,&imgTime);
    }
    else if (ceos->facility==EOC)
    {
        imgSec-=ceos->dssr.sc_lin*fabs(meta->sar->azimuth_time_per_pixel);
    }
    else {/*Convert scene center time to scene *start* time, by
       subtracting off the center line # * the time/line */
        imgSec-=ceos->dssr.sc_lin*fabs(meta->sar->azimuth_time_per_pixel);
    }
    /*
    // Complex ALOS data have an additional 1 sec shift
    // Still under investigation: Need word from DQ on this
    if (ceos->facility==EOC && ceos->product==SLC)
      imgSec -= 1.0;
    */

    /*Convert scene center # of seconds back to date/time*/
    sec2date(imgSec,&imgJD,&imgTime);

/*Write image time to meta->state_vectors structure*/
    meta->state_vectors->year   = (int) imgJD.year;
    meta->state_vectors->julDay = (int) imgJD.jd;
    meta->state_vectors->second = date_hms2sec(&imgTime);

/*Return the time between state vector start and image start*/
    return stSec-imgSec;
}
Пример #4
0
// input is string in the format "DD-MMM-YYYY, hh:mm:ss" (as in parse_date())
// output is seconds since midnight, Jan 1, 1900 (as from date2sec())
double seconds_from_str(const char *date_str)
{
  ymd_date d;
  hms_time t;
  parse_date(date_str, &d, &t);
  t.sec = 0;

  julian_date jd;
  date_ymd2jd(&d, &jd);

  return date2sec(&jd, &t);
}
Пример #5
0
/* Calculate seconds elapsed from given refYear to the
    seekYear, seekDay (julian day), and seekTime
 ----------------------------------------------------*/
double timeSince(ymd_date *seekDate, hms_time *seekTime, int refYear)
 {
  double totTime;
  int    totDays=0,
         year;
  julian_date julDay;

  date_ymd2jd(seekDate,&julDay);
  for (year = refYear; year < julDay.year; year++) totDays += date_getDaysInYear(year);
  totDays += julDay.jd;
  totTime = totDays * 24.0 * 3600.0 + date_hms2sec(seekTime);

  return(totTime);
 }
Пример #6
0
terrasar_meta *read_terrasar_meta(const char *dataFile)
{
  int ii, kk, numStateVectors, numDopplerEstimates;
  ymd_date imgStartDate, imgDopplerDate, date;
  hms_time imgStartTime, imgDopplerTime, time;
  julian_date julianDate;
  char timeStr[30], str[50];
  tsx_doppler_params *tsx;

  terrasar_meta *terrasar = terrasar_meta_init();

  if (!fileExists(dataFile))
    asfPrintError("Metadata file (%s) does not exist!\n", dataFile);
  xmlDoc *doc = xmlReadFile(dataFile, NULL, 0);
  if (!doc)
    asfPrintError("Could not parse file %s\n", dataFile);

  strcpy(terrasar->filename, xml_get_string_value(doc, 
     "level1Product.productComponents.annotation.file.location.filename"));
  strcpy(terrasar->mission, xml_get_string_value(doc, 
     "level1Product.productInfo.missionInfo.mission"));
  strcpy(terrasar->sensor, xml_get_string_value(doc, 
     "level1Product.productInfo.acquisitionInfo.sensor"));
  strcpy(terrasar->imagingMode, xml_get_string_value(doc,
     "level1Product.productInfo.acquisitionInfo.imagingMode"));
  strcpy(terrasar->elevationBeamConfiguration, xml_get_string_value(doc, 
     "level1Product.productInfo.acquisitionInfo.elevationBeamConfiguration"));
  strcpy(terrasar->imageDataType, xml_get_string_value(doc, 
     "level1Product.productInfo.imageDataInfo.imageDataType"));
  terrasar->imageDataDepth = xml_get_int_value(doc, 
     "level1Product.productInfo.imageDataInfo.imageDataDepth");
  strcpy(terrasar->imageDataFormat, xml_get_string_value(doc, 
     "level1Product.productInfo.imageDataInfo.imageDataFormat"));
  strcpy(terrasar->azimuthTimeUTC, xml_get_string_value(doc, 
     "level1Product.productInfo.sceneInfo.sceneCenterCoord.azimuthTimeUTC"));
  terrasar->absOrbit = 
    xml_get_int_value(doc, "level1Product.productInfo.missionInfo.absOrbit");
  strcpy(terrasar->orbitDirection, xml_get_string_value(doc, 
     "level1Product.productInfo.missionInfo.orbitDirection"));
  terrasar->numberOfLayers = xml_get_int_value(doc, 
     "level1Product.productInfo.imageDataInfo.numberOfLayers");
  strcpy(terrasar->polarisationMode, xml_get_string_value(doc, 
     "level1Product.productInfo.acquisitionInfo.polarisationMode"));
  if (strcmp_case(terrasar->polarisationMode, "SINGLE") == 0)
    strcpy(terrasar->bands, xml_get_string_value(doc, 
    "level1Product.productInfo.acquisitionInfo.polarisationList.polLayer[0]"));
  else if (strcmp_case(terrasar->polarisationMode, "DUAL") == 0) {
    strcpy(terrasar->bands, xml_get_string_value(doc, 
    "level1Product.productInfo.acquisitionInfo.polarisationList.polLayer[0]"));
    strcat(terrasar->bands, ",");
    strcat(terrasar->bands, xml_get_string_value(doc, 
    "level1Product.productInfo.acquisitionInfo.polarisationList.polLayer[1]"));
  }
  else if (strcmp_case(terrasar->polarisationMode, "TWIN") == 0) {
    strcpy(terrasar->bands, xml_get_string_value(doc, 
    "level1Product.productInfo.acquisitionInfo.polarisationList.polLayer[0]"));
    strcat(terrasar->bands, ",");
    strcat(terrasar->bands, xml_get_string_value(doc, 
    "level1Product.productInfo.acquisitionInfo.polarisationList.polLayer[1]"));
  }
  else if (strcmp_case(terrasar->polarisationMode, "QUAD") == 0) {
    strcpy(terrasar->bands, xml_get_string_value(doc, 
    "level1Product.productInfo.acquisitionInfo.polarisationList.polLayer[0]"));
    strcat(terrasar->bands, ",");
    strcat(terrasar->bands, xml_get_string_value(doc, 
    "level1Product.productInfo.acquisitionInfo.polarisationList.polLayer[1]"));
    strcat(terrasar->bands, ",");
    strcat(terrasar->bands, xml_get_string_value(doc, 
    "level1Product.productInfo.acquisitionInfo.polarisationList.polLayer[2]"));
    strcat(terrasar->bands, ",");
    strcat(terrasar->bands, xml_get_string_value(doc, 
    "level1Product.productInfo.acquisitionInfo.polarisationList.polLayer[3]"));
  }
  terrasar->numberOfRows = xml_get_int_value(doc, 
     "level1Product.productInfo.imageDataInfo.imageRaster.numberOfRows");
  terrasar->numberOfColumns = xml_get_int_value(doc, 
     "level1Product.productInfo.imageDataInfo.imageRaster.numberOfColumns");
  strcpy(terrasar->projection, xml_get_string_value(doc, 
     "level1Product.productInfo.productVariantInfo.projection"));
  if (strcmp_case(terrasar->projection, "GROUNDRANGE") == 0)
    terrasar->rangeResolution = xml_get_double_value(doc, 
    "level1Product.productInfo.imageDataInfo.imageRaster."
    "groundRangeResolution");
  if (strcmp_case(terrasar->projection, "SLANTRANGE") == 0)
    terrasar->rangeResolution = xml_get_double_value(doc, 
       "level1Product.productSpecific.complexImageInfo.projectedSpacingRange."
       "slantRange");
  // FIXME: cover MAP case
  terrasar->azimuthResolution = xml_get_double_value(doc, 
     "level1Product.productInfo.imageDataInfo.imageRaster.azimuthResolution");
  terrasar->sceneCenterCoordLat = xml_get_double_value(doc, 
     "level1Product.productInfo.sceneInfo.sceneCenterCoord.lat");
  terrasar->sceneCenterCoordLon = xml_get_double_value(doc, 
     "level1Product.productInfo.sceneInfo.sceneCenterCoord.lon");
  strcpy(terrasar->lookDirection, xml_get_string_value(doc, 
     "level1Product.productInfo.acquisitionInfo.lookDirection"));
  terrasar->azimuthLooks = xml_get_int_value(doc, 
     "level1Product.productInfo.imageDataInfo.imageRaster.azimuthLooks");
  terrasar->rangeLooks = xml_get_int_value(doc, 
     "level1Product.productInfo.imageDataInfo.imageRaster.rangeLooks");
  strcpy(terrasar->imageCoordinateType, xml_get_string_value(doc, 
     "level1Product.productSpecific.complexImageInfo.imageCoordinateType"));
  terrasar->rowSpacing = xml_get_double_value(doc, 
     "level1Product.productInfo.imageDataInfo.imageRaster.rowSpacing");
  terrasar->columnSpacing =  xml_get_double_value(doc, 
     "level1Product.productInfo.imageDataInfo.imageRaster.columnSpacing");
  terrasar->rangeTimeFirst = xml_get_double_value(doc, 
     "level1Product.productInfo.sceneInfo.rangeTime.firstPixel");
  terrasar->rangeTimeLast = xml_get_double_value(doc, 
     "level1Product.productInfo.sceneInfo.rangeTime.lastPixel");
  terrasar->centerFrequency = xml_get_double_value(doc, 
     "level1Product.instrument.radarParameters.centerFrequency");
  terrasar->prf = xml_get_double_value(doc, 
     "level1Product.instrument.settings.settingRecord.PRF");
  terrasar->totalProcessedAzimuthBandwidth = xml_get_double_value(doc, 
     "level1Product.processing.processingParameter."
     "totalProcessedAzimuthBandwidth");
  // chirp rate ???
  terrasar->pulseLength = xml_get_double_value(doc, 
     "level1Product.processing.processingParameter.rangeCompression.chirps."
     "referenceChirp.pulseLength");
  terrasar->rsf = xml_get_double_value(doc, 
     "level1Product.instrument.settings.RSF");
  // pitch, roll, yaw ???

  // read Doppler values
  terrasar->doppler = meta_doppler_init();
  terrasar->doppler->type = tsx_doppler;
  numDopplerEstimates = xml_get_int_value(doc, 
     "level1Product.processing.doppler.dopplerCentroid[0]."
     "numberOfDopplerRecords");
  tsx = tsx_doppler_init(numDopplerEstimates);
  terrasar->doppler->tsx = tsx;
  strcpy(str, xml_get_string_value(doc, 
     "level1Product.processing.doppler.dopplerCentroid[0].dopplerEstimate[0]."
     "timeUTC"));
  date_terrasar2date(str, &imgDopplerDate, &imgDopplerTime);
  tsx->year = imgDopplerDate.year;
  date_ymd2jd(&imgDopplerDate, &julianDate);
  tsx->julDay = julianDate.jd;
  tsx->second = date_hms2sec(&imgDopplerTime);
  for (ii=0; ii<numDopplerEstimates; ii++) {
    strcpy(timeStr, xml_get_string_value(doc, 
       "level1Product.processing.doppler.dopplerCentroid[0]."
       "dopplerEstimate[%d].timeUTC", ii));
    date_terrasar2date(timeStr, &date, &time);
    tsx->dop[ii].time =
      time_difference(&date, &time, &imgDopplerDate, &imgDopplerTime);
    tsx->dop[ii].first_range_time = xml_get_double_value(doc, 
       "level1Product.processing.doppler.dopplerCentroid[0]."
       "dopplerEstimate[%d].combinedDoppler.validityRangeMin", ii);
    tsx->dop[ii].reference_time = xml_get_double_value(doc, 
       "level1Product.processing.doppler.dopplerCentroid[0]."
       "dopplerEstimate[%d].combinedDoppler.referencePoint", ii);
    tsx->dop[ii].poly_degree = xml_get_double_value(doc, 
       "level1Product.processing.doppler.dopplerCentroid[0]."
       "dopplerEstimate[%d].combinedDoppler.polynomialDegree", ii);
    tsx->dop[ii].coefficient = 
      (double *) MALLOC(sizeof(double) * (tsx->dop[ii].poly_degree+1));
    for (kk=0; kk<=tsx->dop[ii].poly_degree; kk++)
      tsx->dop[ii].coefficient[kk] = xml_get_double_value(doc, 
	 "level1Product.processing.doppler.dopplerCentroid[0]."
         "dopplerEstimate[%d].combinedDoppler.coefficient[%d]", ii, kk);
  }  

  // read state vectors
  strcpy(terrasar->sceneStart, xml_get_string_value(doc, 
     "level1Product.productInfo.sceneInfo.start.timeUTC"));
  date_terrasar2date(terrasar->sceneStart, &imgStartDate, &imgStartTime);
  strcpy(terrasar->sceneStop, xml_get_string_value(doc, 
     "level1Product.productInfo.sceneInfo.stop.timeUTC"));
  numStateVectors = xml_get_int_value(doc, 
     "level1Product.platform.orbit.orbitHeader.numStateVectors");
  terrasar->state_vectors = meta_state_vectors_init(numStateVectors);
  terrasar->state_vectors->year = imgStartDate.year;
  date_ymd2jd(&imgStartDate, &julianDate);
  terrasar->state_vectors->julDay = julianDate.jd;
  terrasar->state_vectors->second = date_hms2sec(&imgStartTime);
  for (ii=0; ii<numStateVectors; ii++) {
    sprintf(str, "level1Product.platform.orbit.stateVec[%d].timeUTC", ii);
    strcpy(timeStr, xml_get_string_value(doc, str));
    date_terrasar2date(timeStr, &date, &time);
    terrasar->state_vectors->vecs[ii].time =
      time_difference(&date, &time, &imgStartDate, &imgStartTime);
    sprintf(str, "level1Product.platform.orbit.stateVec[%d].posX", ii);
    terrasar->state_vectors->vecs[ii].vec.pos.x = 
      xml_get_double_value(doc, str);
    sprintf(str, "level1Product.platform.orbit.stateVec[%d].posY", ii);
    terrasar->state_vectors->vecs[ii].vec.pos.y = 
      xml_get_double_value(doc, str);
    sprintf(str, "level1Product.platform.orbit.stateVec[%d].posZ", ii);
    terrasar->state_vectors->vecs[ii].vec.pos.z = 
      xml_get_double_value(doc, str);
    sprintf(str, "level1Product.platform.orbit.stateVec[%d].velX", ii);
    terrasar->state_vectors->vecs[ii].vec.vel.x = 
      xml_get_double_value(doc, str);
    sprintf(str, "level1Product.platform.orbit.stateVec[%d].velY", ii);
    terrasar->state_vectors->vecs[ii].vec.vel.y = 
      xml_get_double_value(doc, str);
    sprintf(str, "level1Product.platform.orbit.stateVec[%d].velZ", ii);
    terrasar->state_vectors->vecs[ii].vec.vel.z = 
      xml_get_double_value(doc, str);
  }

  // read location information
  terrasar->sceneCornerCoord1Lat = xml_get_double_value(doc, 
     "level1Product.productInfo.sceneInfo.sceneCornerCoord[0].lat");
  terrasar->sceneCornerCoord1Lon = xml_get_double_value(doc, 
     "level1Product.productInfo.sceneInfo.sceneCornerCoord[0].lon");
  terrasar->sceneCornerCoord2Lat = xml_get_double_value(doc, 
     "level1Product.productInfo.sceneInfo.sceneCornerCoord[1].lat");
  terrasar->sceneCornerCoord2Lon = xml_get_double_value(doc, 
     "level1Product.productInfo.sceneInfo.sceneCornerCoord[1].lon");
  terrasar->sceneCornerCoord3Lat = xml_get_double_value(doc, 
     "level1Product.productInfo.sceneInfo.sceneCornerCoord[2].lat");
  terrasar->sceneCornerCoord3Lon = xml_get_double_value(doc, 
     "level1Product.productInfo.sceneInfo.sceneCornerCoord[2].lon");
  terrasar->sceneCornerCoord4Lat = xml_get_double_value(doc, 
     "level1Product.productInfo.sceneInfo.sceneCornerCoord[3].lat");
  terrasar->sceneCornerCoord4Lon = xml_get_double_value(doc, 
     "level1Product.productInfo.sceneInfo.sceneCornerCoord[3].lon");

  // read calibration information
  char calFlag[15];
  strcpy(calFlag, xml_get_string_value(doc,
     "level1Product.productInfo.productVariantInfo.radiometricCorrection"));
  if (strcmp_case(calFlag, "CALIBRATED") == 0)
    terrasar->cal_factor = xml_get_double_value(doc,
       "level1Product.calibration.calibrationConstant.calFactor");

  xmlFreeDoc(doc);
  xmlCleanupParser();

  return terrasar;
}
Пример #7
0
radarsat2_meta *read_radarsat2_meta_ext(const char *dataFile, int cal)
{
    int ii, numStateVectors, numDopplerEstimates;
    ymd_date imgStartDate, date;
    hms_time imgStartTime, time;
    julian_date julianDate;
    char timeStr[30], str[150];
    radarsat2_doppler_params *r2_doppler;

    radarsat2_meta *radarsat2 = radarsat2_meta_init();

    if (!fileExists(dataFile))
        asfPrintError("Metadata file (%s) does not exist!\n", dataFile);
    char *path = (char *) MALLOC(sizeof(char)*512);
    char *file = (char *) MALLOC(sizeof(char)*128);
    split_dir_and_file(dataFile, path, file);

    xmlDoc *doc = xmlReadFile(dataFile, NULL, 0);
    if (!doc)
        asfPrintError("Could not parse file %s\n", dataFile);

    strcpy(radarsat2->satellite, xml_get_string_value(doc,
            "product.sourceAttributes.satellite"));
    strcpy(radarsat2->sensor, xml_get_string_value(doc,
            "product.sourceAttributes.sensor"));
    strcpy(radarsat2->beamModeMnemonic, xml_get_string_value(doc,
            "product.sourceAttributes.beamModeMnemonic"));
    strcpy(radarsat2->acquisitionType, xml_get_string_value(doc,
            "product.sourceAttributes.radarParameters.acquisitionType"));
    strcpy(radarsat2->productType, xml_get_string_value(doc,
            "product.imageGenerationParameters.generalProcessingInformation."
            "productType"));
    strcpy(radarsat2->dataType, xml_get_string_value(doc,
            "product.imageAttributes.rasterAttributes.dataType"));
    strcpy(radarsat2->processingFacility, xml_get_string_value(doc,
            "product.imageGenerationParameters.generalProcessingInformation."
            "processingFacility"));
    strcpy(radarsat2->zeroDopplerAzimuthTime, xml_get_string_value(doc,
            "product.imageGenerationParameters.slantRangeToGroundRange."
            "zeroDopplerAzimuthTime"));
    strcpy(radarsat2->softwareVersion, xml_get_string_value(doc,
            "product.imageGenerationParameters.generalProcessingInformation."
            "softwareVersion"));
    radarsat2->bitsPerSample = xml_get_int_value(doc,
                               "product.productInfo.imageDataInfo.imageDataDepth");
    //radarsat2->absOrbit =
    //xml_get_int_value(doc, "product.productInfo.missionInfo.absOrbit");
    strcpy(radarsat2->passDirection, xml_get_string_value(doc,
            "product.sourceAttributes.orbitAndAttitude.orbitInformation."
            "passDirection"));
    // Number of bands needs to be derived from polarizations string
    int band_count = 0;
    char *attribute = (char *) MALLOC(sizeof(char)*128);
    char *fileName = (char *) MALLOC(sizeof(char)*512);
    strcpy(radarsat2->polarizations, xml_get_string_value(doc,
            "product.sourceAttributes.radarParameters.polarizations"));
    for (ii=0; ii<strlen(radarsat2->polarizations)-1; ii++)
        if (radarsat2->polarizations[ii] == ' ')
            radarsat2->polarizations[ii] = ',';
    if (strstr(radarsat2->polarizations, "HH"))
        band_count++;
    if (strstr(radarsat2->polarizations, "VV"))
        band_count++;
    if (strstr(radarsat2->polarizations, "HV"))
        band_count++;
    if (strstr(radarsat2->polarizations, "VH"))
        band_count++;
    radarsat2->band_count = band_count;
    strcpy(radarsat2->filename, "");
    strcpy(radarsat2->bands, "");
    // Park the filenames in the basename field of the metadata and replace
    // it with the directory name once we are done with importing the data
    for (ii=0; ii<band_count; ii++) {
        sprintf(str,
                "product.imageAttributes.fullResolutionImageData[%d].pole", ii);
        strcpy(attribute, xml_get_string_attribute(doc, str));
        sprintf(str, "product.imageAttributes.fullResolutionImageData[%d]", ii);
        strcpy(fileName, xml_get_string_value(doc, str));
        if (ii == 0) {
            sprintf(radarsat2->filename, "%s", fileName);
            sprintf(radarsat2->bands, "AMP-%s,PHASE-%s",
                    uc(attribute), uc(attribute));
        }
        else {
            strcat(radarsat2->filename, ",");
            strcat(radarsat2->filename, fileName);
            strcat(radarsat2->bands, ",");
            sprintf(str, "AMP-%s,PHASE-%s", uc(attribute), uc(attribute));
            strcat(radarsat2->bands, str);
        }
    }
    FREE(fileName);
    FREE(attribute);
    radarsat2->numberOfLines = xml_get_int_value(doc,
                               "product.imageAttributes.rasterAttributes.numberOfLines");
    radarsat2->numberOfSamplesPerLine = xml_get_int_value(doc,
                                        "product.imageAttributes.rasterAttributes.numberOfSamplesPerLine");
    radarsat2->sampledPixelSpacing = xml_get_double_value(doc,
                                     "product.imageAttributes.rasterAttributes.sampledPixelSpacing");
    radarsat2->sampledLineSpacing = xml_get_double_value(doc,
                                    "product.imageAttributes.rasterAttributes.sampledLineSpacing");
    radarsat2->semiMajorAxis = xml_get_double_value(doc,
                               "product.imageAttributes.geographicInformation."
                               "referenceEllipsoidParameters.semiMajorAxis");
    radarsat2->semiMinorAxis = xml_get_double_value(doc,
                               "product.imageAttributes.geographicInformation."
                               "referenceEllipsoidParameters.semiMinorAxis");
    strcpy(radarsat2->lineTimeOrdering, xml_get_string_value(doc,
            "product.imageAttributes.rasterAttributes.lineTimeOrdering"));
    strcpy(radarsat2->pixelTimeOrdering, xml_get_string_value(doc,
            "product.imageAttributes.rasterAttributes.pixelTimeOrdering"));
    strcpy(radarsat2->antennaPointing, xml_get_string_value(doc,
            "product.sourceAttributes.radarParameters.antennaPointing"));
    radarsat2->numberOfAzimuthLooks = xml_get_int_value(doc,
                                      "product.imageGenerationParameters.sarProcessingInformation."
                                      "numberOfAzimuthLooks");
    radarsat2->numberOfRangeLooks = xml_get_int_value(doc,
                                    "product.imageGenerationParameters.sarProcessingInformation."
                                    "numberOfRangeLooks");
    radarsat2->slantRangeNearEdge = xml_get_double_value(doc,
                                    "product.imageGenerationParameters.sarProcessingInformation."
                                    "slantRangeNearEdge");
    radarsat2->radarCenterFrequency = xml_get_double_value(doc,
                                      "product.sourceAttributes.radarParameters.radarCenterFrequency");
    radarsat2->pulseRepetitionFrequency = xml_get_double_value(doc,
                                          "product.sourceAttributes.radarParameters.pulseRepetitionFrequency");
    radarsat2->satelliteHeight = xml_get_double_value(doc,
                                 "product.imageGenerationParameters.sarProcessingInformation."
                                 "satelliteHeight");
    radarsat2->totalProcessedAzimuthBandwidth = xml_get_double_value(doc,
            "product.imageGenerationParameters.sarProcessingInformation."
            "totalProcessedAzimuthBandwidth");
    // chirp rate ???
    radarsat2->pulseLength = xml_get_double_value(doc,
                             "product.sourceAttributes.radarParameters.pulseLength");
    radarsat2->adcSamplingRate = xml_get_double_value(doc,
                                 "product.sourceAttributes.radarParameters.adcSamplingRate");
    // pitch, roll, yaw ???

    // read Doppler values
    radarsat2->doppler = meta_doppler_init();
    radarsat2->doppler->type = radarsat2_doppler;
    char *dopplerCentroidStr;
    dopplerCentroidStr = (char *) MALLOC(sizeof(char)*512);
    strcpy(dopplerCentroidStr, xml_get_string_value(doc,
            "product.imageGenerationParameters.dopplerCentroid."
            "dopplerCentroidCoefficients"));
    numDopplerEstimates = getNumParamsInString(dopplerCentroidStr);
    r2_doppler = radarsat2_doppler_init(numDopplerEstimates);
    radarsat2->doppler->r2 = r2_doppler;
    r2_doppler->ref_time_centroid = xml_get_double_value(doc,
                                    "product.imageGenerationParameters.dopplerCentroid."
                                    "dopplerCentroidReferenceTime");
    r2_doppler->ref_time_rate = xml_get_double_value(doc,
                                "product.imageGenerationParameters.dopplerRateValues."
                                "dopplerRateReferenceTime");
    char *dopplerRateStr;
    dopplerRateStr = (char *) MALLOC(sizeof(char)*512);
    strcpy(dopplerRateStr, xml_get_string_value(doc,
            "product.imageGenerationParameters.dopplerRateValues."
            "dopplerRateValuesCoefficients"));
    r2_doppler->time_first_sample = xml_get_double_value(doc,
                                    "product.imageGenerationParameters.slantRangeToGroundRange."
                                    "slantRangeTimeToFirstRangeSample");
    char *p, *q;
    p = dopplerCentroidStr;
    for (ii=0; ii<numDopplerEstimates; ii++) {
        if (ii == 0)
            q = p;
        else {
            if (strchr(p, ' ')) {
                q = strchr(p, ' ');
                q++;
            }
        }
        sscanf(q, "%lf", &r2_doppler->centroid[ii]);
        p = q;
    }
    FREE(dopplerCentroidStr);
    p = dopplerRateStr;
    for (ii=0; ii<numDopplerEstimates; ii++) {
        if (ii == 0)
            q = p;
        else {
            if (strchr(p, ' ')) {
                q = strchr(p, ' ');
                q++;
            }
        }
        sscanf(q, "%lf", &r2_doppler->rate[ii]);
        p = q;
    }
    FREE(dopplerRateStr);

    // read state vectors
    strcpy(radarsat2->zeroDopplerTimeFirstLine, xml_get_string_value(doc,
            "product.imageGenerationParameters.sarProcessingInformation."
            "zeroDopplerTimeFirstLine"));
    date_terrasar2date(radarsat2->zeroDopplerTimeFirstLine,
                       &imgStartDate, &imgStartTime);
    strcpy(radarsat2->zeroDopplerTimeLastLine, xml_get_string_value(doc,
            "product.imageGenerationParameters.sarProcessingInformation."
            "zeroDopplerTimeLastLine"));
    // Accommodate data stored in reverse time
    if (strcmp_case(radarsat2->lineTimeOrdering, "DECREASING") == 0)
        date_terrasar2date(radarsat2->zeroDopplerTimeLastLine,
                           &imgStartDate, &imgStartTime);

    // FIXME: determine numStateVector from data - count the entries
    //numStateVectors = xml_get_int_value(doc,
    //   "product.platform.orbit.orbitHeader.numStateVectors");
    numStateVectors = 5;
    radarsat2->state_vectors = meta_state_vectors_init(numStateVectors);
    radarsat2->state_vectors->year = imgStartDate.year;
    date_ymd2jd(&imgStartDate, &julianDate);
    radarsat2->state_vectors->julDay = julianDate.jd;
    radarsat2->state_vectors->second = date_hms2sec(&imgStartTime);
    for (ii=0; ii<numStateVectors; ii++) {
        sprintf(str, "product.sourceAttributes.orbitAndAttitude.orbitInformation."
                "stateVector[%d].timeStamp", ii);
        strcpy(timeStr, xml_get_string_value(doc, str));
        date_terrasar2date(timeStr, &date, &time);
        radarsat2->state_vectors->vecs[ii].time =
            time_difference(&date, &time, &imgStartDate, &imgStartTime);
        sprintf(str, "product.sourceAttributes.orbitAndAttitude.orbitInformation."
                "stateVector[%d].xPosition", ii);
        radarsat2->state_vectors->vecs[ii].vec.pos.x =
            xml_get_double_value(doc, str);
        sprintf(str, "product.sourceAttributes.orbitAndAttitude.orbitInformation."
                "stateVector[%d].yPosition", ii);
        radarsat2->state_vectors->vecs[ii].vec.pos.y =
            xml_get_double_value(doc, str);
        sprintf(str, "product.sourceAttributes.orbitAndAttitude.orbitInformation."
                "stateVector[%d].zPosition", ii);
        radarsat2->state_vectors->vecs[ii].vec.pos.z =
            xml_get_double_value(doc, str);
        sprintf(str, "product.sourceAttributes.orbitAndAttitude.orbitInformation."
                "stateVector[%d].xVelocity", ii);
        radarsat2->state_vectors->vecs[ii].vec.vel.x =
            xml_get_double_value(doc, str);
        sprintf(str, "product.sourceAttributes.orbitAndAttitude.orbitInformation."
                "stateVector[%d].yVelocity", ii);
        radarsat2->state_vectors->vecs[ii].vec.vel.y =
            xml_get_double_value(doc, str);
        sprintf(str, "product.sourceAttributes.orbitAndAttitude.orbitInformation."
                "stateVector[%d].zVelocity", ii);
        radarsat2->state_vectors->vecs[ii].vec.vel.z =
            xml_get_double_value(doc, str);
    }

    // read location information from the tie points
    ii = 0;
    int line=-99, pixel=-99, found=TRUE;
    while (found) {
        sprintf(str, "product.imageAttributes.geographicInformation."
                "geolocationGrid.imageTiePoint[%d].imageCoordinate.line", ii);
        line = (int) xml_get_double_value(doc, str);
        sprintf(str, "product.imageAttributes.geographicInformation."
                "geolocationGrid.imageTiePoint[%d].imageCoordinate.pixel", ii);
        pixel = (int) xml_get_double_value(doc, str);
        if (line < 0 || pixel < 0)
            found = FALSE;
        if (found) {
            if (line == 0 && pixel == 0) {
                sprintf(str, "product.imageAttributes.geographicInformation."
                        "geolocationGrid.imageTiePoint[%d].geodeticCoordinate."
                        "latitude", ii);
                radarsat2->sceneCornerCoord1Lat = xml_get_double_value(doc, str);
                sprintf(str, "product.imageAttributes.geographicInformation."
                        "geolocationGrid.imageTiePoint[%d].geodeticCoordinate."
                        "longitude", ii);
                radarsat2->sceneCornerCoord1Lon = xml_get_double_value(doc, str);
            }
            if (line == 0 && pixel == radarsat2->numberOfSamplesPerLine-1) {
                sprintf(str, "product.imageAttributes.geographicInformation."
                        "geolocationGrid.imageTiePoint[%d].geodeticCoordinate."
                        "latitude", ii);
                radarsat2->sceneCornerCoord2Lat = xml_get_double_value(doc, str);
                sprintf(str, "product.imageAttributes.geographicInformation."
                        "geolocationGrid.imageTiePoint[%d].geodeticCoordinate."
                        "longitude", ii);
                radarsat2->sceneCornerCoord2Lon = xml_get_double_value(doc, str);
            }
            if (line == radarsat2->numberOfLines-1 && pixel == 0) {
                sprintf(str, "product.imageAttributes.geographicInformation."
                        "geolocationGrid.imageTiePoint[%d].geodeticCoordinate."
                        "latitude", ii);
                radarsat2->sceneCornerCoord3Lat = xml_get_double_value(doc, str);
                sprintf(str, "product.imageAttributes.geographicInformation."
                        "geolocationGrid.imageTiePoint[%d].geodeticCoordinate."
                        "longitude", ii);
                radarsat2->sceneCornerCoord3Lon = xml_get_double_value(doc, str);
            }
            if (line == radarsat2->numberOfLines-1 &&
                    pixel == radarsat2->numberOfSamplesPerLine-1) {
                sprintf(str, "product.imageAttributes.geographicInformation."
                        "geolocationGrid.imageTiePoint[%d].geodeticCoordinate."
                        "latitude", ii);
                radarsat2->sceneCornerCoord4Lat = xml_get_double_value(doc, str);
                sprintf(str, "product.imageAttributes.geographicInformation."
                        "geolocationGrid.imageTiePoint[%d].geodeticCoordinate."
                        "longitude", ii);
                radarsat2->sceneCornerCoord4Lon = xml_get_double_value(doc, str);
            }
        }
        ii++;
    }

    // Read calibration information
    if (cal) {
        double sample_count = radarsat2->numberOfSamplesPerLine;
        attribute = (char *) MALLOC(sizeof(char)*128);
        fileName = (char *) MALLOC(sizeof(char)*512);
        for (ii=0; ii<3; ii++) {
            sprintf(str,
                    "product.imageAttributes.lookupTable[%d].incidenceAngleCorrection",
                    ii);
            strcpy(attribute, xml_get_string_attribute(doc, str));
            sprintf(str, "product.imageAttributes.lookupTable[%d]", ii);
            if (strlen(path) > 0)
                sprintf(fileName, "%s%s", path, xml_get_string_value(doc, str));
            else
                strcpy(fileName, xml_get_string_value(doc, str));
            if (strcmp_case(attribute, "Beta Nought") == 0)
                radarsat2->gains_beta = read_radarsat2_lut(fileName, sample_count);
            else if (strcmp_case(attribute, "Sigma Nought") == 0)
                radarsat2->gains_sigma = read_radarsat2_lut(fileName, sample_count);
            else if (strcmp_case(attribute, "Gamma") == 0)
                radarsat2->gains_gamma = read_radarsat2_lut(fileName, sample_count);
        }
        FREE(attribute);
        FREE(fileName);
    }

    xmlFreeDoc(doc);
    xmlCleanupParser();

    return radarsat2;
}
Пример #8
0
meta_parameters *iso2meta(iso_meta *iso)
{
  int ii;
  meta_parameters *meta = raw_init();
  char str[30];

  // Convenience pointers
  iso_generalHeader *header = iso->generalHeader;
  iso_productComponents *comps = iso->productComponents;
  iso_productInfo *info = iso->productInfo;
  iso_productSpecific *spec = iso->productSpecific;
  iso_setup *setup = iso->setup;
  iso_processing *proc = iso->processing;
  iso_instrument *inst = iso->instrument;
  iso_platform *platform = iso->platform;
  iso_productQuality *quality = iso->productQuality;

  meta->meta_version = 3.5;

  // General block
  for (ii=0; ii<comps->numAnnotations; ii++)
    if (comps->annotation[ii].type == MAIN_TYPE)
      strncpy(meta->general->basename, comps->annotation[ii].file.name, 256);
  strcpy(meta->general->sensor, header->mission);
  strcpy(meta->general->sensor_name, info->sensor);
  strcpy(meta->general->mode, info->elevationBeamConfiguration);
  strcpy(meta->general->receiving_station, info->receivingStation);
  strcpy(meta->general->processor, header->generationSystem);
  if (info->imageDataType == DETECTED_DATA_TYPE &&
      info->imageDataDepth == 8)
    meta->general->data_type = ASF_BYTE;
  else if (info->imageDataType == DETECTED_DATA_TYPE &&
	   info->imageDataDepth == 16)
    meta->general->data_type = INTEGER16;
  else if (info->imageDataType == DETECTED_DATA_TYPE &&
	   info->imageDataDepth == 32)
    // assumption here is that we are not dealing with INTERGER32
    meta->general->data_type = REAL32;
  else if (info->imageDataType == DETECTED_DATA_TYPE &&
	   info->imageDataDepth == 64)
    meta->general->data_type = REAL64;
  else if (info->imageDataType == COMPLEX_DATA_TYPE &&
	   info->imageDataDepth == 8)
    meta->general->data_type = COMPLEX_BYTE;
  else if (info->imageDataType == COMPLEX_DATA_TYPE &&
	   info->imageDataDepth == 16)
    meta->general->data_type = COMPLEX_INTEGER16;
  else if (info->imageDataType == COMPLEX_DATA_TYPE &&
	   info->imageDataDepth == 32)
    // assumption here is that we are not dealing with COMPLEX_INTEGER32
    meta->general->data_type = COMPLEX_REAL32;
  else if (info->imageDataType == COMPLEX_DATA_TYPE &&
	   info->imageDataDepth == 64)
    meta->general->data_type = COMPLEX_REAL64;
  if (info->imageDataType == RAW_DATA_TYPE)
    meta->general->image_data_type = RAW_IMAGE;
  else if (info->imageDataType == COMPLEX_DATA_TYPE)
    meta->general->image_data_type = COMPLEX_IMAGE;
  else if (info->imageDataType == DETECTED_DATA_TYPE)
    meta->general->image_data_type = AMPLITUDE_IMAGE;
  // more detailed mapping of imageDataType will probably need pixelValueID 
  // context
  if (strcmp_case(info->pixelValueID, "RADAR BRIGHTNESS") == 0)
    meta->general->radiometry = r_AMP;
  // dealing with any form of calibration not implemented yet
  dateTime2str(info->sceneCenterCoord.azimuthTimeUTC,
	       meta->general->acquisition_date);
  meta->general->orbit = info->absOrbit;
  if (info->orbitDirection == ASCENDING)  
    meta->general->orbit_direction = 'A';
  else if (info->orbitDirection == DESCENDING)
    meta->general->orbit_direction = 'D';
  meta->general->frame = setup->frameID;
  meta->general->band_count = comps->numLayers;
  strcpy(meta->general->bands, polLayer2str(comps->imageData[0].polLayer));
  for (ii=1; ii<comps->numLayers; ii++) {
    sprintf(str, ", %s", polLayer2str(comps->imageData[ii].polLayer));
    strcat(meta->general->bands, str);
  }
  meta->general->line_count = info->numberOfRows;
  meta->general->sample_count = info->numberOfColumns;
  meta->general->start_line = info->startRow;
  meta->general->start_sample = info->startColumn;
  meta->general->x_pixel_size = info->groundRangeResolution;
  meta->general->y_pixel_size = info->azimuthResolution;
  meta->general->center_latitude = info->sceneCenterCoord.lat;
  meta->general->center_longitude = info->sceneCenterCoord.lon;
  spheroid_type_t spheroid = WGS84_SPHEROID; // FIXME: needs to know reference
  spheroid_axes_lengths(spheroid,
			&meta->general->re_major, &meta->general->re_minor);
  meta->general->bit_error_rate = quality->imageDataQuality[0].bitErrorRate;
  meta->general->missing_lines = quality->imageDataQuality[0].missingLines;
  meta->general->no_data = (float) quality->imageDataQuality[0].noData;

  // SAR block
  meta->sar = meta_sar_init();
  if (info->projection == SLANTRANGE_PROJ)
    meta->sar->image_type = 'S';
  else if (info->projection == GROUNDRANGE_PROJ)
    meta->sar->image_type = 'G';
  else if (info->projection == MAP_PROJ)
    meta->sar->image_type = 'P';
  if (setup->lookDirection == RIGHT_LOOK)
    meta->sar->look_direction = 'R';
  else if (setup->lookDirection == LEFT_LOOK)
    meta->sar->look_direction = 'L';
  meta->sar->azimuth_look_count = info->azimuthLooks;
  meta->sar->range_look_count = info->rangeLooks;
  if (spec->imageCoordinateType == RAW_COORD)
    meta->sar->deskewed = FALSE;
  else if (spec->imageCoordinateType == ZERODOPPLER)
    meta->sar->deskewed = TRUE;
  meta->general->line_scaling = info->rowScaling;  
  meta->general->sample_scaling = info->columnScaling;
  meta->sar->range_time_per_pixel = info->columnSpacing;
  meta->sar->azimuth_time_per_pixel = info->rowSpacing;
  meta->sar->slant_shift = spec->slantRangeShift;
  //meta->sar->slant_range_first_pixel = info->rangeTimeFirstPixel * SPD_LIGHT;
  meta->sar->slant_range_first_pixel = spec->projectedSpacingSlantRange;
  meta->sar->wavelength = SPD_LIGHT / inst->centerFrequency;
  meta->sar->prf = spec->commonPRF;
  meta->sar->earth_radius = info->earthRadius;
  meta->sar->satellite_height = info->satelliteHeight;
  // meta->sar->satellite_binary_time;
  // meta->sar->satellite_clock_time;
  for (ii=0; ii<=proc->doppler[0].polynomialDegree; ii++)
    meta->sar->range_doppler_coefficients[ii] = 
      proc->doppler[0].coefficient[ii];
  meta->sar->azimuth_doppler_coefficients[0] = proc->doppler[0].coefficient[0];
  // meta->sar->chirp_rate
  // meta->sar->pulse_duration
  meta->sar->range_sampling_rate = spec->commonRSF;
  if (info->polarizationMode == SINGLE_POL)
    strcpy(meta->sar->polarization, "SINGLE");
  else if (info->polarizationMode == DUAL_POL)
    strcpy(meta->sar->polarization, "DUAL");
  else if (info->polarizationMode == QUAD_POL)
    strcpy(meta->sar->polarization, "QUAD");
  meta->sar->multilook = proc->multiLookedFlag;
  meta->sar->pitch = info->pitch;
  meta->sar->roll = info->roll;
  meta->sar->yaw = info->yaw;
  meta->sar->incid_a[0] = info->sceneCenterCoord.incidenceAngle;
  meta->sar->heading_angle = info->headingAngle;
  meta->sar->chirp_rate = proc->processingParameter[0].chirpRate;
  meta->sar->pulse_duration = proc->processingParameter[0].pulseDuration;

  // meta->projection
  // meta->transform
  // meta->airsar
  // meta->uavsar
  // meta->statistics

  int numVectors = platform->numStateVectors;
  meta->state_vectors = meta_state_vectors_init(numVectors);
  meta->state_vectors->vector_count = numVectors;
  ymd_date ymdStart, ymdSV;
  julian_date jd;
  hms_time hmsStart, hmsSV;
  ymdStart.year = info->startTimeUTC.year;
  ymdStart.month = info->startTimeUTC.month;
  ymdStart.day = info->startTimeUTC.day;
  hmsStart.hour = info->startTimeUTC.hour;
  hmsStart.min = info->startTimeUTC.min;
  hmsStart.sec = info->startTimeUTC.second;
  meta->state_vectors->year = info->startTimeUTC.year;
  date_ymd2jd(&ymdStart, &jd);
  meta->state_vectors->julDay = jd.jd;
  meta->state_vectors->second = date_hms2sec(&hmsStart);
  for (ii=0; ii<numVectors; ii++) {
    ymdSV.year = platform->stateVec[ii].timeUTC.year;
    ymdSV.month = platform->stateVec[ii].timeUTC.month;
    ymdSV.day = platform->stateVec[ii].timeUTC.day;
    hmsSV.hour = platform->stateVec[ii].timeUTC.hour;
    hmsSV.min = platform->stateVec[ii].timeUTC.min;
    hmsSV.sec = platform->stateVec[ii].timeUTC.second;
    meta->state_vectors->vecs[ii].time = 
      time_difference(&ymdSV, &hmsSV, &ymdStart, &hmsStart);
    meta->state_vectors->vecs[ii].vec.pos.x = platform->stateVec[ii].posX;
    meta->state_vectors->vecs[ii].vec.pos.y = platform->stateVec[ii].posY;
    meta->state_vectors->vecs[ii].vec.pos.z = platform->stateVec[ii].posZ;
    meta->state_vectors->vecs[ii].vec.vel.x = platform->stateVec[ii].velX;
    meta->state_vectors->vecs[ii].vec.vel.y = platform->stateVec[ii].velY;
    meta->state_vectors->vecs[ii].vec.vel.z = platform->stateVec[ii].velZ;
  }
  if (meta->sar->azimuth_time_per_pixel > 0)
    meta->sar->time_shift = 0.0;
  else
    meta->sar->time_shift = meta->state_vectors->vecs[numVectors-1].time;

  if (meta->sar->yaw == 0 ||
      !meta_is_valid_double(meta->sar->yaw))
  {
    meta->sar->yaw = meta_yaw(meta, meta->general->line_count/2.0,
                                    meta->general->sample_count/2.0);
  }
  /*
  // few calculations need state vectors
  meta->sar->earth_radius = 
    meta_get_earth_radius(meta, line_count/2, sample_count/2);
  // meta->sar->earth_radius_pp
  meta->sar->satellite_height =
    meta_get_sat_height(meta, meta->general->line_count/2,
			meta->general->sample_count/2);
  meta->sar->incid_a[0] = meta_incid(meta, line_count/2, sample_count/2)*R2D;
  */

  // Location block
  meta_get_corner_coords(meta);
/*
  meta->location = meta_location_init();
  for (ii=0; ii<4; ii++) {
    if (info->sceneCornerCoord[ii].refRow == 0 &&
	info->sceneCornerCoord[ii].refColumn == 0) {
      meta->location->lat_start_near_range = info->sceneCornerCoord[ii].lat;
      meta->location->lon_start_near_range = info->sceneCornerCoord[ii].lon;
    }
    else if (info->sceneCornerCoord[ii].refRow == 0 &&
	     info->sceneCornerCoord[ii].refColumn == sample_count) {
      meta->location->lat_start_far_range = info->sceneCornerCoord[ii].lat;
      meta->location->lon_start_far_range = info->sceneCornerCoord[ii].lon;
    }
    else if (info->sceneCornerCoord[ii].refRow == line_count &&
	     info->sceneCornerCoord[ii].refColumn == 0) {
      meta->location->lat_end_near_range = info->sceneCornerCoord[ii].lat;
      meta->location->lon_end_near_range = info->sceneCornerCoord[ii].lon;
    }
    else if (info->sceneCornerCoord[ii].refRow == line_count &&
	     info->sceneCornerCoord[ii].refColumn == sample_count) {
      meta->location->lat_end_far_range = info->sceneCornerCoord[ii].lat;
      meta->location->lon_end_far_range = info->sceneCornerCoord[ii].lon;
    }
  }
*/
  return meta;
}
Пример #9
0
/***************************************************************
 * Ceos_init_stVec:
 * Reads state vectors from given CEOS file, writing them in the
 * appropriate format to SAR parameters structure.*/
void ceos_init_stVec(const char *fName, ceos_description *ceos,
             meta_parameters *meta)
{
  struct pos_data_rec ppdr;

  /*Fetch platform position data record.*/
  get_ppdr(fName,&ppdr);

  // Read the state vectors from the leader data file, adjust coordinate system, etc.
  // and write them to the SAR parameters structures
  ceos_read_stVecs(fName, ceos, meta);

  // For ALOS Palsar orbits only
  // Don't propagate but select nine state vectors around the center for the
  // higher order interpolation scheme
  if (ceos->processor == ALOS_PROC) {

    // Determine closest state vector
    int ii, min;
    double diff = 99999999;
    for (ii=0; ii<meta->state_vectors->vector_count; ii++) {
      if (fabs(meta->state_vectors->vecs[ii].time) < diff) {
        diff = fabs(meta->state_vectors->vecs[ii].time);
        min = ii;
      }
    }

    // Populate a new state vector 
    ymd_date img_ymd;
    julian_date img_jd;
    hms_time img_time;
    img_jd.year = meta->state_vectors->year;
    img_jd.jd   = meta->state_vectors->julDay;
    date_sec2hms(meta->state_vectors->second,&img_time);
    date_jd2ymd(&img_jd, &img_ymd);
    add_time((min-4)*60, &img_ymd, &img_time);
    date_ymd2jd(&img_ymd, &img_jd);
    meta_state_vectors *new_st = meta_state_vectors_init(9);
    new_st->year   = img_jd.year;
    new_st->julDay = img_jd.jd;
    new_st->second = date_hms2sec(&img_time);
    for (ii=0; ii<9; ii++)
      new_st->vecs[ii] = meta->state_vectors->vecs[ii+min-4];
    FREE(meta->state_vectors);
    meta->state_vectors = new_st;
    // Time shift should definitely set in the code that is calling this function
    // meta->sar->time_shift = 0.0;
  }
  // Propagate three state vectors for regular frames
  else if (ceos->processor != PREC && ceos->processor != unknownProcessor) {
      int vector_count=3;
      double data_int = meta->sar->original_line_count / 2
                  * fabs(meta->sar->azimuth_time_per_pixel);
      meta->state_vectors->vecs[0].time = get_timeDelta(ceos, &ppdr, meta);
      if (ceos->processor != PREC && data_int < 360.0) {
          while (fabs(data_int) > 15.0) {
              data_int /= 2;
              vector_count = vector_count*2-1;
          }
      // propagate three state vectors: start, center, end
          propagate_state(meta, vector_count, data_int);
      }
  }
}
Пример #10
0
static void sort_input_preference(char **infiles, int n_inputs, 
				  char *preference)
{
  int ii, kk;
  double lat[n_inputs], lon[n_inputs], sec[n_inputs], sorter[n_inputs];
  ymd_date date;
  hms_time time;
  julian_date jd;
  char **tmpfiles = (char **) MALLOC(sizeof(char *)*n_inputs);

  asfPrintStatus("Sort input images for preference: %s\n\n", preference);

  // Read in metadata
  for (ii=0; ii<n_inputs; ii++) {
    tmpfiles[ii] = (char *) MALLOC(sizeof(char)*50);
    meta_parameters *meta = meta_read(infiles[ii]);
    lat[ii] = meta->general->center_latitude;
    lon[ii] = meta->general->center_longitude;
    parse_DMYdate(meta->general->acquisition_date, &date, &time);
    date_ymd2jd(&date, &jd);
    sec[ii] = date2sec(&jd, &time);
    if (strcmp_case(preference, "north") == 0 ||
	strcmp_case(preference, "south") == 0)
      sorter[ii] = lat[ii];
    else if (strcmp_case(preference, "west") == 0 ||
	     strcmp_case(preference, "east") == 0)
      sorter[ii] = lon[ii];
    else if (strcmp_case(preference, "old") == 0 ||
	     strcmp_case(preference, "new") == 0)
      sorter[ii] = sec[ii];
    meta_free(meta);
  }
  
  // Get on with the sorting business
  if (strcmp_case(preference, "south") == 0 ||
      strcmp_case(preference, "west") == 0 ||
      strcmp_case(preference, "old") == 0)
    qsort(sorter, n_inputs, sizeof(double), compare_big_doubles);
  else
    qsort(sorter, n_inputs, sizeof(double), compare_small_doubles);

  // Apply the order to input file list
  for (ii=0; ii<n_inputs; ii++) {
    for (kk=0; kk<n_inputs; kk++) {
      if ((strcmp_case(preference, "north") == 0 ||
	   strcmp_case(preference, "south") == 0) &&
	  sorter[ii] == lat[kk])
	sprintf(tmpfiles[ii], "%s", infiles[kk]);
      else if ((strcmp_case(preference, "east") == 0 ||
		strcmp_case(preference, "west") == 0) &&
	       sorter[ii] == lon[kk])
	sprintf(tmpfiles[ii], "%s", infiles[kk]);
      else if ((strcmp_case(preference, "old") == 0 ||
		strcmp_case(preference, "new") == 0) &&
	       sorter[ii] == sec[kk])
	sprintf(tmpfiles[ii], "%s", infiles[kk]);
    }
  }
  for (ii=0; ii<n_inputs; ii++) {
    sprintf(infiles[ii], "%s", tmpfiles[ii]);
    //printf("Sorted file[%d]: %s\n", ii+1, infiles[ii]);
  }

  // Clean up
  for (ii=0; ii<n_inputs; ii++)
    FREE(tmpfiles[ii]);
  FREE(tmpfiles);
}
Пример #11
0
meta_parameters* vp2meta(vexcel_plain *vp)
{
  vp_doppler_centroid_parameters doppler_params;
  meta_parameters *meta;
  char *mon[13]={"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep",
     "Oct","Nov","Dec"};
  ymd_date ymd, ref_date;
  hms_time time, ref_time;
  julian_date jd;
  int i, nStVec;

  // Initialize the meta structure
  meta = raw_init();

  // Fill general block
  strcpy(meta->general->basename, vp->gli_product.image_desc.title);
  strcpy(meta->general->sensor, vp->sensor.instrument_name);
  strcpy(meta->general->sensor_name, vp->sensor.sensor_name);
  // FIXME: need to handle multibeam data
  strcpy(meta->general->mode, vp->sensor.beam[0].beam_name);
  strcpy(meta->general->processor, vp->gli_product.processor_name);
  if (vp->gli_product.image_desc.bytes_per_pixel == 1)
    meta->general->data_type = ASF_BYTE;
  else if (vp->gli_product.image_desc.bytes_per_pixel == 2)
    meta->general->data_type = INTEGER16;
  else if (vp->gli_product.image_desc.bytes_per_pixel == 4)
    meta->general->data_type = REAL32;
  meta->general->image_data_type = AMPLITUDE_IMAGE;
  meta->general->radiometry = r_AMP;
  date_dssr2date(vp->gli_product.orbit_nr_date, &ymd, &time);
  sprintf(meta->general->acquisition_date, "%2d-%s-%4d", 
	  ymd.day, mon[ymd.month], ymd.year);
  meta->general->orbit = vp->gli_product.orbit_nr;
  if (strncmp(vp->flight_path_direction, "ASCENDING", 9) == 0)
    meta->general->orbit_direction = 'A';
  else
    meta->general->orbit_direction = 'D';
  meta->general->frame = MAGIC_UNSET_INT;
  meta->general->band_count = vp->sensor.nr_beams;
  strcpy(meta->general->bands, "AMP");
  meta->general->line_count = vp->gli_product.image_desc.nr_lines;;
  meta->general->sample_count = vp->gli_product.image_desc.nr_pixels;
  meta->general->start_line = 0;
  meta->general->start_sample = 0;
  meta->general->x_pixel_size = vp->gli_product.image_desc.line_spacing;
  meta->general->y_pixel_size = vp->gli_product.image_desc.pixel_spacing;
  meta->general->center_latitude = 
    vp->gli_product.image_desc.coord.center_line_center_pixel.lat;
  meta->general->center_longitude = 
    vp->gli_product.image_desc.coord.center_line_center_pixel.lon;;
  meta->general->re_major = 
    vp->gli_product.image_desc.coord.earth_model.major;
  meta->general->re_minor = 
    vp->gli_product.image_desc.coord.earth_model.minor;
  meta->general->bit_error_rate = MAGIC_UNSET_DOUBLE;
  meta->general->missing_lines = 0;
  meta->general->no_data = MAGIC_UNSET_DOUBLE;

  // Fill SAR block
  meta->sar = meta_sar_init();
  // working with assumptions here
  meta->sar->image_type = 'G';
  if (vp->sensor.clock_angle >= 0.0)
    meta->sar->look_direction = 'R';
  else
    meta->sar->look_direction = 'L';
  meta->sar->azimuth_look_count = vp->gli_product.azimuth_looks;
  meta->sar->range_look_count = vp->gli_product.range_looks;
  meta->sar->deskewed = vp->gli_product.skew_flag;
  meta->sar->original_line_count = meta->general->line_count;
  meta->sar->original_sample_count = meta->general->sample_count;
  meta->sar->line_increment = 1;
  meta->sar->sample_increment = 1;
  meta->sar->range_time_per_pixel = 
    fabs((2.0 * vp->gli_product.image_desc.pixel_spacing) / SPD_LIGHT);
  meta->sar->azimuth_time_per_pixel = vp->gli_product.time_per_line;
  meta->sar->slant_range_first_pixel = vp->gli_product.near_range;
  meta->sar->slant_shift = 0.0;
  if (meta->general->orbit_direction == 'D')
    meta->sar->time_shift = 0.0;
  else if (meta->general->orbit_direction == 'A')
    meta->sar->time_shift = 
      fabs(meta->sar->original_line_count * meta->sar->azimuth_time_per_pixel);
  else
    meta->sar->time_shift = MAGIC_UNSET_DOUBLE;
  meta->sar->wavelength = SPD_LIGHT / vp->sensor.beam[0].carrier_freq;
  meta->sar->prf = vp->sensor.beam[0].prf;
  meta->sar->earth_radius_pp = MAGIC_UNSET_DOUBLE;
  strcpy(meta->sar->satellite_binary_time, MAGIC_UNSET_STRING);
  strcpy(meta->sar->satellite_clock_time, MAGIC_UNSET_STRING);
  doppler_params = vp->sensor.beam[0].doppler_centroid_parameters;
  // FIXME: Check units for higher coefficients
  meta->sar->range_doppler_coefficients[0] =
    doppler_params.doppler_centroid_coefficients.a[0];
  meta->sar->range_doppler_coefficients[1] =
    doppler_params.doppler_centroid_coefficients.a[1];
  meta->sar->range_doppler_coefficients[2] =
    doppler_params.doppler_centroid_coefficients.a[2];

  for (i=0; i<3; i++)
    meta->sar->azimuth_doppler_coefficients[i] = 0.0;
  meta->sar->azimuth_processing_bandwidth = 
    vp->gli_product.processor_bandwidth;
  meta->sar->chirp_rate = vp->sensor.beam[0].chirp_rate;
  meta->sar->pulse_duration = vp->sensor.beam[0].pulse_length;
  meta->sar->range_sampling_rate = vp->sensor.beam[0].sampling_freq;
  strcpy(meta->sar->polarization,
	 vp->sensor.beam[0].polarization_block.polarization[0].polarization);
  meta->sar->multilook = 1;
  meta->sar->pitch = vp->sensor.ephemeris.attitude.pitch;
  meta->sar->roll = vp->sensor.ephemeris.attitude.roll;
  meta->sar->yaw = vp->sensor.ephemeris.attitude.yaw;

  // Fill state vector structure
  nStVec = vp->sensor.ephemeris.sv_block.nr_sv;
  meta->state_vectors = meta_state_vectors_init(nStVec);
  date_dssr2date(vp->sensor.ephemeris.sv_block.state_vector[0].date, 
		 &ref_date, &ref_time);
  meta->state_vectors->year = ref_date.year;
  date_ymd2jd(&ref_date, &jd);
  meta->state_vectors->julDay = jd.jd;
  meta->state_vectors->second = date_hms2sec(&ref_time);
  meta->state_vectors->vector_count = nStVec;
  for (i=0; i<nStVec; i++) {
    date_dssr2date(vp->sensor.ephemeris.sv_block.state_vector[i].date, 
		   &ymd, &time);
    meta->state_vectors->vecs[i].time = 
      date_difference(&ref_date, &ref_time, &ymd, &time);
    meta->state_vectors->vecs[i].vec.pos.x = 
      vp->sensor.ephemeris.sv_block.state_vector[i].x;
    meta->state_vectors->vecs[i].vec.pos.y =
      vp->sensor.ephemeris.sv_block.state_vector[i].y;
    meta->state_vectors->vecs[i].vec.pos.z =
      vp->sensor.ephemeris.sv_block.state_vector[i].z;
    meta->state_vectors->vecs[i].vec.vel.x = 
      vp->sensor.ephemeris.sv_block.state_vector[i].xv;
    meta->state_vectors->vecs[i].vec.vel.y =
      vp->sensor.ephemeris.sv_block.state_vector[i].yv;
    meta->state_vectors->vecs[i].vec.vel.z =
      vp->sensor.ephemeris.sv_block.state_vector[i].zv;
  }
  date_dssr2date(vp->gli_product.first_line, &ymd, &time);
  double shift = date_difference(&ref_date, &ref_time, &ymd, &time);
  int sign;
  if (compare_time(&ymd, &time, &ref_date, &ref_time) > 0)
    sign = -1;
  else
    sign = 1;
  for (i=0; i<nStVec; i++)
    meta->state_vectors->vecs[i].time += sign * shift;
  meta->state_vectors->second = date_hms2sec(&time);
  double interval = 
    meta->general->line_count * meta->sar->azimuth_time_per_pixel / 2;
  propagate_state(meta, 3, interval);
  meta->sar->earth_radius = 
    meta_get_earth_radius(meta, meta->general->line_count/2, 
			  meta->general->sample_count/2);
  meta->sar->satellite_height = 
    meta_get_sat_height(meta, meta->general->line_count/2,
			meta->general->sample_count/2);  

  // Fill location block
  meta->location = meta_location_init();
  meta->location->lat_start_near_range =
    vp->gli_product.image_desc.coord.first_line_first_pixel.lat;
  meta->location->lon_start_near_range =
    vp->gli_product.image_desc.coord.first_line_first_pixel.lon;
  meta->location->lat_start_far_range =
    vp->gli_product.image_desc.coord.first_line_last_pixel.lat;
  meta->location->lon_start_far_range =
    vp->gli_product.image_desc.coord.first_line_last_pixel.lon;
  meta->location->lat_end_near_range =
    vp->gli_product.image_desc.coord.last_line_first_pixel.lat;
  meta->location->lon_end_near_range =
    vp->gli_product.image_desc.coord.last_line_first_pixel.lon;
  meta->location->lat_end_far_range =
    vp->gli_product.image_desc.coord.last_line_last_pixel.lat;
  meta->location->lon_end_far_range =
    vp->gli_product.image_desc.coord.last_line_last_pixel.lon;

  return meta;
}