Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py2topy3 #43

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions CONFIG/autowrf_classlib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

import datetime as dt
import math
from collections import OrderedDict
Expand Down Expand Up @@ -64,9 +64,9 @@ def ReadNamelist(self, namelist_file):

def WriteNamelist(self, out_filename):
with open(out_filename, 'w') as f:
for sect, optlist in self.opts.iteritems():
for sect, optlist in self.opts.items():
f.write("&"+sect+"\n")
for optname, optvals in optlist.iteritems():
for optname, optvals in optlist.items():
padding = " " * (self.opt_field_width - len(optname) - 1)
f.write(" "+optname+padding+"= ")
for val in optvals:
Expand Down Expand Up @@ -416,7 +416,7 @@ def AdjustMapProjOpts(self, map_proj, neiproj=False):
# Setting neiproj to true will alter the messages printed if options are changed.
proj_opts, all_opts = self.MapProjOptions(map_proj)
# All these options are in the "geogrid" section
curr_opts = self.opts["geogrid"].keys()
curr_opts = list(self.opts["geogrid"].keys())
opt_added = False
opt_removed = False
for opt in all_opts:
Expand Down Expand Up @@ -444,7 +444,7 @@ def AdjustMapProjOpts(self, map_proj, neiproj=False):
msg_print("geogrid options have changed with the map projection.")
msg_print("The NEI compatibility checker will help you set them.")

junk = raw_input("Press ENTER to continue.")
junk = input("Press ENTER to continue.")


class NamelistContainer:
Expand Down Expand Up @@ -850,7 +850,7 @@ def UserSetMozFile():
msg_print("This must be created and contain your MOZBC files. Both")
msg_print("this program and the MOZBC component of the automatic WRF")
msg_print("program rely on this.")
raw_input("Press ENTER to continue")
input("Press ENTER to continue")
return None

tmp = glob(os.path.join(mozDataDir, "*.nc"))
Expand All @@ -859,7 +859,7 @@ def UserSetMozFile():
msg_print("No MOZBC data files present! You need to download some.")
msg_print("As of 20 Jul 2016, they can be obtained at")
msg_print("http://www.acom.ucar.edu/wrf-chem/mozart.shtml")
raw_input("Press ENTER to continue")
input("Press ENTER to continue")
return None

newMozFilename = UI.UserInputList("Choose the MOZBC file to use: ", mozFiles,currentvalue=mozFilename)
Expand All @@ -870,7 +870,7 @@ def UserSetMozFile():
msg_print("the input preparation step. Rerunning 'autowrfchem config namelist'")
msg_print("and modifying the current namelist will allow you to select a file")
msg_print("later.")
raw_input("Press ENTER to continue")
input("Press ENTER to continue")
return None

wroteMoz=False
Expand All @@ -885,11 +885,11 @@ def UserSetMozFile():
cfgw.write("mozbcFile=\"{0}\"\n".format(newMozFilename))

def UserSetOtherOpt(self, namelist):
sect = UI.UserInputList("Choose the namelist section: ", namelist.opts.keys())
sect = UI.UserInputList("Choose the namelist section: ", list(namelist.opts.keys()))
if sect is None:
return

k = namelist.opts[sect].keys()
k = list(namelist.opts[sect].keys())
if len(k) == 0:
msg_print("{0} has no options".format(sect))
return
Expand All @@ -913,16 +913,16 @@ def UserSetOtherOpt(self, namelist):
namelist.SetOptVal(sect, opt, optval)

def DisplayOptions(self, namelist):
sectnames = namelist.opts.keys()
sectnames = list(namelist.opts.keys())
sectnames.append("All")
sect = UI.UserInputList("Which namelist section to display?", sectnames)
if sect == "All":
for s in namelist.opts.keys():
for s in list(namelist.opts.keys()):
msg_print("{0}:".format(s))
for k,v in namelist.opts[s].iteritems():
for k,v in namelist.opts[s].items():
msg_print(" {0} = {1}".format(k,v))
elif sect is not None:
for k,v in namelist.opts[sect].iteritems():
for k,v in namelist.opts[sect].items():
msg_print(" {0} = {1}".format(k,v))

def UserNEICompatCheck(self):
Expand Down Expand Up @@ -1111,7 +1111,7 @@ def UserInputList( prompt, options, returntype="value", currentvalue=None, empty
print(" {2}{0}: {1}".format(i, options[i-1], currstr))

while True:
userans = raw_input("Enter 1-{0}: ".format(len(options)))
userans = input("Enter 1-{0}: ".format(len(options)))
if len(userans) == 0:
return None

Expand Down Expand Up @@ -1146,7 +1146,7 @@ def UserInputDate( prompt, currentvalue=None):
print("Current value is {0}".format(currentvalue))

while True:
userdate = raw_input("--> ")
userdate = input("--> ")
userdate = userdate.strip()
if len(userdate) == 0:
return None
Expand Down Expand Up @@ -1188,7 +1188,7 @@ def UserInputDate( prompt, currentvalue=None):
# Take advantage of datetime's built in checking to be sure we have a valid date
try:
dateout = dt.datetime(yr,mn,dy,hour,min,sec)
except ValueError, e:
except ValueError as e:
print("Problem with date/time entered: {0}".format(str(e)))
continue

Expand All @@ -1207,7 +1207,7 @@ def UserInputValue( optname, isbool=False, currval=None, noempty=False):

while True:
if isbool:
userans = raw_input("T/F: ").lower().strip()
userans = input("T/F: ").lower().strip()
if userans == "t":
return ".true."
elif userans == "f":
Expand All @@ -1217,7 +1217,7 @@ def UserInputValue( optname, isbool=False, currval=None, noempty=False):
else:
print("Option is a boolean. Must enter T or F.")
else:
userans = raw_input("--> ").strip()
userans = input("--> ").strip()
if len(userans) == 0 and not noempty:
return None
elif len(userans) == 0 and noempty:
Expand All @@ -1234,7 +1234,7 @@ def UserInputYN(prompt, default="y"):
else:
defstr = " y/[n]"
defaultans = False
userans = raw_input(prompt + defstr + ": ")
userans = input(prompt + defstr + ": ")

if userans == "":
return defaultans
Expand Down
4 changes: 2 additions & 2 deletions CONFIG/autowrf_namelist_main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

import sys
import os
import datetime as dt
Expand Down Expand Up @@ -126,7 +126,7 @@ def SaveMenu(nlc):

nlc.WriteNamelists(dir=NamelistsPath(), suffix=suffix)

userans = raw_input("Do you also write to make these the current namelist? y/[n]: ")
userans = input("Do you also write to make these the current namelist? y/[n]: ")
if userans.lower() == "y":
print("Writing out namelists.")
nlc.WriteNamelists(dir=my_dir)
Expand Down
2 changes: 1 addition & 1 deletion PREPINPUT/bestemissyear.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# best represents the emissions for it and prints out a start
# date which can be used by the namelist program to set the
# start date for convert_emiss.F
from __future__ import print_function

import datetime as dt
import argparse
import re
Expand Down
2 changes: 1 addition & 1 deletion PREPINPUT/metgriblist.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function

import argparse
import calendar
import datetime as dt
Expand Down
10 changes: 5 additions & 5 deletions PREPINPUT/mozcheck.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# check that the given Mozart file covers the time range and the domain plus a 10 degree buffer
from __future__ import print_function

import argparse
import datetime as dt
import os
Expand Down Expand Up @@ -55,12 +55,12 @@ def get_run_info(wrfin, stime_str, etime_str):
def convert_moz_date(dateint, datesec):
# MOZ dates are given as an integer with 8 digits. The first four are year, then two month, then two for day
# Some arithmetic sneakiness to break it apart
yr = dateint/10000
mn = (dateint % 10000)/100
yr = dateint//10000
mn = (dateint % 10000)//100
dy = dateint % 100

hour = datesec / 3600
minute = (datesec % 3600)/60
hour = datesec // 3600
minute = (datesec % 3600)//60
sec = datesec % 60
return dt.datetime(year=yr, month=mn, day=dy, hour=hour, minute=minute, second=sec)

Expand Down
4 changes: 2 additions & 2 deletions PREPINPUT/postcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 4 bit: on = wrfinput missing variables, off = variables below min threshold
# 8 bit = problem with wrfbdy
# 16 bit: on = wrfbdy missing variables, off = variables below min threshold
from __future__ import print_function

import pdb
import argparse
import re
Expand All @@ -38,7 +38,7 @@ def get_var_names(filename):
return pync.call_ncdump_varnames(filename)
else:
rgrp = ncdat(filename)
return rgrp.variables.keys()
return list(rgrp.variables.keys())
rgrp.close()

def get_var_values(varnames, filename):
Expand Down
2 changes: 1 addition & 1 deletion Tools/datecompare.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# datecompare.py - python script that can be used to compare two dates given as strings
# Gives exit status of 0 if comparison is true, 1 if false, so can be used in shell if
# statements.
from __future__ import print_function

import argparse
import datetime as dt
import re
Expand Down
12 changes: 6 additions & 6 deletions Tools/gc2moz/python/gc2moz.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

import argparse
from bpch import bpch
import datetime as dt
Expand Down Expand Up @@ -166,9 +166,9 @@ def unit_conversion(current_values, unit_type, current_unit, new_unit):
else:
raise ValueError('Unit type "{0}" not recognized'.format(unit_type))

if current_unit not in conv_factors.keys():
if current_unit not in list(conv_factors.keys()):
raise KeyError('{0} unit "{1}" not defined'.format(unit_type, current_unit))
if new_unit not in conv_factors.keys():
if new_unit not in list(conv_factors.keys()):
raise KeyError('{0} unit "{1}" not defined'.format(unit_type, new_unit))

return current_values * conv_factors[new_unit] / conv_factors[current_unit]
Expand Down Expand Up @@ -400,13 +400,13 @@ def write_chem_species(ncfile, filetimes):
# Find all GEOS variables in the categories defined as static variables
b = bpch(filetimes.unique_files()[0])
gc_moz_names = {} # this will be a dictionary with the GC name as the key and the MOZART-like name as the value
for k in b.variables.keys():
for k in list(b.variables.keys()):
for cat in gc_categories:
if cat in k:
gc_moz_names[k] = geos_to_moz_name(k)
b.close()

for gc_name, moz_name in gc_moz_names.iteritems():
for gc_name, moz_name in gc_moz_names.items():
if __debug_level__ > 1:
shell_msg(' Writing {0} as {1}'.format(gc_name, moz_name))
val = []
Expand Down Expand Up @@ -452,7 +452,7 @@ def add_methane(ncfile):
lat = ncfile.variables['lat'][:]

# Find a chemistry variable to get the shape of
for k in ncfile.variables.keys():
for k in list(ncfile.variables.keys()):
if moz_suffix in k:
chem_key = k
break
Expand Down
2 changes: 1 addition & 1 deletion Tools/gc2moz/python/gcCH4bins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

import sys
__author__ = 'Josh'

Expand Down
2 changes: 1 addition & 1 deletion Tools/pyncdf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

import numpy as np
import os
import re
Expand Down