CNES / MAJA

Level-2A processor used for atmospheric correction and cloud-detection. The active repository is the one below, this one is kept to leave access to the older issues.
https://gitlab.orfeo-toolbox.org/maja/maja
Apache License 2.0
137 stars 25 forks source link

OSError when a image is too cloudy #23

Closed borlafgis closed 5 years ago

borlafgis commented 5 years ago

I have been working a bit with MAJA v3.3, and I have had a small problem with start_maja. When there is an image that is too cloudy the execution stops throwing the following error

Traceback (most recent call last):
  File "./start_maja.py", line 655, in <module>
    start_maja(folder_file, gipp, lut, site, tile, orbit, nb_backward, options, debug_mode)
  File "./start_maja.py", line 555, in start_maja
    valid = test_valid_L2A(nomL2init_MUSCATE[0])
  File "./start_maja.py", line 226, in test_valid_L2A
    os.rename(L2A_DIR, dir_name+"/L2NOTV_"+prod_name)
OSError: [Errno 13] Permission denied

I think this happens within the function test_valid_L2A because it tries to rename the parent directory while the metadata is still open by python, (JPIfile).

In my case I modified the function like this to avoid the error:

def test_valid_L2A(L2A_DIR):
    # test validity of a Level2A product of MUSCATE type
    JPIfile = glob.glob("%s/DATA/*_JPI_ALL.xml" % L2A_DIR.replace('[', '[[]'))[0]
    valid = True
    try:
        with open(JPIfile) as f:
            for ligne in f:
                if ligne.find("<Value>L2NOTV</Value>") >= 0:
                    valid = False

        if valid is False:
            prod_name = os.path.basename(L2A_DIR)
            dir_name = os.path.dirname(L2A_DIR)
            if not(os.path.exists(dir_name+"/L2NOTV_"+prod_name)):
                os.rename(L2A_DIR, dir_name+"/L2NOTV_"+prod_name)
            else:
                shutil.rmtree(dir_name+"/L2NOTV_"+prod_name)
                os.rename(L2A_DIR, dir_name+"/L2NOTV_"+prod_name)
            print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
            print(
                "L2A product %s is not valid (probably due to too many clouds or No_data values)" % dir_name)
            print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")

    except IOError:
        valid = False
        print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
        print("L2A product %s not found " % L2A_DIR)
        print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")

    return(valid)

Hope this is useful, Ignacio

olivierhagolle commented 5 years ago

Hi, Ignacio, I do not have the error, but the correction makes sense. I'll test it a bit and then update Thanks, Olivier

borlafgis commented 5 years ago

Hello again

I forgot to mention the context: the ubuntu (v16.04) subsystem of windows 10, so MAJA sort of works on windows now :)

Kind regards, Ignacio