Index: Source/Python/Classes/EcFlexpart.py
===================================================================
--- Source/Python/Classes/EcFlexpart.py	(revision c77630a97116cfe48788a474eaf76b1887d1479f)
+++ Source/Python/Classes/EcFlexpart.py	(revision 0f89116d0fc1de9b182758abd84208eb9c6933b5)
@@ -53,4 +53,8 @@
 #pylint: disable=consider-using-enumerate
 # this is not useful in this case
+#pylint: disable=unsubscriptable-object
+# this error is a bug
+#pylint: disable=ungrouped-imports
+# not necessary that we group the imports
 # ------------------------------------------------------------------------------
 # MODULES
@@ -62,13 +66,13 @@
 import glob
 import shutil
-import subprocess
 from datetime import datetime, timedelta
 
 # software specific classes and modules from flex_extract
+#pylint: disable=wrong-import-position
 sys.path.append('../')
 import _config
 from Classes.GribUtil import GribUtil
 from Mods.tools import (init128, to_param_id, silent_remove, product,
-                        my_error, make_dir, get_informations, get_dimensions,
+                        my_error, get_informations, get_dimensions,
                         execute_subprocess, to_param_id_with_tablenumber,
                         generate_retrieval_period_boundary)
@@ -76,5 +80,5 @@
 from Classes.UioFiles import UioFiles
 import Mods.disaggregation as disaggregation
-
+#pylint: enable=wrong-import-position
 # ------------------------------------------------------------------------------
 # CLASS
@@ -401,6 +405,6 @@
         else:  # GAUSS and ETA
             print('Warning: Collecting etadot and parameters for gaussian grid '
-                           'is a very costly parameter combination, '
-                           'use this combination only for debugging!')
+                  'is a very costly parameter combination, '
+                  'use this combination only for debugging!')
             self.params['GG__SL'] = ['Q', 'ML', '1',
                                      '{}'.format((int(self.resol) + 1) // 2)]
@@ -415,5 +419,5 @@
 
         # ADDITIONAL FIELDS FOR FLEXPART-WRF MODEL (IF QUESTIONED)
-        # -----------------------------------------------------------------------
+        # ----------------------------------------------------------------------
         if wrf:
             # @WRF
@@ -710,5 +714,6 @@
                     retr_param_dict['date'] = self.dates.split('/')[0]
                     retr_param_dict['target'] = self._mk_targetname('',
-                                            pk, retr_param_dict['date'])
+                                                                    pk,
+                                                                    retr_param_dict['date'])
                 elif pk == 'OG_OROLSM__SL' and oro:
                     continue
@@ -752,5 +757,5 @@
                         if 'acc' in pk:
                             startdate = retr_param_dict['date'].split('/')[0]
-                            enddate = datetime.strftime(elimit - t24h,'%Y%m%d')
+                            enddate = datetime.strftime(elimit - t24h, '%Y%m%d')
                             retr_param_dict['date'] = '/'.join([startdate,
                                                                 'to',
@@ -781,7 +786,7 @@
                         timesave = ''.join(retr_param_dict['time'])
 
-                        if ('/' in retr_param_dict['time'] and
-                            pk != 'OG_OROLSM__SL' and
-                            'acc' not in pk ) :
+                        if all(['/' in retr_param_dict['time'],
+                                pk != 'OG_OROLSM__SL',
+                                'acc' not in pk]):
                             times = retr_param_dict['time'].split('/')
                             steps = retr_param_dict['step'].split('/')
@@ -794,7 +799,7 @@
                                     retr_param_dict['time'] = times[0]
 
-                        if (pk != 'OG_OROLSM__SL' and
-                            int(retr_param_dict['step'].split('/')[0]) == 0 and
-                            int(timesave.split('/')[0]) == 0):
+                        if all([pk != 'OG_OROLSM__SL',
+                                int(retr_param_dict['step'].split('/')[0]) == 0,
+                                int(timesave.split('/')[0]) == 0]):
 
                             retr_param_dict['date'] = \
@@ -810,5 +815,5 @@
                     else:
                         raise ValueError('ERROR: Basetime has an invalid value '
-                                                 '-> {}'.format(str(basetime)))
+                                         '-> {}'.format(str(self.basetime)))
 
         if request == 0 or request == 2:
@@ -860,21 +865,21 @@
 
             stream = namelist_template.generate(
-                maxl = str(maxl),
-                maxb = str(maxb),
-                mlevel = str(self.level),
-                mlevelist = str(self.levelist),
-                mnauf = str(self.resol),
-                metapar = '77',
-                rlo0 = str(area[1]),
-                rlo1 = str(area[3]),
-                rla0 = str(area[2]),
-                rla1 = str(area[0]),
-                momega = str(c.omega),
-                momegadiff = str(c.omegadiff),
-                mgauss = str(c.gauss),
-                msmooth = str(c.smooth),
-                meta = str(c.eta),
-                metadiff = str(c.etadiff),
-                mdpdeta = str(c.dpdeta)
+                maxl=str(maxl),
+                maxb=str(maxb),
+                mlevel=str(self.level),
+                mlevelist=str(self.levelist),
+                mnauf=str(self.resol),
+                metapar='77',
+                rlo0=str(area[1]),
+                rlo1=str(area[3]),
+                rla0=str(area[2]),
+                rla1=str(area[0]),
+                momega=str(c.omega),
+                momegadiff=str(c.omegadiff),
+                mgauss=str(c.gauss),
+                msmooth=str(c.smooth),
+                meta=str(c.eta),
+                metadiff=str(c.etadiff),
+                mdpdeta=str(c.dpdeta)
             )
         except UndefinedError as e:
@@ -928,5 +933,5 @@
         '''
         import numpy as np
-        from eccodes import (codes_index_select, codes_new_from_index, codes_get,
+        from eccodes import (codes_index_select, codes_get,
                              codes_get_values, codes_set_values, codes_set,
                              codes_write, codes_release, codes_new_from_index,
@@ -1053,5 +1058,4 @@
             step = codes_get(gid, 'step') # integer
             ctime = '{:0>2}'.format(time)
-            cstep = '{:0>3}'.format(step)
 
             t_date = datetime.strptime(cdate + ctime, '%Y%m%d%H')
@@ -1132,5 +1136,5 @@
                     deac_vals[parId].append(
                         (orig_vals[parId][-1] - orig_vals[parId][-2]) /
-                         int(c.dtime))
+                        int(c.dtime))
 
                 # store precipitation if new disaggregation method is selected
@@ -1332,10 +1336,10 @@
             for inum in range(maxnum):
                 for ix in range(ni*nj):
-                    lsp_new_np[inum,ix,:] = disaggregation.IA3(lsp_np[inum,ix,:])[:-1]
-                    cp_new_np[inum,ix,:] = disaggregation.IA3(cp_np[inum,ix,:])[:-1]
+                    lsp_new_np[inum, ix, :] = disaggregation.IA3(lsp_np[inum, ix, :])[:-1]
+                    cp_new_np[inum, ix, :] = disaggregation.IA3(cp_np[inum, ix, :])[:-1]
         else:
             for ix in range(ni*nj):
-                lsp_new_np[0,ix,:] = disaggregation.IA3(lsp_np[ix,:])[:-1]
-                cp_new_np[0,ix,:] = disaggregation.IA3(cp_np[ix,:])[:-1]
+                lsp_new_np[0, ix, :] = disaggregation.IA3(lsp_np[ix, :])[:-1]
+                cp_new_np[0, ix, :] = disaggregation.IA3(cp_np[ix, :])[:-1]
 
         # write to grib files (full/orig times to flux file and inbetween
@@ -1402,44 +1406,50 @@
             # write original time step to flux file as usual
             fluxfile = GribUtil(os.path.join(c.inputdir, fluxfilename))
-            fluxfile.set_keys(tmpfile, filemode='ab', strict=True,
+            fluxfile.set_keys(tmpfile, filemode='ab',
                               wherekeynames=['paramId'], wherekeyvalues=[142],
-                              keynames=['perturbationNumber','date','time','stepRange','values'],
+                              keynames=['perturbationNumber', 'date', 'time',
+                                        'stepRange', 'values'],
                               keyvalues=[inumb, int(date.strftime('%Y%m%d')),
-                                         date.hour*100, 0, lsp_new_np[inumb,:,it]],
+                                         date.hour*100, 0, lsp_new_np[inumb, :, it]],
                              )
-            fluxfile.set_keys(tmpfile, filemode='ab', strict=True,
+            fluxfile.set_keys(tmpfile, filemode='ab',
                               wherekeynames=['paramId'], wherekeyvalues=[143],
-                              keynames=['perturbationNumber','date','time','stepRange','values'],
-                              keyvalues=[inumb,int(date.strftime('%Y%m%d')),
-                                         date.hour*100, 0, cp_new_np[inumb,:,it]]
+                              keynames=['perturbationNumber', 'date', 'time',
+                                        'stepRange', 'values'],
+                              keyvalues=[inumb, int(date.strftime('%Y%m%d')),
+                                         date.hour*100, 0, cp_new_np[inumb, :, it]]
                              )
 
             # rr for first subgrid point is identified by step = 1
-            fluxfile.set_keys(tmpfile, filemode='ab', strict=True,
+            fluxfile.set_keys(tmpfile, filemode='ab',
                               wherekeynames=['paramId'], wherekeyvalues=[142],
-                              keynames=['perturbationNumber','date','time','stepRange','values'],
-                              keyvalues=[inumb,int(date.strftime('%Y%m%d')),
-                                         date.hour*100, '1', lsp_new_np[inumb,:,it+1]]
-                              )
-            fluxfile.set_keys(tmpfile, filemode='ab', strict=True,
+                              keynames=['perturbationNumber', 'date', 'time',
+                                        'stepRange', 'values'],
+                              keyvalues=[inumb, int(date.strftime('%Y%m%d')),
+                                         date.hour*100, '1', lsp_new_np[inumb, :, it+1]]
+                             )
+            fluxfile.set_keys(tmpfile, filemode='ab',
                               wherekeynames=['paramId'], wherekeyvalues=[143],
-                              keynames=['perturbationNumber','date','time','stepRange','values'],
-                              keyvalues=[inumb,int(date.strftime('%Y%m%d')),
-                                         date.hour*100, '1', cp_new_np[inumb,:,it+1]]
-                              )
+                              keynames=['perturbationNumber', 'date', 'time',
+                                        'stepRange', 'values'],
+                              keyvalues=[inumb, int(date.strftime('%Y%m%d')),
+                                         date.hour*100, '1', cp_new_np[inumb, :, it+1]]
+                             )
 
             # rr for second subgrid point is identified by step = 2
-            fluxfile.set_keys(tmpfile, filemode='ab', strict=True,
+            fluxfile.set_keys(tmpfile, filemode='ab',
                               wherekeynames=['paramId'], wherekeyvalues=[142],
-                              keynames=['perturbationNumber','date','time','stepRange','values'],
-                              keyvalues=[inumb,int(date.strftime('%Y%m%d')),
-                                         date.hour*100, '2', lsp_new_np[inumb,:,it+2]]
-                              )
-            fluxfile.set_keys(tmpfile, filemode='ab', strict=True,
+                              keynames=['perturbationNumber', 'date', 'time',
+                                        'stepRange', 'values'],
+                              keyvalues=[inumb, int(date.strftime('%Y%m%d')),
+                                         date.hour*100, '2', lsp_new_np[inumb, :, it+2]]
+                             )
+            fluxfile.set_keys(tmpfile, filemode='ab',
                               wherekeynames=['paramId'], wherekeyvalues=[143],
-                              keynames=['perturbationNumber','date','time','stepRange','values'],
-                              keyvalues=[inumb,int(date.strftime('%Y%m%d')),
-                                         date.hour*100, '2', cp_new_np[inumb,:,it+2]]
-                              )
+                              keynames=['perturbationNumber', 'date', 'time',
+                                        'stepRange', 'values'],
+                              keyvalues=[inumb, int(date.strftime('%Y%m%d')),
+                                         date.hour*100, '2', cp_new_np[inumb, :, it+2]]
+                             )
 
             it = it + 3 # jump to next original time step in rr fields
@@ -1463,11 +1473,11 @@
         '''
 
-        gribfile = GribUtil(os.path.join(inputdir,'rr_grib_dummy.grb'))
+        gribfile = GribUtil(os.path.join(inputdir, 'rr_grib_dummy.grb'))
 
         gribfile.copy_dummy_msg(ifile, keynames=['paramId'],
-                      keyvalues=[142], filemode='wb')
+                                keyvalues=[142], filemode='wb')
 
         gribfile.copy_dummy_msg(ifile, keynames=['paramId'],
-                      keyvalues=[143], filemode='ab')
+                                keyvalues=[143], filemode='ab')
 
         return
@@ -1501,5 +1511,5 @@
 
         '''
-        from eccodes import (codes_index_select, codes_new_from_index, codes_get,
+        from eccodes import (codes_index_select, codes_get,
                              codes_get_values, codes_set_values, codes_set,
                              codes_write, codes_release, codes_new_from_index,
@@ -1583,20 +1593,18 @@
             cdate_hour = datetime.strftime(timestamp, '%Y%m%d%H')
 
+            # if basetime is used, adapt start/end date period
+            if c.basetime is not None:
+                time_delta = timedelta(hours=12-int(c.dtime))
+                start_period = datetime.strptime(c.end_date + str(c.basetime),
+                                               '%Y%m%d%H') - time_delta
+                end_period = datetime.strptime(c.end_date + str(c.basetime),
+                                             '%Y%m%d%H')
+
             # skip all temporary times
-            # which are outside the retrieval period
+            # which are outside the retrieval period                
             if timestamp < start_period or \
                timestamp > end_period:
                 continue
-
-            # if the timestamp is out of basetime start/end date period,
-            # skip this specific product
-            if c.basetime is not None:
-                time_delta = timedelta(hours=12-int(c.dtime))
-                start_time = datetime.strptime(c.end_date + str(c.basetime),
-                                                '%Y%m%d%H') - time_delta
-                end_time = datetime.strptime(c.end_date + str(c.basetime),
-                                             '%Y%m%d%H')
-                if timestamp < start_time or timestamp > end_time:
-                    continue
+                
 
             # @WRF
@@ -1620,5 +1628,4 @@
                 paramId = codes_get(gid, 'paramId')
                 gridtype = codes_get(gid, 'gridType')
-                levtype = codes_get(gid, 'typeOfLevel')
                 if paramId == 77: # ETADOT
                     codes_write(gid, fdict['21'])
@@ -1704,5 +1711,5 @@
             # Fortran program creates file fort.15 (with u,v,etadot,t,sp,q)
             execute_subprocess([os.path.join(c.exedir,
-                                _config.FORTRAN_EXECUTABLE)],
+                                             _config.FORTRAN_EXECUTABLE)],
                                error_msg='FORTRAN PROGRAM FAILED!')#shell=True)
 
@@ -1733,5 +1740,7 @@
             # to the outputfile (final GRIB input files for FLEXPART)
             orolsm = os.path.basename(glob.glob(c.inputdir +
-                                        '/OG_OROLSM__SL.*.' + c.ppid + '*')[0])
+                                                '/OG_OROLSM__SL.*.' +
+                                                c.ppid +
+                                                '*')[0])
             fluxfile = 'flux' + cdate[0:2] + suffix
             if not c.cwc:
@@ -1783,6 +1792,6 @@
         '''
         from eccodes import (codes_grib_new_from_file, codes_get_array,
-                             codes_set_array, codes_release, codes_set_values,
-                             codes_set, codes_write, codes_release)
+                             codes_set_array, codes_release,
+                             codes_set, codes_write)
 
         # max number
@@ -1790,10 +1799,10 @@
 
         # get a list of all prepared output files with control forecast (CF)
-        CF_filelist = UioFiles(path, prefix + '*.N000')
-        CF_filelist.files = sorted(CF_filelist.files)
-
-        for cffile in CF_filelist.files:
+        cf_filelist = UioFiles(path, prefix + '*.N000')
+        cf_filelist.files = sorted(cf_filelist.files)
+
+        for cffile in cf_filelist.files:
             with open(cffile, 'rb') as f:
-                cfvalues=[]
+                cfvalues = []
                 while True:
                     fid = codes_grib_new_from_file(f)
@@ -1900,3 +1909,2 @@
 
         return
-
