1 | from fielddisplay import fielddisplay
|
---|
2 | from checkfield import checkfield
|
---|
3 | from WriteData import WriteData
|
---|
4 |
|
---|
5 |
|
---|
6 | class SMBgradientsela(object):
|
---|
7 | """
|
---|
8 | SMBgradientsela Class definition
|
---|
9 |
|
---|
10 | Usage:
|
---|
11 | SMBgradientsela = SMBgradientsela()
|
---|
12 | """
|
---|
13 |
|
---|
14 | def __init__(self): # {{{
|
---|
15 | self.ela = float('NaN')
|
---|
16 | self.b_pos = float('NaN')
|
---|
17 | self.b_neg = float('NaN')
|
---|
18 | self.b_max = float('NaN')
|
---|
19 | self.b_min = float('NaN')
|
---|
20 | self.steps_per_step = 1
|
---|
21 | self.averaging = 0
|
---|
22 | self.requested_outputs = []
|
---|
23 | self.setdefaultparameters()
|
---|
24 | #}}}
|
---|
25 |
|
---|
26 | def __repr__(self): # {{{
|
---|
27 | string = " surface forcings parameters:"
|
---|
28 | string += '\n SMB gradients ela parameters:'
|
---|
29 |
|
---|
30 | string = "%s\n%s" % (string, fielddisplay(self, 'ela', ' equilibrium line altitude from which deviation is used to calculate smb using the smb gradients ela method [m a.s.l.]'))
|
---|
31 | string = "%s\n%s" % (string, fielddisplay(self, 'b_pos', ' vertical smb gradient (dB/dz) above ela'))
|
---|
32 | string = "%s\n%s" % (string, fielddisplay(self, 'b_neg', ' vertical smb gradient (dB/dz) below ela'))
|
---|
33 | string = "%s\n%s" % (string, fielddisplay(self, 'b_max', ' upper cap on smb rate, default: 9999 (no cap) [m ice eq./yr]'))
|
---|
34 | string = "%s\n%s" % (string, fielddisplay(self, 'b_min', ' lower cap on smb rate, default: -9999 (no cap) [m ice eq./yr]'))
|
---|
35 | string = "%s\n%s" % (string, fielddisplay(self, 'steps_per_step', 'number of smb steps per time step'))
|
---|
36 | string = "%s\n%s" % (string, fielddisplay(self, 'averaging', 'averaging methods from short to long steps'))
|
---|
37 | string = "%s\n\t\t%s" % (string, '0: Arithmetic (default)')
|
---|
38 | string = "%s\n\t\t%s" % (string, '1: Geometric')
|
---|
39 | string = "%s\n\t\t%s" % (string, '2: Harmonic')
|
---|
40 |
|
---|
41 | string = "%s\n%s" % (string, fielddisplay(self, 'requested_outputs', 'additional outputs requested'))
|
---|
42 | return string
|
---|
43 | #}}}
|
---|
44 |
|
---|
45 | def extrude(self, md): # {{{
|
---|
46 | #Nothing for now
|
---|
47 | return self
|
---|
48 | #}}}
|
---|
49 |
|
---|
50 | def defaultoutputs(self, md): # {{{
|
---|
51 | return []
|
---|
52 | #}}}
|
---|
53 |
|
---|
54 | def initialize(self, md): # {{{
|
---|
55 | #Nothing for now
|
---|
56 | return self
|
---|
57 | #}}}
|
---|
58 |
|
---|
59 | def setdefaultparameters(self): # {{{
|
---|
60 | self.b_max = 9999.
|
---|
61 | self.b_min = -9999.
|
---|
62 | return self
|
---|
63 | #}}}
|
---|
64 |
|
---|
65 | def checkconsistency(self, md, solution, analyses): # {{{
|
---|
66 | if 'MasstransportAnalysis' in analyses:
|
---|
67 | md = checkfield(md, 'fieldname', 'smb.ela', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
|
---|
68 | md = checkfield(md, 'fieldname', 'smb.b_pos', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
|
---|
69 | md = checkfield(md, 'fieldname', 'smb.b_neg', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
|
---|
70 | md = checkfield(md, 'fieldname', 'smb.b_max', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
|
---|
71 | md = checkfield(md, 'fieldname', 'smb.b_min', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
|
---|
72 |
|
---|
73 | md = checkfield(md, 'fieldname', 'smb.steps_per_step', '>=', 1, 'numel', [1])
|
---|
74 | md = checkfield(md, 'fieldname', 'smb.averaging', 'numel', [1], 'values', [0, 1, 2])
|
---|
75 | md = checkfield(md, 'fieldname', 'smb.requested_outputs', 'stringrow', 1)
|
---|
76 | return md
|
---|
77 | # }}}
|
---|
78 | def marshall(self, prefix, md, fid): # {{{
|
---|
79 |
|
---|
80 | yts = md.constants.yts
|
---|
81 |
|
---|
82 | WriteData(fid, prefix, 'name', 'md.smb.model', 'data', 9, 'format', 'Integer')
|
---|
83 | WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'ela', 'format', 'DoubleMat', 'mattype', 1, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
|
---|
84 | WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'b_pos', 'format', 'DoubleMat', 'mattype', 1, 'scale', 1. / yts, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
|
---|
85 | WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'b_neg', 'format', 'DoubleMat', 'mattype', 1, 'scale', 1. / yts, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
|
---|
86 | WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'b_max', 'format', 'DoubleMat', 'mattype', 1, 'scale', 1. / yts, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
|
---|
87 | WriteData(fid, prefix, 'object', self, 'class', 'smb', 'fieldname', 'b_min', 'format', 'DoubleMat', 'mattype', 1, 'scale', 1. / yts, 'timeserieslength', md.mesh.numberofvertices + 1, 'yts', yts)
|
---|
88 | WriteData(fid, prefix, 'object', self, 'fieldname', 'steps_per_step', 'format', 'Integer')
|
---|
89 | WriteData(fid, prefix, 'object', self, 'fieldname', 'averaging', 'format', 'Integer')
|
---|
90 |
|
---|
91 | #process requested outputs
|
---|
92 | outputs = self.requested_outputs
|
---|
93 | indices = [i for i, x in enumerate(outputs) if x == 'default']
|
---|
94 | if len(indices) > 0:
|
---|
95 | outputscopy = outputs[0:max(0, indices[0] - 1)] + self.defaultoutputs(md) + outputs[indices[0] + 1:]
|
---|
96 | outputs = outputscopy
|
---|
97 | WriteData(fid, prefix, 'data', outputs, 'name', 'md.smb.requested_outputs', 'format', 'StringArray')
|
---|
98 |
|
---|
99 | # }}}
|
---|