Changeset 25125 for issm/trunk-jpl/src/m/io/loadvars.py
- Timestamp:
- 06/23/20 15:42:10 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/io/loadvars.py
r25092 r25125 1 from collections import OrderedDict 2 from netCDF4 import Dataset 3 import numpy as np 4 from re import findall 1 5 import shelve 2 import numpy as np 3 from netCDF4 import Dataset 4 from re import findall 5 from collections import OrderedDict 6 6 7 from model import * 7 8 #hack to keep python 2 compatibility … … 15 16 16 17 def loadvars(*args, OL): 17 """18 LOADVARS - function to load variables toa file.19 20 This function loads one or more variables from a file. The names of the variables21 must be supplied. If more than one variable is specified, it may be done with22 a list of names or a dictionary of name as keys. The output type will correspond23 t o the input type. All the variables in the file may be loaded by specifying only24 the file name.18 ''' 19 LOADVARS - function to load variables from a file. 20 21 This function loads one or more variables from a file. The names of the 22 variables must be supplied. If more than one variable is specified, it may 23 be done with a list of names or a dictionary of name as keys. The output 24 type will correspond to the input type. All the variables in the file may 25 be loaded by specifying only the file name. 25 26 26 27 Usage: … … 29 30 nvdict = loadvars('shelve.dat', {'a':None, 'b':None}) 30 31 nvdict = loadvars('shelve.dat') 31 32 """ 32 ''' 33 33 34 34 filename = '' … … 40 40 if not filename: 41 41 filename = '/tmp/shelve.dat' 42 43 42 else: 44 43 raise TypeError("Missing file name.") … … 47 46 for name in args[1:]: 48 47 nvdict[name] = None 49 50 48 elif len(args) == 2 and isinstance(args[1], list): # (filename, [names]) 51 49 for name in args[1]: 52 50 nvdict[name] = None 53 54 51 elif len(args) == 2 and isinstance(args[1], dict): # (filename, {names:values}) 55 52 nvdict = args[1] 56 57 53 elif len(args) == 1: # (filename) 58 54 pass 59 60 55 else: 61 56 raise TypeError("Unrecognized input arguments.") … … 78 73 print(("Variable '%s' loaded." % name)) 79 74 my_shelf.close() 80 81 75 else: #We used netcdf for the save 82 76 try:
Note:
See TracChangeset
for help on using the changeset viewer.