Skip to content

Commit

Permalink
i.modis: fix python3 issues (#88)
Browse files Browse the repository at this point in the history
* fix rmodislib python3 issue dict_keys -> list

* fix other issues (string.find(), iteritems())
  • Loading branch information
landam committed Feb 11, 2020
1 parent 2925183 commit 0ad5a2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
7 changes: 3 additions & 4 deletions grass7/imagery/i.modis/i.modis.import/i.modis.import.py
Expand Up @@ -107,7 +107,6 @@

import os
import sys
import string
import glob
import shutil
import grass.script as grass
Expand Down Expand Up @@ -155,10 +154,10 @@ def list_files(opt, mosaik=False):
filelist = []
# append hdf files
for line in listoffile:
if string.find(line, 'xml') == -1 and mosaik is False:
if line.find('xml') == -1 and mosaik is False:
filelist.append(line.strip())
# for mosaic create a list of hdf files for each day
elif string.find(line, 'xml') == -1 and mosaik is True:
elif line.find('xml') == -1 and mosaik is True:
day = line.split('/')[-1].split('.')[1]
if day in filelist:
filelist[day].append(line.strip())
Expand Down Expand Up @@ -410,7 +409,7 @@ def mosaic(options, remove, an, ow, fil):
dictfile, targetdir = list_files(options, True)
pid = str(os.getpid())
# for each day
for dat, listfiles in dictfile.iteritems():
for dat, listfiles in dictfile.items():
pref = listfiles[0].split('/')[-1]
prod = product().fromcode(pref.split('.')[0])
spectr = spectral(options, prod, an)
Expand Down
17 changes: 8 additions & 9 deletions grass7/imagery/i.modis/libmodis/rmodislib.py
Expand Up @@ -299,22 +299,21 @@ def __init__(self, value=None):
}

def returned(self):
if self.products.keys().count(self.prod) == 1:
if list(self.products.keys()).count(self.prod) == 1:
return self.products[self.prod]
elif self.products_swath.keys().count(self.prod) == 1:
elif list(self.products_swath.keys()).count(self.prod) == 1:
return self.products_swath[self.prod]
else:
grass.fatal(_("The MODIS product inserted is not supported yet. "
"Consider to ask on the grass-dev mailing list "
"for future support"))

def fromcode(self, code):
import string
for k, v in self.products.iteritems():
if string.find(v['prod'], code) != -1:
for k, v in self.products.items():
if v['prod'].find(code) != -1:
return self.products[k]
for k, v in self.products_swath.iteritems():
if string.find(v['prod'], code) != -1:
for k, v in self.products_swath.items():
if v['prod'].find(code) != -1:
return self.products_swath[k]
grass.fatal(_("The MODIS product inserted is not supported yet. "
"Consider to ask on the grass-dev mailing list "
Expand Down Expand Up @@ -343,9 +342,9 @@ def print_prods(self):
def __str__(self):
prod = self.returned()
string = "product: " + prod['prod'] + ", url: " + prod['url']
if prod.keys().count('spec') == 1:
if list(prod.keys()).count('spec') == 1:
string += ", spectral_subset: " + prod['spec']
if prod.keys().count('spec_qa') == 1:
if list(prod.keys()).count('spec_qa') == 1:
if prod['spec_qa'] != None:
string += ", spectral_subset_qa:" + prod['spec_qa']
return string
Expand Down

0 comments on commit 0ad5a2e

Please sign in to comment.