Skip to content

Commit 8a9f969

Browse files
committed
Improved command-line interface
Added a minimal parser with argparse, and renamed the module from pdd to pypdd. Type pypdd.py -h for help.
1 parent a7d50b0 commit 8a9f969

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pdd.py renamed to pypdd.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ def nc(self, i_file, o_file):
8080
i.close()
8181
o.close()
8282

83-
# netCDF IO
83+
# netCDF climate initializer
8484

85-
def init():
86-
"""Create an artificial PISM atmosphere file"""
85+
def make_fake_climate(filename):
86+
"""Create an artificial temperature and precipitation file"""
8787

8888
from math import cos, pi
8989
from netCDF4 import Dataset as NC
9090

9191
# open netcdf file
92-
nc = NC('atm.nc', 'w')
92+
nc = NC(filename, 'w')
9393

9494
# create dimensions
9595
tdim = nc.createDimension('time', 12)
@@ -121,13 +121,19 @@ def init():
121121
# Called at execution
122122

123123
if __name__ == "__main__":
124+
import argparse
125+
parser = argparse.ArgumentParser(description='Compute glacier surface mass balance from temperature and precipitation')
126+
parser.add_argument('-i', help='input file')
127+
parser.add_argument('-o', help='output file', default='smb.nc')
128+
args = parser.parse_args()
124129

125130
# prepare dummy input dataset
126-
init()
131+
if not args.i:
132+
make_fake_climate('atm.nc')
127133

128134
# initiate PDD model
129135
pdd=PDDModel()
130136

131137
# compute surface mass balance
132-
pdd.nc('atm.nc', 'clim.nc')
138+
pdd.nc(args.i or 'atm.nc', args.o)
133139

0 commit comments

Comments
 (0)