1 | #module imports {{{
|
---|
2 | from netCDF4 import Dataset
|
---|
3 | import time
|
---|
4 | import collections
|
---|
5 | from os import path, remove
|
---|
6 | #}}}
|
---|
7 |
|
---|
8 |
|
---|
9 | class truc(object):
|
---|
10 | #properties
|
---|
11 | def __init__(self,*filename):#{{{
|
---|
12 |
|
---|
13 | def netCDFread(filename):
|
---|
14 | def walktree(data):
|
---|
15 | keys = list(data.groups.keys())
|
---|
16 | yield keys
|
---|
17 | for key in keys:
|
---|
18 | for children in walktree(data.groups[str(key)]):
|
---|
19 | yield children
|
---|
20 |
|
---|
21 | if path.exists(filename):
|
---|
22 | print(('Opening {} for reading '.format(filename)))
|
---|
23 | NCData=Dataset(filename, 'r')
|
---|
24 | class_dict={}
|
---|
25 |
|
---|
26 | for children in walktree(NCData):
|
---|
27 | for child in children:
|
---|
28 | class_dict[str(child)]=str(getattr(NCData.groups[str(child)],'classtype'))
|
---|
29 |
|
---|
30 | return class_dict
|
---|
31 |
|
---|
32 | if filename:
|
---|
33 | classtype=netCDFread(filename[0])
|
---|
34 | else:
|
---|
35 | classtype=self.default_prop()
|
---|
36 |
|
---|
37 | module=list(map(__import__,dict.values(classtype)))
|
---|
38 |
|
---|
39 | for i,mod in enumerate(dict.keys(classtype)):
|
---|
40 | self.__dict__[mod] = getattr(module[i],str(classtype[str(mod)]))()
|
---|
41 |
|
---|
42 | #}}}
|
---|
43 | def default_prop(self): # {{{
|
---|
44 | # ordered list of properties since vars(self) is random
|
---|
45 | return {'mesh':'mesh2d',\
|
---|
46 | 'mask':'mask',\
|
---|
47 | 'geometry':'geometry',\
|
---|
48 | 'constants':'constants',\
|
---|
49 | 'smb':'SMB',\
|
---|
50 | 'basalforcings':'basalforcings',\
|
---|
51 | 'materials':'matice',\
|
---|
52 | 'damage':'damage',\
|
---|
53 | 'friction':'friction',\
|
---|
54 | 'flowequation':'flowequation',\
|
---|
55 | 'timestepping':'timestepping',\
|
---|
56 | 'initialization':'initialization',\
|
---|
57 | 'rifts':'rifts',\
|
---|
58 | 'debug':'debug',\
|
---|
59 | 'verbose':'verbose',\
|
---|
60 | 'settings':'settings',\
|
---|
61 | 'toolkits':'toolkits',\
|
---|
62 | 'cluster':'generic',\
|
---|
63 | 'balancethickness':'balancethickness',\
|
---|
64 | 'stressbalance':'stressbalance',\
|
---|
65 | 'groundingline':'groundingline',\
|
---|
66 | 'hydrology':'hydrologyshreve',\
|
---|
67 | 'masstransport':'masstransport',\
|
---|
68 | 'thermal':'thermal',\
|
---|
69 | 'steadystate':'steadystate',\
|
---|
70 | 'transient':'transient',\
|
---|
71 | 'calving':'calving',\
|
---|
72 | 'giaivins':'giaivins',\
|
---|
73 | 'autodiff':'autodiff',\
|
---|
74 | 'inversion':'inversion',\
|
---|
75 | 'qmu':'qmu',\
|
---|
76 | 'outputdefinition':'outputdefinition',\
|
---|
77 | 'results':'results',\
|
---|
78 | 'radaroverlay':'radaroverlay',\
|
---|
79 | 'miscellaneous':'miscellaneous',\
|
---|
80 | 'private':'private'}
|
---|
81 | # }}}
|
---|
82 |
|
---|
83 | def __repr__(obj): #{{{
|
---|
84 | #print "Here %s the number: %d" % ("is", 37)
|
---|
85 | string="%19s: %-22s -- %s" % ("mesh","[%s,%s]" % ("1x1",obj.mesh.__class__.__name__),"mesh properties")
|
---|
86 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("mask","[%s,%s]" % ("1x1",obj.mask.__class__.__name__),"defines grounded and floating elements"))
|
---|
87 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("geometry","[%s,%s]" % ("1x1",obj.geometry.__class__.__name__),"surface elevation, bedrock topography, ice thickness,..."))
|
---|
88 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("constants","[%s,%s]" % ("1x1",obj.constants.__class__.__name__),"physical constants"))
|
---|
89 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("smb","[%s,%s]" % ("1x1",obj.smb.__class__.__name__),"surface forcings"))
|
---|
90 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("basalforcings","[%s,%s]" % ("1x1",obj.basalforcings.__class__.__name__),"bed forcings"))
|
---|
91 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("materials","[%s,%s]" % ("1x1",obj.materials.__class__.__name__),"material properties"))
|
---|
92 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("damage","[%s,%s]" % ("1x1",obj.damage.__class__.__name__),"damage propagation laws"))
|
---|
93 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("friction","[%s,%s]" % ("1x1",obj.friction.__class__.__name__),"basal friction/drag properties"))
|
---|
94 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("flowequation","[%s,%s]" % ("1x1",obj.flowequation.__class__.__name__),"flow equations"))
|
---|
95 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("timestepping","[%s,%s]" % ("1x1",obj.timestepping.__class__.__name__),"time stepping for transient models"))
|
---|
96 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("initialization","[%s,%s]" % ("1x1",obj.initialization.__class__.__name__),"initial guess/state"))
|
---|
97 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("rifts","[%s,%s]" % ("1x1",obj.rifts.__class__.__name__),"rifts properties"))
|
---|
98 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("debug","[%s,%s]" % ("1x1",obj.debug.__class__.__name__),"debugging tools (valgrind, gprof)"))
|
---|
99 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("verbose","[%s,%s]" % ("1x1",obj.verbose.__class__.__name__),"verbosity level in solve"))
|
---|
100 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("settings","[%s,%s]" % ("1x1",obj.settings.__class__.__name__),"settings properties"))
|
---|
101 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("toolkits","[%s,%s]" % ("1x1",obj.toolkits.__class__.__name__),"PETSc options for each solution"))
|
---|
102 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("cluster","[%s,%s]" % ("1x1",obj.cluster.__class__.__name__),"cluster parameters (number of cpus...)"))
|
---|
103 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("balancethickness","[%s,%s]" % ("1x1",obj.balancethickness.__class__.__name__),"parameters for balancethickness solution"))
|
---|
104 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("stressbalance","[%s,%s]" % ("1x1",obj.stressbalance.__class__.__name__),"parameters for stressbalance solution"))
|
---|
105 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("groundingline","[%s,%s]" % ("1x1",obj.groundingline.__class__.__name__),"parameters for groundingline solution"))
|
---|
106 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("hydrology","[%s,%s]" % ("1x1",obj.hydrology.__class__.__name__),"parameters for hydrology solution"))
|
---|
107 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("masstransport","[%s,%s]" % ("1x1",obj.masstransport.__class__.__name__),"parameters for masstransport solution"))
|
---|
108 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("thermal","[%s,%s]" % ("1x1",obj.thermal.__class__.__name__),"parameters for thermal solution"))
|
---|
109 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("steadystate","[%s,%s]" % ("1x1",obj.steadystate.__class__.__name__),"parameters for steadystate solution"))
|
---|
110 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("transient","[%s,%s]" % ("1x1",obj.transient.__class__.__name__),"parameters for transient solution"))
|
---|
111 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("calving","[%s,%s]" % ("1x1",obj.calving.__class__.__name__),"parameters for calving"))
|
---|
112 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("autodiff","[%s,%s]" % ("1x1",obj.autodiff.__class__.__name__),"automatic differentiation parameters"))
|
---|
113 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("inversion","[%s,%s]" % ("1x1",obj.inversion.__class__.__name__),"parameters for inverse methods"))
|
---|
114 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("qmu","[%s,%s]" % ("1x1",obj.qmu.__class__.__name__),"dakota properties"))
|
---|
115 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("outputdefinition","[%s,%s]" % ("1x1",obj.outputdefinition.__class__.__name__),"output definition"))
|
---|
116 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("results","[%s,%s]" % ("1x1",obj.results.__class__.__name__),"model results"))
|
---|
117 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("radaroverlay","[%s,%s]" % ("1x1",obj.radaroverlay.__class__.__name__),"radar image for plot overlay"))
|
---|
118 | string="%s\n%s" % (string,"%19s: %-22s -- %s" % ("miscellaneous","[%s,%s]" % ("1x1",obj.miscellaneous.__class__.__name__),"miscellaneous fields"))
|
---|
119 | return string
|
---|
120 | # }}}
|
---|