l2gen on landsat 8 collection 2
Posted: Sun Feb 19, 2023 3:30 am America/New_York
Hello, I've encountered some issues recently while processing Landsat 8 Collection 2 data using the source code. It seems like Landsat 8 band 9 is not being read? While examining the l1_oli.c code, I noticed that band 9 is not being read during the band reading process.
It's also possible that my understanding is incorrect. Could you please take a look?
int readl1_oli(filehandle *file, int recnum, l1str *l1rec, int lonlat)
-----------------------code-----------------------
567 // int y = 0;
568 int y_in_tile = 0;
569
570 if (tile_exist != 0) {
571 // y = recnum / tileLength;
572 y_in_tile = recnum % tileLength;
573 if (data->line_num_cached == -1 || recnum < data->line_num_cached || recnum >= (data->line_num_cached + tileLength)) {
574 int y = recnum / tileLength;
575 data->line_num_cached = y * tileLength;
576 for (ib = 0; ib <= file->nbands; ib++) {
577 for (int x = 0; x < imageWidth; x += tileWidth) {
578 if (TIFFReadTile(data->tif[ib], (void*) (data->buf_tile_row + ib * imageWidth * tileLength + x * tileLength), x, y * tileLength, 0, 0) == -1) {
579 fprintf(stderr, "-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
580 __FILE__, __LINE__, ib, recnum);
581 exit(1);
582 }
583 }
584 }
585 }
586 }
-----------------------code-----------------------
file->nbands = 7, so band 9 not be read in buf_tile_row
But later on in the code, band 9 is being called.
-----------------------code-----------------------
629 // read Cirrus Band 9
630
631 ib = 8;
632
633 if (tile_exist == 0) {
634 if (TIFFReadScanline(data->tif[ib], (void*) data->buf, recnum, 0) == -1) {
635 fprintf(stderr, "-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
636 __FILE__, __LINE__, ib, recnum);
637 exit(1);
638 }
639 } else {
640 for (int x = 0; x < imageWidth; x += tileWidth) {
641 if ((imageWidth - x) >= tileWidth) {
642 _TIFFmemcpy((void*) (data->buf + x), (void*) (data->buf_tile_row + ib * imageWidth * tileLength + x * tileLength + y_in_tile * tileWidth), tileWidth * 2);
643 }
644 else
645 _TIFFmemcpy((void*) (data->buf + x), (void*) (data->buf_tile_row + ib * imageWidth * tileLength + x * tileLength + y_in_tile * tileWidth), (imageWidth - x) * 2);
646 }
647 }
-----------------------code-----------------------
It's also possible that my understanding is incorrect. Could you please take a look?
int readl1_oli(filehandle *file, int recnum, l1str *l1rec, int lonlat)
-----------------------code-----------------------
567 // int y = 0;
568 int y_in_tile = 0;
569
570 if (tile_exist != 0) {
571 // y = recnum / tileLength;
572 y_in_tile = recnum % tileLength;
573 if (data->line_num_cached == -1 || recnum < data->line_num_cached || recnum >= (data->line_num_cached + tileLength)) {
574 int y = recnum / tileLength;
575 data->line_num_cached = y * tileLength;
576 for (ib = 0; ib <= file->nbands; ib++) {
577 for (int x = 0; x < imageWidth; x += tileWidth) {
578 if (TIFFReadTile(data->tif[ib], (void*) (data->buf_tile_row + ib * imageWidth * tileLength + x * tileLength), x, y * tileLength, 0, 0) == -1) {
579 fprintf(stderr, "-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
580 __FILE__, __LINE__, ib, recnum);
581 exit(1);
582 }
583 }
584 }
585 }
586 }
-----------------------code-----------------------
file->nbands = 7, so band 9 not be read in buf_tile_row
But later on in the code, band 9 is being called.
-----------------------code-----------------------
629 // read Cirrus Band 9
630
631 ib = 8;
632
633 if (tile_exist == 0) {
634 if (TIFFReadScanline(data->tif[ib], (void*) data->buf, recnum, 0) == -1) {
635 fprintf(stderr, "-E- %s line %d: Failed to read Lt, band %d, recnum %d\n",
636 __FILE__, __LINE__, ib, recnum);
637 exit(1);
638 }
639 } else {
640 for (int x = 0; x < imageWidth; x += tileWidth) {
641 if ((imageWidth - x) >= tileWidth) {
642 _TIFFmemcpy((void*) (data->buf + x), (void*) (data->buf_tile_row + ib * imageWidth * tileLength + x * tileLength + y_in_tile * tileWidth), tileWidth * 2);
643 }
644 else
645 _TIFFmemcpy((void*) (data->buf + x), (void*) (data->buf_tile_row + ib * imageWidth * tileLength + x * tileLength + y_in_tile * tileWidth), (imageWidth - x) * 2);
646 }
647 }
-----------------------code-----------------------