source: issm/trunk-jpl/src/m/classes/SMBforcing.py@ 23833

Last change on this file since 23833 was 23833, checked in by kruegern, 6 years ago

BUG: fixed various tab vs 4-space bugs and misaligned tabs

File size: 3.2 KB
RevLine 
[21303]1import numpy as np
[19527]2from fielddisplay import fielddisplay
3from checkfield import checkfield
4from WriteData import WriteData
5from project3d import project3d
6
7class SMBforcing(object):
[23833]8 """
9 SMBforcing Class definition
[19527]10
[23833]11 Usage:
12 SMB=SMBforcing();
13 """
[19527]14
[23833]15 def __init__(self): # {{{
16 self.mass_balance = float('NaN')
17 self.requested_outputs = []
18 self.isclimatology = 0
19 #}}}
20 def __repr__(self): # {{{
21 string=" surface forcings parameters:"
22 string="%s\n%s"%(string,fielddisplay(self,'mass_balance','surface mass balance [m/yr ice eq]'))
23 string="%s\n%s"%(string,fielddisplay(self,'isclimatology','repeat all forcings when past last forcing time (default false)'))
24 string="%s\n%s"%(string,fielddisplay(self,'requested_outputs','additional outputs requested'))
25 return string
26 #}}}
27 def extrude(self,md): # {{{
[19527]28
[23833]29 self.mass_balance=project3d(md,'vector',self.mass_balance,'type','node');
30 return self
31 #}}}
32 def defaultoutputs(self,md): # {{{
33 return []
34 #}}}
35 def initialize(self,md): # {{{
[19527]36
[23833]37 if np.all(np.isnan(self.mass_balance)):
38 self.mass_balance=np.zeros((md.mesh.numberofvertices))
39 print(" no SMBforcing.mass_balance specified: values set as zero")
[19527]40
[23833]41 return self
42 #}}}
43 def checkconsistency(self,md,solution,analyses): # {{{
[19527]44
[23833]45 if 'MasstransportAnalysis' in analyses:
46 md = checkfield(md,'fieldname','smb.mass_balance','timeseries',1,'NaN',1,'Inf',1)
[19527]47
[23833]48 if 'BalancethicknessAnalysis' in analyses:
49 md = checkfield(md,'fieldname','smb.mass_balance','size',[md.mesh.numberofvertices],'NaN',1,'Inf',1)
[19527]50
[23833]51 md = checkfield(md,'fieldname','masstransport.requested_outputs','stringrow',1)
52 md = checkfield(md,'fieldname','smb.isclimatology','values',[0,1])
53 if (self.isclimatology>0):
54 md = checkfield(md,'fieldname', 'smb.mass_balance', 'size',[md.mesh.numberofvertices+1],'message','mass_balance must have md.mesh.numberofvertices+1 rows in order to force a climatology')
[23814]55
[23833]56 return md
57 # }}}
58 def marshall(self,prefix,md,fid): # {{{
[19527]59
[23833]60 yts=md.constants.yts
[19527]61
[23833]62 WriteData(fid,prefix,'name','md.smb.model','data',1,'format','Integer');
63 WriteData(fid,prefix,'object',self,'class','smb','fieldname','mass_balance','format','DoubleMat','mattype',1,'scale',1./yts,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts)
64 #WriteData(fid,prefix,'object',self,'class','smb','fieldname','mass_balance','format','CompressedMat','mattype',1,'scale',1./yts,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts);
65
66 #process requested outputs
67 outputs = self.requested_outputs
68 indices = [i for i, x in enumerate(outputs) if x == 'default']
69 if len(indices) > 0:
70 outputscopy=outputs[0:max(0,indices[0]-1)]+self.defaultoutputs(md)+outputs[indices[0]+1:]
71 outputs =outputscopy
72 WriteData(fid,prefix,'data',outputs,'name','md.smb.requested_outputs','format','StringArray')
73 WriteData(fid,prefix,'object',self,'class','smb','fieldname','isclimatology','format','Boolean')
[19527]74
[23833]75 # }}}
Note: See TracBrowser for help on using the repository browser.