source: issm/trunk/src/m/classes/regionaloutput.py

Last change on this file was 28013, checked in by Mathieu Morlighem, 16 months ago

merged trunk-jpl and trunk for revision 28011

  • Property svn:executable set to *
File size: 4.8 KB
RevLine 
[21827]1from project3d import project3d
[21808]2from fielddisplay import fielddisplay
3from pairoptions import pairoptions
4from checkfield import checkfield
5from WriteData import WriteData
[21827]6from ContourToMesh import ContourToMesh
7import numpy as np
[21808]8import os
9
[24313]10
[21808]11class regionaloutput(object):
[24313]12 """
13 REGIONALOUTPUT class definition
[21808]14
[24313]15 Usage:
16 regionaloutput = regionaloutput()
17 regionaloutput = regionaloutput('name', 'Volume1', 'definitionstring', 'Outputdefinition1', 'outputnamestring', 'IceVolume', 'mask', mask)
18 regionaloutput = regionaloutput('name', 'Volume1', 'definitionstring', 'Outputdefinition1', 'outputnamestring', 'IceVolume', 'maskexpstring', 'Exp/Mask.exp', 'model', md)
[21808]19
[24313]20 where mask is a vectorial field of size md.mesh.numberofvertices, 1 : where vertices with values > 1 are to be included in the calculated region.
21 Alternatively, the user can pass in an Argus file and model object instead of a mask, and mask will be calculated for the user
22 """
[21808]23
[24313]24 def __init__(self, *args): # {{{
[21808]25
[24313]26 self.name = ''
[27035]27 self.model= ''
[24313]28 self.definitionstring = ''
29 self.outputnamestring = ''
[27035]30 self.mask = np.nan
[24313]31 self.maskexpstring = ''
[21808]32
[24313]33 #set defaults
34 self.setdefaultparameters()
[21808]35
[24313]36 #use provided options to change fields
37 options = pairoptions(*args)
[21808]38
[24313]39 #OK get other fields
40 self = options.AssignObjectFields(self)
[21808]41
[24313]42 #get name
43 if options.getfieldvalue('model', 0):
44 if options.getfieldvalue('maskexpstring', 0):
45 modelname = options.getfieldvalue('model')
46 self.maskexpstring = options.getfieldvalue('maskexpstring')
47 self.setmaskfromexp(modelname)
[21808]48
[27035]49 # if (len(self.mask) <= 1 & np.any(np.isnan(self.mask))):
50 # raise IOError('regionaloutput error message: ''mask'' field or ''maskexpstring'' and ''model'' fields should be defined!')
[21808]51
[28013]52 # }}}
[21808]53
[24313]54 def __repr__(self): # {{{
55 string = " Regionaloutput:"
56 string = "%s\n%s" % (string, fielddisplay(self, 'name', 'identifier for this regional response'))
57 string = "%s\n%s" % (string, fielddisplay(self, 'definitionstring', 'string that identifies this output definition uniquely, from Outputdefinition[1 - 100]'))
58 string = "%s\n%s" % (string, fielddisplay(self, 'outputnamestring', 'string that identifies the type of output you want, eg. IceVolume, TotalSmb, GroudedArea'))
59 string = "%s\n%s" % (string, fielddisplay(self, 'mask', 'mask vectorial field which identifies the region of interest (value > 0 will be included)'))
60 string = "%s\n%s" % (string, fielddisplay(self, 'maskexpstring', 'name of Argus file that can be passed in to define the regional mask'))
61 return string
[28013]62 # }}}
[21808]63
[24313]64 def extrude(self, md): # {{{
65 self.mask = project3d(md, 'vector', self.mask, 'type', 'node')
66 return self
[28013]67 # }}}
[21808]68
[24313]69 def setdefaultparameters(self): # {{{
70 return self
[28013]71 # }}}
[24313]72
73 def setmaskfromexp(self, md): # {{{
74 if len(self.maskexpstring) > 0:
75 self.mask = ContourToMesh(md.mesh.elements, md.mesh.x, md.mesh.y, self.maskexpstring, 'node', 1)
76
77 return self
78 # }}}
[27035]79
[24313]80 def checkconsistency(self, md, solution, analyses): # {{{
81
82 if not isinstance(self.name, str):
83 raise RuntimeError("regionaloutput error message: 'name' field should be a string!")
84
85 if not isinstance(self.outputnamestring, str):
86 raise RuntimeError("regionaloutput error message: 'outputnamestring' field should be a string!")
87
88 if len(self.maskexpstring) > 0:
89 if not os.path.isfile(self.maskexpstring):
90 raise RuntimeError("regionaloutput error message: file name for mask exp does not point to a legitimate file on disk!")
91 else:
92 self.setmaskfromexp(md)
93
94 OutputdefinitionStringArray = []
95 for i in range(1, 100):
96 x = 'Outputdefinition' + str(i)
97 OutputdefinitionStringArray.append(x)
98
99 md = checkfield(md, 'field', self.definitionstring, 'values', OutputdefinitionStringArray)
100 md = checkfield(md, 'field', self.mask, 'size', [md.mesh.numberofvertices], 'NaN', 1, 'Inf', 1)
101 return md
102 # }}}
103 def marshall(self, prefix, md, fid): # {{{
104
105 #before marshalling, make sure mask is set:
106 self.setmaskfromexp(md)
107
108 #ok, marshall strings and mask:
109 WriteData(fid, prefix, 'data', self.name, 'name', 'md.regionaloutput.name', 'format', 'String')
110 WriteData(fid, prefix, 'data', self.definitionstring, 'name', 'md.regionaloutput.definitionstring', 'format', 'String')
111 WriteData(fid, prefix, 'data', self.outputnamestring, 'name', 'md.regionaloutput.outputnamestring', 'format', 'String')
112 WriteData(fid, prefix, 'data', self.mask, 'name', 'md.regionaloutput.mask', 'format', 'DoubleMat', 'mattype', 1)
113
114 # }}}
Note: See TracBrowser for help on using the repository browser.