[19895] | 1 | import numpy
|
---|
| 2 | from fielddisplay import fielddisplay
|
---|
| 3 | from EnumDefinitions import *
|
---|
| 4 | from checkfield import checkfield
|
---|
| 5 | from WriteData import WriteData
|
---|
| 6 | from project3d import project3d
|
---|
| 7 |
|
---|
| 8 | class SMBd18opdd(object):
|
---|
| 9 | """
|
---|
| 10 | SMBd18opdd Class definition
|
---|
| 11 |
|
---|
| 12 | Usage:
|
---|
| 13 | SMBd18opdd=SMBd18opdd();
|
---|
| 14 | """
|
---|
| 15 |
|
---|
| 16 | def __init__(self): # {{{
|
---|
| 17 | self.desfac = 0.
|
---|
| 18 | self.s0p = float('NaN')
|
---|
| 19 | self.s0t = float('NaN')
|
---|
| 20 | self.rlaps = 0.
|
---|
| 21 | self.rlapslgm = 0.
|
---|
| 22 | self.dpermil = 0.
|
---|
| 23 | self.Tdiff = float('NaN')
|
---|
| 24 | self.sealev = float('NaN')
|
---|
| 25 | self.ismungsm = 0
|
---|
| 26 | self.isd18opd = 0
|
---|
| 27 | self.delta18o = float('NaN')
|
---|
| 28 | self.delta18o_surface = float('NaN')
|
---|
| 29 | self.temperatures_presentday = float('NaN')
|
---|
| 30 | self.precipitations_presentday = float('NaN')
|
---|
| 31 |
|
---|
| 32 | #set defaults
|
---|
| 33 | self.setdefaultparameters()
|
---|
| 34 | self.requested_outputs = []
|
---|
| 35 | #}}}
|
---|
| 36 | def __repr__(self): # {{{
|
---|
| 37 | string=" surface forcings parameters:"
|
---|
| 38 |
|
---|
| 39 | string="%s\n%s"%(string,fielddisplay(self,'isd18opd','is delta18o parametrisation from present day temperature and precipitation activated (0 or 1, default is 0)'))
|
---|
| 40 | string="%s\n%s"%(string,fielddisplay(self,'desfac','desertification elevation factor (between 0 and 1, default is 0.5) [m]'))
|
---|
| 41 | string="%s\n%s"%(string,fielddisplay(self,'s0p','should be set to elevation from precip source (between 0 and a few 1000s m, default is 0) [m]'))
|
---|
| 42 | string="%s\n%s"%(string,fielddisplay(self,'s0t','should be set to elevation from temperature source (between 0 and a few 1000s m, default is 0) [m]'))
|
---|
| 43 | string="%s\n%s"%(string,fielddisplay(self,'rlaps','present day lapse rate [degree/km]'))
|
---|
| 44 | if self.isd18opd:
|
---|
| 45 | string="%s\n%s"%(string,fielddisplay(self,'temperatures_presentday','monthly present day surface temperatures [K], required if delta18o/mungsm is activated'))
|
---|
| 46 | string="%s\n%s"%(string,fielddisplay(self,'precipitations_presentday','monthly surface precipitation [m/yr water eq], required if delta18o or mungsm is activated'))
|
---|
| 47 | string="%s\n%s"%(string,fielddisplay(self,'delta18o','delta18o [per mil], required if pdd is activated and delta18o activated'))
|
---|
| 48 | string="%s\n%s"%(string,fielddisplay(self,'dpermil','degree per mil, required if d18opd is activated'))
|
---|
| 49 | string="%s\n%s"%(string,fielddisplay(self,'requested_outputs','additional outputs requested'))
|
---|
| 50 |
|
---|
| 51 | return string
|
---|
| 52 | #}}}
|
---|
| 53 | def extrude(self,md): # {{{
|
---|
| 54 |
|
---|
| 55 | if self.isd18opd: self.temperatures_presentday=project3d(md,'vector',self.temperatures_presentday,'type','node')
|
---|
| 56 | if self.isd18opd: self.precipitations_presentday=project3d(md,'vector',self.precipitations_presentday,'type','node')
|
---|
| 57 | self.s0p=project3d(md,'vector',self.s0p,'type','node')
|
---|
| 58 | self.s0t=project3d(md,'vector',self.s0t,'type','node')
|
---|
| 59 |
|
---|
| 60 | return self
|
---|
| 61 | #}}}
|
---|
| 62 | def defaultoutputs(self,md): # {{{
|
---|
| 63 | return []
|
---|
| 64 | #}}}
|
---|
| 65 | def initialize(self,md): # {{{
|
---|
| 66 |
|
---|
| 67 | if numpy.all(numpy.isnan(self.s0p)):
|
---|
| 68 | self.s0p=numpy.zeros((md.mesh.numberofvertices,1))
|
---|
| 69 | print(" no SMBd18opdd.s0p specified: values set as zero")
|
---|
| 70 |
|
---|
| 71 | if numpy.all(numpy.isnan(self.s0t)):
|
---|
| 72 | self.s0t=numpy.zeros((md.mesh.numberofvertices,1))
|
---|
| 73 | print(" no SMBd18opdd.s0t specified: values set as zero")
|
---|
| 74 |
|
---|
| 75 | return self
|
---|
| 76 | # }}}
|
---|
| 77 | def setdefaultparameters(self): # {{{
|
---|
| 78 |
|
---|
| 79 | #pdd method not used in default mode
|
---|
| 80 | self.ismungsm = 0
|
---|
| 81 | self.isd18opd = 1
|
---|
| 82 | self.desfac = 0.5
|
---|
| 83 | self.rlaps = 6.5
|
---|
| 84 | self.rlapslgm = 6.5
|
---|
| 85 | self.dpermil = 2.4
|
---|
| 86 |
|
---|
| 87 | return self
|
---|
| 88 | #}}}
|
---|
| 89 | def checkconsistency(self,md,solution,analyses): # {{{
|
---|
| 90 |
|
---|
| 91 | if MasstransportAnalysisEnum() in analyses:
|
---|
| 92 | md = checkfield(md,'fieldname','smb.desfac','<=',1,'numel',[1])
|
---|
| 93 | md = checkfield(md,'fieldname','smb.s0p','>=',0,'NaN',1,'size',[md.mesh.numberofvertices,1])
|
---|
| 94 | md = checkfield(md,'fieldname','smb.s0t','>=',0,'NaN',1,'size',[md.mesh.numberofvertices,1])
|
---|
| 95 | md = checkfield(md,'fieldname','smb.rlaps','>=',0,'numel',[1])
|
---|
| 96 | md = checkfield(md,'fieldname','smb.rlapslgm','>=',0,'numel',[1])
|
---|
| 97 |
|
---|
| 98 | if self.isd18opd:
|
---|
| 99 | md = checkfield(md,'fieldname','smb.temperatures_presentday','size',[md.mesh.numberofvertices+1,12],'NaN',1,'timeseries',1)
|
---|
| 100 | md = checkfield(md,'fieldname','smb.precipitations_presentday','size',[md.mesh.numberofvertices+1,12],'NaN',1,'timeseries',1)
|
---|
| 101 | md = checkfield(md,'fieldname','smb.delta18o','NaN',1,'size',[2,numpy.nan],'singletimeseries',1)
|
---|
| 102 | md = checkfield(md,'fieldname','smb.dpermil','>=',0,'numel',[1])
|
---|
| 103 |
|
---|
| 104 | md = checkfield(md,'fieldname','masstransport.requested_outputs','stringrow',1)
|
---|
| 105 |
|
---|
| 106 | return md
|
---|
| 107 | # }}}
|
---|
| 108 | def marshall(self,md,fid): # {{{
|
---|
| 109 |
|
---|
| 110 | yts=365.0*24.0*3600.0
|
---|
| 111 |
|
---|
| 112 | WriteData(fid,'enum',SmbEnum(),'data',SMBd18opddEnum(),'format','Integer')
|
---|
| 113 |
|
---|
| 114 | WriteData(fid,'object',self,'class','smb','fieldname','ismungsm','format','Boolean')
|
---|
| 115 | WriteData(fid,'object',self,'class','smb','fieldname','isd18opd','format','Boolean')
|
---|
| 116 | WriteData(fid,'object',self,'class','smb','fieldname','desfac','format','Double')
|
---|
| 117 | WriteData(fid,'object',self,'class','smb','fieldname','s0p','format','DoubleMat','mattype',1);
|
---|
| 118 | WriteData(fid,'object',self,'class','smb','fieldname','s0t','format','DoubleMat','mattype',1);
|
---|
| 119 | WriteData(fid,'object',self,'class','smb','fieldname','rlaps','format','Double')
|
---|
| 120 | WriteData(fid,'object',self,'class','smb','fieldname','rlapslgm','format','Double')
|
---|
| 121 | WriteData(fid,'object',self,'class','smb','fieldname','Tdiff','format','DoubleMat','mattype',1,'timeserieslength',2)
|
---|
| 122 | WriteData(fid,'object',self,'class','smb','fieldname','sealev','format','DoubleMat','mattype',1,'timeserieslength',2)
|
---|
| 123 |
|
---|
| 124 | if self.isd18opd:
|
---|
| 125 | WriteData(fid,'object',self,'class','smb','fieldname','temperatures_presentday','format','DoubleMat','mattype',1,'timeserieslength',md.mesh.numberofvertices+1)
|
---|
| 126 | WriteData(fid,'object',self,'class','smb','fieldname','precipitations_presentday','format','DoubleMat','mattype',1,'scale',1./yts,'timeserieslength',md.mesh.numberofvertices+1)
|
---|
| 127 | WriteData(fid,'object',self,'class','smb','fieldname','delta18o','format','DoubleMat','mattype',1,'timeserieslength',2)
|
---|
| 128 | WriteData(fid,'object',self,'class','smb','fieldname','dpermil','format','Double')
|
---|
| 129 |
|
---|
| 130 | #process requested outputs
|
---|
| 131 | outputs = self.requested_outputs
|
---|
| 132 | indices = [i for i, x in enumerate(outputs) if x == 'default']
|
---|
| 133 | if len(indices) > 0:
|
---|
| 134 | outputscopy=outputs[0:max(0,indices[0]-1)]+self.defaultoutputs(md)+outputs[indices[0]+1:]
|
---|
| 135 | outputs =outputscopy
|
---|
| 136 | WriteData(fid,'data',outputs,'enum',SmbRequestedOutputsEnum(),'format','StringArray')
|
---|
| 137 |
|
---|
| 138 | # }}}
|
---|