Page 1 of 1

l2gen on landsat 8 collection 2

Posted: Sun Feb 19, 2023 3:30 am America/New_York
by lvxiaoning
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-----------------------

Re: l2gen on landsat 8 collection 2

Posted: Sat Feb 25, 2023 8:17 pm America/New_York
by lvxiaoning
I found that this problem occurred because I modified the pixel values of the band 9 image when I was processing Landsat 8. However, I noticed that these modifications were not being read. Could you please confirm if this problem really exists?

Re: l2gen on landsat 8 collection 2

Posted: Mon Feb 27, 2023 10:59 am America/New_York
by OB.DAAC - SeanBailey
The code is reading band 9, but it does not treat the band as it does other TOA data. It is read directly into a record specifically assigned to rho_cirrus. This is done because the cirrus channel cannot be treated the same as the other TOA bands. If you want to see the output from l2gen, you will need to look at the rho_cirrus band, not the rhot or Lt bands.

Sean

Re: l2gen on landsat 8 collection 2

Posted: Mon Feb 27, 2023 6:39 pm America/New_York
by lvxiaoning
Thanks, Sean. I know that band 9 is used as rho_cirrus, but the premise is that we first read the data of band 9 into data->buf_tile_row. However, when nbands=7, this code only reads the data of band 8 (and even has not finished reading it, as the data volume of band 8 is twice that of other bands). It seems that band 9 has not been read. Only when nbands=8, band 9 will be read. However, I noticed that the value assigned to nbands is 7, so that's why I raised this question.

Re: l2gen on landsat 8 collection 2

Posted: Tue Feb 28, 2023 2:29 am America/New_York
by lvxiaoning
Hello, Sean. I can now confirm that there is an issue with this code. I downloaded SeaDAS 8.3 and OCSSW V2022.3 on Ubuntu 22.04, and processed an image of Landsat 8 collection 2, with the ID LC08_L1TP_119038_20130325_20200913_02_T1. I added the rho_cirrus option when running l2gen, but the output for rho_cirrus is completely wrong, with only values on the two edges and blank values in the middle.

Re: l2gen on landsat 8 collection 2

Posted: Wed Mar 01, 2023 9:46 am America/New_York
by lvxiaoning
Maybe something worry in band 9.

Re: l2gen on landsat 8 collection 2

Posted: Wed Mar 01, 2023 4:45 pm America/New_York
by OB SeaDAS - xuanyang02
We replicated the error and are looking into the issue. Thanks for reporting the bug.

Re: l2gen on landsat 8 collection 2

Posted: Thu Mar 02, 2023 9:32 pm America/New_York
by OB SeaDAS - xuanyang02
You are right that Band 9 needs to be read into the buffer (line 578) before Cirrus Band 9 can be read correctly at line 629. We fixed the bug and l2gen produced a valid rho_cirrus image.

Thanks again for reporting the bug.