diff --git a/source/python/__init__.py b/source/python/__init__.py index 4609bf2c36fe073fdb731fa34a23fa45990e8b57..c44e32301dd7d73dac05abfef800984e01266407 100644 --- a/source/python/__init__.py +++ b/source/python/__init__.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Philipp (University of Vienna) diff --git a/source/python/_config.py b/source/python/_config.py index 9354d080926e35c96859c3aeda955815d98fdb89..6a9aee1eaf9d827bf86a908c40aac2774121b423 100644 --- a/source/python/_config.py +++ b/source/python/_config.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Philipp (University of Vienna) diff --git a/source/python/classes/ControlFile.py b/source/python/classes/ControlFile.py index f6c4353f92290d6508435879470fce3893a575bf..48026ad08a905dc1b3855a2e17d0b1d2f80d86da 100644 --- a/source/python/classes/ControlFile.py +++ b/source/python/classes/ControlFile.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Leopold Haimberger (University of Vienna) @@ -552,7 +552,7 @@ class ControlFile(object): if args_dict[k] != None} # assign all passed command line arguments to ControlFile instance - for k, v in arguments.iteritems(): + for k, v in arguments.items(): setattr(self, str(k), v) return @@ -572,7 +572,7 @@ class ControlFile(object): ''' - for k, v in envs.iteritems(): + for k, v in envs.items(): setattr(self, str(k).lower(), str(v)) return diff --git a/source/python/classes/EcFlexpart.py b/source/python/classes/EcFlexpart.py index 8213bf26425a527eeb0c4262374a0ee1ba1cc4dc..c52aa680de6873addc1efa1ec7e0b4df8f2976b4 100644 --- a/source/python/classes/EcFlexpart.py +++ b/source/python/classes/EcFlexpart.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Fouilloux (University of Oslo) @@ -277,7 +277,7 @@ class EcFlexpart(object): ''' i = 0 for ty, st, ti in zip(ftype, fstep, ftime): - btlist = range(len(ftime)) + btlist = list(range(len(ftime))) if self.basetime == 12: btlist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] if self.basetime == 0: @@ -397,8 +397,8 @@ class EcFlexpart(object): if not gauss and eta: self.params['OG__ML'][0] += '/U/V/ETADOT' elif gauss and not eta: - self.params['GG__SL'] = ['Q', 'ML', '1', \ - '{}'.format((int(self.resol) + 1) / 2)] + self.params['GG__SL'] = ['Q', 'ML', '1', + '{}'.format((int(self.resol) + 1) // 2)] self.params['SH__ML'] = ['U/V/D', 'ML', self.glevelist, 'OFF'] elif not gauss and not eta: self.params['OG__ML'][0] += '/U/V' @@ -407,9 +407,9 @@ class EcFlexpart(object): '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)] + '{}'.format((int(self.resol) + 1) // 2)] self.params['GG__ML'] = ['U/V/D/ETADOT', 'ML', self.glevelist, - '{}'.format((int(self.resol) + 1) / 2)] + '{}'.format((int(self.resol) + 1) // 2)] if omega: self.params['OG__ML'][0] += '/W' @@ -667,7 +667,7 @@ class EcFlexpart(object): for ftype in self.types: # ftype contains field types such as # [AN, FC, PF, CV] - for pk, pv in self.params.iteritems(): + for pk, pv in self.params.items(): # pk contains one of these keys of params # [SH__ML, SH__SL, GG__ML, GG__SL, OG__ML, OG__SL, # OG_OROLSM_SL, OG_acc_SL] @@ -992,7 +992,7 @@ class EcFlexpart(object): # create correct timestamp from the three time informations cdate = str(codes_get(gid, 'date')) - time = codes_get(gid, 'time')/100 # integer + time = codes_get(gid, 'time') // 100 # integer step = codes_get(gid, 'step') # integer ctime = '{:0>2}'.format(time) cstep = '{:0>3}'.format(step) @@ -1254,7 +1254,10 @@ class EcFlexpart(object): # write to grib files (full/orig times to flux file and inbetween # times into seperate end files) print('... write disaggregated precipitation to files.') + # index variable of disaggregated fields it = 0 + # loop over times and write original time step and the two newly + # generated sub time steps for each loop for date in date_list: for step in step_list: tmpfile = os.path.join(c.inputdir, 'rr_grib_dummy.grb') @@ -1433,14 +1436,14 @@ class EcFlexpart(object): #============================================================================================ # remove old fort.* files and open new ones # they are just valid for a single product - for k, f in fdict.iteritems(): + for k, f in fdict.items(): fortfile = os.path.join(c.inputdir, 'fort.' + k) silent_remove(fortfile) fdict[k] = open(fortfile, 'w') #============================================================================================ # create correct timestamp from the three time informations cdate = str(codes_get(gid, 'date')) - ctime = '{:0>2}'.format(codes_get(gid, 'time')/100) + ctime = '{:0>2}'.format(codes_get(gid, 'time') // 100) cstep = '{:0>3}'.format(codes_get(gid, 'step')) timestamp = datetime.strptime(cdate + ctime, '%Y%m%d%H') timestamp += timedelta(hours=int(cstep)) diff --git a/source/python/classes/GribUtil.py b/source/python/classes/GribUtil.py index dd99828fffe52f52154829e2540a123468f36cb2..fdb25ea7faf1a8512f0e56e1235bd675bba55c64 100644 --- a/source/python/classes/GribUtil.py +++ b/source/python/classes/GribUtil.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Fouilloux (University of Oslo) diff --git a/source/python/classes/MarsRetrieval.py b/source/python/classes/MarsRetrieval.py index 76f4a22cdecf7fa3fa5e8ca043a6ee717a9044fb..20f585fb9d05c972f3520bb79f1d91c766cbab65 100644 --- a/source/python/classes/MarsRetrieval.py +++ b/source/python/classes/MarsRetrieval.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Fouilloux (University of Oslo) @@ -433,7 +433,7 @@ class MarsRetrieval(object): _config.FILE_MARS_REQUESTS), 'a') as f: f.write(str(request_number) + ', ') f.write(', '.join(str(attrs[key]) - for key in sorted(attrs.iterkeys()))) + for key in sorted(attrs.keys()))) f.write('\n') return @@ -473,7 +473,7 @@ class MarsRetrieval(object): # find all keys without a value and convert all other values to strings empty_keys = [] - for key, value in attrs.iteritems(): + for key, value in attrs.items(): if value == '': empty_keys.append(str(key)) else: @@ -510,7 +510,7 @@ class MarsRetrieval(object): # MARS request via call in shell else: request_str = 'ret' - for key, value in attrs.iteritems(): + for key, value in attrs.items(): request_str = request_str + ',' + key + '=' + str(value) request_str += ',target="' + target + '"' p = subprocess.Popen(['mars', '-p'], @@ -518,7 +518,7 @@ class MarsRetrieval(object): stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1) - pout = p.communicate(input=request_str)[0] + pout = p.communicate(input=request_str.encode())[0] print(pout.decode()) if 'Some errors reported' in pout.decode(): diff --git a/source/python/classes/UioFiles.py b/source/python/classes/UioFiles.py index 3cca0df663e00657df3bbf7e976263252279b226..4023d8b3c7a433b8ca0af1c284bf19d0f4689c3c 100644 --- a/source/python/classes/UioFiles.py +++ b/source/python/classes/UioFiles.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Fouilloux (University of Oslo) diff --git a/source/python/classes/__init__.py b/source/python/classes/__init__.py index 4609bf2c36fe073fdb731fa34a23fa45990e8b57..c44e32301dd7d73dac05abfef800984e01266407 100644 --- a/source/python/classes/__init__.py +++ b/source/python/classes/__init__.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Philipp (University of Vienna) diff --git a/source/python/install.py b/source/python/install.py index 395d1ac75ec412042da2e8b3f1e701bcf8919158..417329a7fdccedb19bb42fea9458979c44dc8cf1 100755 --- a/source/python/install.py +++ b/source/python/install.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Leopold Haimberger (University of Vienna) @@ -366,17 +366,9 @@ def mk_tarball(tarball_path, target): if os.path.splitext(tarinfo.name)[1] in exclude_files else tarinfo) - except subprocess.CalledProcessError as e: - print('... ERROR CODE:\n ... ' + str(e.returncode)) - print('... ERROR MESSAGE:\n ... ' + str(e)) - - sys.exit('\n... could not make installation tar ball!') - except OSError as e: - print('... ERROR CODE: ' + str(e.errno)) - print('... ERROR MESSAGE:\n \t ' + str(e.strerror)) - - sys.exit('\n... error occured while trying to read tar-file ' + - str(tarball_path)) + except tarfile.TarError as e: + sys.exit('\n... error occured while trying to create the tar-file ' + + str(tarball_path)) return @@ -677,9 +669,9 @@ def mk_convert_build(src_path, makefile): stderr=subprocess.PIPE, bufsize=1) pout, perr = p.communicate() - print(pout) + print(pout.decode()) if p.returncode != 0: - print(perr) + print(perr.decode()) print('Please edit ' + makefile + ' or try another Makefile in the src directory.') print('Most likely GRIB_API_INCLUDE_DIR, GRIB_API_LIB ' diff --git a/source/python/mods/__init__.py b/source/python/mods/__init__.py index 4609bf2c36fe073fdb731fa34a23fa45990e8b57..c44e32301dd7d73dac05abfef800984e01266407 100644 --- a/source/python/mods/__init__.py +++ b/source/python/mods/__init__.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Philipp (University of Vienna) diff --git a/source/python/mods/checks.py b/source/python/mods/checks.py index 97c27b8ad6569b11f9da9228796c4eb5ae74e95e..434a42a7cb33439fe626562fbd667fb92dbfa56a 100644 --- a/source/python/mods/checks.py +++ b/source/python/mods/checks.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Philipp (University of Vienna) @@ -30,9 +30,9 @@ try: import exceptions except ImportError: import builtins as exceptions -from .tools import my_error, silent_remove from datetime import datetime import numpy as np +from .tools import my_error, silent_remove # ------------------------------------------------------------------------------ # FUNCTIONS # ------------------------------------------------------------------------------ diff --git a/source/python/mods/disaggregation.py b/source/python/mods/disaggregation.py index 5407ca1c8481ada9c95d56e379f48604497eead2..a5d36ca3612f8cf7e4468728c6b98041c9eebb9d 100644 --- a/source/python/mods/disaggregation.py +++ b/source/python/mods/disaggregation.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Philipp (University of Vienna) diff --git a/source/python/mods/get_mars_data.py b/source/python/mods/get_mars_data.py index 6dc9dd04e8e0d4ee6164c3accf2861803a66d23e..56e6b3c4bb0bd257e13ebfbdb12d56e66c2287e3 100755 --- a/source/python/mods/get_mars_data.py +++ b/source/python/mods/get_mars_data.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Fouilloux (University of Oslo) @@ -175,7 +175,7 @@ def write_reqheader(marsfile): del attrs['public'] with open(marsfile, 'w') as f: f.write('request_number' + ', ') - f.write(', '.join(str(key) for key in sorted(attrs.iterkeys()))) + f.write(', '.join(str(key) for key in sorted(attrs.keys()))) f.write('\n') return diff --git a/source/python/mods/prepare_flexpart.py b/source/python/mods/prepare_flexpart.py index b55494492b6a85c68c67347a6924e14c06feb5e0..0d6cfe8ce672124d1aa9256145bd2103cd6331f3 100755 --- a/source/python/mods/prepare_flexpart.py +++ b/source/python/mods/prepare_flexpart.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Fouilloux (University of Oslo) diff --git a/source/python/mods/profiling.py b/source/python/mods/profiling.py index a20cad6d0c0c51b5868b045e9e56c74c80b88d11..c4c79d17f3d882df6be44a4bae37e43d473bb729 100644 --- a/source/python/mods/profiling.py +++ b/source/python/mods/profiling.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #************************************************************************ # ToDo AP @@ -65,7 +65,7 @@ def timefn(fn): t1 = time.time() result = fn(*args, **kwargs) t2 = time.time() - print("@timefn:" + fn.func_name + " took " + str(t2 - t1) + " seconds") + print("@timefn:" + fn.__name__ + " took " + str(t2 - t1) + " seconds") return result diff --git a/source/python/mods/tools.py b/source/python/mods/tools.py index 2cd1ec9ab87afd54911cb6becb73cde9229e754f..f8eb0ab127abc4221c107c87fac0735c20797f88 100644 --- a/source/python/mods/tools.py +++ b/source/python/mods/tools.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Philipp (University of Vienna) @@ -367,7 +367,7 @@ def send_mail(users, success_mode, message): stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1) - pout = p.communicate(input=message + '\n\n')[0] + pout = p.communicate(input=message.encode() + '\n\n')[0] except ValueError as e: print('... ERROR: ' + str(e)) sys.exit('... Email could not be sent!') @@ -432,7 +432,7 @@ def product(*args, **kwds): See example in description above. ''' try: - pools = map(tuple, args) * kwds.get('repeat', 1) + pools = [tuple(arg) for arg in args] * kwds.get('repeat', 1) result = [[]] for pool in pools: result = [x + [y] for x in result for y in pool] @@ -532,7 +532,7 @@ def to_param_id(pars, table): cpar = pars.upper().split('/') ipar = [] for par in cpar: - for k, v in table.iteritems(): + for k, v in table.items(): if par == k or par == v: ipar.append(int(k)) break @@ -573,7 +573,7 @@ def to_param_id_with_tablenumber(pars, table): cpar = pars.upper().split('/') spar = [] for par in cpar: - for k, v in table.iteritems(): + for k, v in table.items(): if par == k or par == v: spar.append(k + '.128') break @@ -725,7 +725,7 @@ def submit_job_to_ecserver(target, jobname): print('\n... Most likely the ECACCESS library is not available!') sys.exit('... ECACCESS-JOB-SUBMIT FAILED!') - return job_id + return job_id.decode() def get_informations(filename): @@ -826,7 +826,7 @@ def get_dimensions(info, purefc, dtime, index_vals, start_date, end_date): jy = info['Nj'] if not purefc: - it = ((end_date - start_date).days + 1) * 24/int(dtime) + it = ((end_date - start_date).days + 1) * 24 // int(dtime) else: # #no of step * #no of times * #no of days it = len(index_vals[2]) * len(index_vals[1]) * len(index_vals[0]) diff --git a/source/python/submit.py b/source/python/submit.py index bd9f74e0c0b7d9714b79388512595ef07871a796..488ac5e361186e25e5a57a3ae43902c501eba345 100755 --- a/source/python/submit.py +++ b/source/python/submit.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- #******************************************************************************* # @Author: Anne Fouilloux (University of Oslo) @@ -67,7 +67,7 @@ from datetime import datetime, timedelta # software specific classes and modules from flex_extract import _config from mods.tools import (setup_controldata, normal_exit, get_cmdline_args, - submit_job_to_ecserver, read_ecenv) + submit_job_to_ecserver, read_ecenv) from mods.get_mars_data import get_mars_data from mods.prepare_flexpart import prepare_flexpart from classes.ControlFile import ControlFile diff --git a/templates/compilejob.template b/templates/compilejob.template index f79847759ee8d3b6d3248872e3db459eebb28944..a115b5968f37ef40eaa439b06adc2965b079c654 100644 --- a/templates/compilejob.template +++ b/templates/compilejob.template @@ -29,18 +29,20 @@ case $${HOST} in *ecg*) module unload grib_api module unload eccodes - module load eccodes - module load python + module unload python module unload emos + module load python3 + module load eccodes/2.12.0 module load emos/455-r64 export FLEXPART_ROOT_SCRIPTS=$fp_root_scripts export MAKEFILE=$makefile ;; *cca*) + module unload python module switch PrgEnv-cray PrgEnv-intel - module load eccodes + module load python3 + module load eccodes/2.12.0 module load emos - module load python echo $${GROUP} echo $${HOME} echo $${HOME} | awk -F / '{print $1, $2, $3, $4}' diff --git a/templates/job.temp b/templates/job.temp index f0d8564097bbd70ab8470c4184d84317428ace42..2ece17ea6a435155c6a5ef9c3e814244dee1bd89 100644 --- a/templates/job.temp +++ b/templates/job.temp @@ -27,19 +27,21 @@ set -x export VERSION=7.1 case $${HOST} in *ecg*) - module load python module unload grib_api module unload eccodes - module load eccodes + module unload python module unload emos + module load python3 + module load eccodes/2.12.0 module load emos/455-r64 export PATH=$${PATH}:$${HOME}/flex_extract_v7.1/source/python ;; *cca*) + module unload python module switch PrgEnv-cray PrgEnv-intel - module load eccodes + module load python3 + module load eccodes/2.12.0 module load emos - module load python export SCRATCH=$${TMPDIR} export PATH=$${PATH}:$${HOME}/flex_extract_v7.1/source/python ;; diff --git a/templates/job.template b/templates/job.template index 5f12a0b499ad479a7bf7912b5b989405853abfba..35652c10c07bfb5cb4591addddbafdbad15a8494 100644 --- a/templates/job.template +++ b/templates/job.template @@ -27,19 +27,21 @@ set -x export VERSION=$version_number case $$$${HOST} in *ecg*) - module load python module unload grib_api module unload eccodes - module load eccodes + module unload python module unload emos + module load python3 + module load eccodes/2.12.0 module load emos/455-r64 export PATH=$$$${PATH}:$fp_root_path ;; *cca*) + module unload python module switch PrgEnv-cray PrgEnv-intel - module load eccodes + module load python3 + module load eccodes/2.12.0 module load emos - module load python export SCRATCH=$$$${TMPDIR} export PATH=$$$${PATH}:$fp_root_path ;;