It runs without problem but I don't get the expected pca bands, my output folder is empty, I don't know what to test.

path ='C/Users/Manuel/Documents/INPUT'

bandList = [band for band in 
            os.listdir(path) if 
input = [os.path.join(path,band)for band in bandList]

def PCA_GRASS(input,output):
    {'-f': False,'n':False,\
    'input': input,\
    'output': output,\
    'percent': 99,\
  outList=[band for band in os.listdir(output) if 
  new_output = [ os.path.join(output,band) for band in 
                               outList ]
  for band in new_output:


When I run the script I open log message and an ogr error appears (can't open _ address of input files_) I don't understand why (https://i.stack.imgur.com/oAv4s.jpg)

I am working with Landsat 8 band and I have tried other images to see if the code works. Using processing whit grass I have performed other tasks satisfactorily but this one is causing me many problems. The images are not the problem when I perform the operation (i.pca) from the processing toolbox, it is done without problem.

I have also changed the syntax with which I enter the input data but nothing.


Your code have several issues. I fixed them in following code but with only two raster layers (for time processing reasons):

import processing
import os

path =  '/home/zeito/Desktop/INPUT'
output = '/home/zeito/Desktop/OUTPUT'

bandList = [band for band in 
            os.listdir(path) if 
            band[-4:]=='.tif'] #I changed for 'tif'

input = [ os.path.join(path, band) for band in bandList ]

def PCA_GRASS(input, output):
    {'-f': False,
     'input': input, 
     'output': output,
     'percent': 99,
    outList = [band for band in 
               os.listdir(output) if 
               band[-4:]=='.tif'] #I changed for 'tif'
    new_output = [ os.path.join(output, band) for band in outList ]
    for band in new_output:
        iface.addRasterLayer(band, band)

PCA_GRASS(input, output)

After running above script, it loads two raster layers rescaled between [0,400] as expected. It can be observed in following image:

enter image description here

  • change the code, but it follows empty output folder and does not add any band to iface, it runs without error but does not give any results, I don't know what else to try, thanks for your time Apr 23 '20 at 21:02
  • I already changed, it try to upload an img but I could not, again thanks for your time Apr 23 '20 at 22:56
  • it remains with the same problem my output folder is empty Apr 29 '20 at 2:50
  • But in my case it works perfectly. You only need to try in this script a few things; not to create a class for a new script in another question. For example, to change paths as follows: path = 'D:/ESCUELA/JORNADA_CIENT_ALL/clip_L8' or to use only two single raster in folder D:/ESCUELA/JORNADA_CIENT_ALL/clip_L8.
    – xunilk
    Apr 29 '20 at 3:04
  • It could also be your raster layers are not perfectly aligned.
    – xunilk
    Apr 29 '20 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.