Changeset 23670 for issm/trunk-jpl/src/py3/classes/SMBd18opdd.py
- Timestamp:
- 01/31/19 07:34:11 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified issm/trunk-jpl/src/py3/classes/SMBd18opdd.py ¶
r19898 r23670 1 import numpy 1 import numpy as np 2 2 from fielddisplay import fielddisplay 3 from EnumDefinitions import *4 3 from checkfield import checkfield 5 4 from WriteData import WriteData … … 21 20 self.rlapslgm = 0. 22 21 self.dpermil = 0. 22 self.f = 0. 23 23 self.Tdiff = float('NaN') 24 24 self.sealev = float('NaN') 25 25 self.ismungsm = 0 26 26 self.isd18opd = 0 27 self.issetpddfac = 0 28 self.istemperaturescaled = 0 29 self.isprecipscaled = 0 27 30 self.delta18o = float('NaN') 28 31 self.delta18o_surface = float('NaN') 29 32 self.temperatures_presentday = float('NaN') 30 33 self.precipitations_presentday = float('NaN') 34 self.temperatures_reconstructed = float('NaN') 35 self.precipitations_reconstructed = float('NaN') 36 self.pddfac_snow = float('NaN') 37 self.pddfac_ice = float('NaN') 31 38 32 39 #set defaults … … 38 45 39 46 string="%s\n%s"%(string,fielddisplay(self,'isd18opd','is delta18o parametrisation from present day temperature and precipitation activated (0 or 1, default is 0)')) 47 string="%s\n%s"%(string,fielddisplay(self,'issetpddfac','is user passing in defined pdd factors at each vertex (0 or 1, default is 0)')) 40 48 string="%s\n%s"%(string,fielddisplay(self,'desfac','desertification elevation factor (between 0 and 1, default is 0.5) [m]')) 41 49 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]')) … … 45 53 string="%s\n%s"%(string,fielddisplay(self,'temperatures_presentday','monthly present day surface temperatures [K], required if delta18o/mungsm is activated')) 46 54 string="%s\n%s"%(string,fielddisplay(self,'precipitations_presentday','monthly surface precipitation [m/yr water eq], required if delta18o or mungsm is activated')) 55 string="%s\n%s"%(string,fielddisplay(self,'istemperaturescaled','if delta18o parametrisation from present day temperature and precipitation is activated, is temperature scaled to delta18o value? (0 or 1, default is 1)')) 56 string="%s\n%s"%(string,fielddisplay(self,'isprecipscaled','if delta18o parametrisation from present day temperature and precipitation is activated, is precipitation scaled to delta18o value? (0 or 1, default is 1)')) 57 58 if self.istemperaturescaled==0: 59 string="%s\n%s"%(string,fielddisplay(self,'temperatures_reconstructed','monthly historical surface temperatures [K], required if delta18o/mungsm/d18opd is activated and istemperaturescaled is not activated')) 60 61 if self.isprecipscaled==0: 62 string="%s\n%s"%(string,fielddisplay(self,'precipitations_reconstructed','monthly historical precipitation [m/yr water eq], required if delta18o/mungsm/d18opd is activated and isprecipscaled is not activated')) 63 47 64 string="%s\n%s"%(string,fielddisplay(self,'delta18o','delta18o [per mil], required if pdd is activated and delta18o activated')) 48 65 string="%s\n%s"%(string,fielddisplay(self,'dpermil','degree per mil, required if d18opd is activated')) 66 string="%s\n%s"%(string,fielddisplay(self,'f','precip/temperature scaling factor, required if d18opd is activated')) 67 68 if self.issetpddfac==1: 69 string="%s\n%s"%(string,fielddisplay(self,'pddfac_snow','Pdd factor for snow, at each vertex [mm ice equiv/day/degree C]')) 70 string="%s\n%s"%(string,fielddisplay(self,'pddfac_ice','Pdd factor for ice, at each vertex [mm ice equiv/day/degree C]')) 49 71 string="%s\n%s"%(string,fielddisplay(self,'requested_outputs','additional outputs requested')) 50 72 … … 55 77 if self.isd18opd: self.temperatures_presentday=project3d(md,'vector',self.temperatures_presentday,'type','node') 56 78 if self.isd18opd: self.precipitations_presentday=project3d(md,'vector',self.precipitations_presentday,'type','node') 79 if self.istemperaturescaled==0: self.temperatures_reconstructed=project3d(md,'vector',self.temperatures_reconstructed,'type','node') 80 if self.isprecipscaled==0: self.temperatures_reconstructed=project3d(md,'vector',self.precipitations_reconstructed,'type','node') 81 if self.isd18opd: self.precipitations_presentday=project3d(md,'vector',self.precipitations_presentday,'type','node') 82 if self.issetpddfac: self.pddfac_snow=project3d(md,'vector',self.pddfac_snow,'type','node') 83 if self.issetpddfac: self.pddfac_ice=project3d(md,'vector',self.pddfac_ice,'type','node') 57 84 self.s0p=project3d(md,'vector',self.s0p,'type','node') 58 85 self.s0t=project3d(md,'vector',self.s0t,'type','node') … … 65 92 def initialize(self,md): # {{{ 66 93 67 if n umpy.all(numpy.isnan(self.s0p)):68 self.s0p=n umpy.zeros((md.mesh.numberofvertices,1))94 if np.all(np.isnan(self.s0p)): 95 self.s0p=np.zeros((md.mesh.numberofvertices)) 69 96 print(" no SMBd18opdd.s0p specified: values set as zero") 70 97 71 if n umpy.all(numpy.isnan(self.s0t)):72 self.s0t=n umpy.zeros((md.mesh.numberofvertices,1))98 if np.all(np.isnan(self.s0t)): 99 self.s0t=np.zeros((md.mesh.numberofvertices)) 73 100 print(" no SMBd18opdd.s0t specified: values set as zero") 74 101 … … 80 107 self.ismungsm = 0 81 108 self.isd18opd = 1 109 self.istemperaturescaled = 1 110 self.isprecipscaled = 1 82 111 self.desfac = 0.5 83 112 self.rlaps = 6.5 84 113 self.rlapslgm = 6.5 85 114 self.dpermil = 2.4 86 115 self.f = 0.169 116 self.issetpddfac = 0 87 117 return self 88 118 #}}} 89 119 def checkconsistency(self,md,solution,analyses): # {{{ 90 120 91 if MasstransportAnalysisEnum()in analyses:121 if 'MasstransportAnalysis' in analyses: 92 122 md = checkfield(md,'fieldname','smb.desfac','<=',1,'numel',[1]) 93 md = checkfield(md,'fieldname','smb.s0p','>=',0,'NaN',1,'Inf',1,'size',[md.mesh.numberofvertices ,1])94 md = checkfield(md,'fieldname','smb.s0t','>=',0,'NaN',1,'Inf',1,'size',[md.mesh.numberofvertices ,1])123 md = checkfield(md,'fieldname','smb.s0p','>=',0,'NaN',1,'Inf',1,'size',[md.mesh.numberofvertices]) 124 md = checkfield(md,'fieldname','smb.s0t','>=',0,'NaN',1,'Inf',1,'size',[md.mesh.numberofvertices]) 95 125 md = checkfield(md,'fieldname','smb.rlaps','>=',0,'numel',[1]) 96 126 md = checkfield(md,'fieldname','smb.rlapslgm','>=',0,'numel',[1]) 97 127 98 128 if self.isd18opd: 129 lent=float(np.size(self.temperatures_presentday,1)) 130 lenp=float(np.size(self.precipitations_presentday,1)) 131 multt=np.ceil(lent/12.)*12. 132 multp=np.ceil(lenp/12.)*12. 99 133 md = checkfield(md,'fieldname','smb.temperatures_presentday','size',[md.mesh.numberofvertices+1,12],'NaN',1,'Inf',1,'timeseries',1) 100 134 md = checkfield(md,'fieldname','smb.precipitations_presentday','size',[md.mesh.numberofvertices+1,12],'NaN',1,'Inf',1,'timeseries',1) 101 md = checkfield(md,'fieldname','smb.delta18o','NaN',1,'Inf',1,'size',[2,numpy.nan],'singletimeseries',1) 135 136 if self.istemperaturescaled==0: 137 lent=float(np.size(self.temperatures_reconstructed,1)) 138 multt=np.ceil(lent/12.)*12. 139 md = checkfield(md,'fieldname','smb.temperatures_reconstructed','size',[md.mesh.numberofvertices+1,multt],'NaN',1,'Inf',1,'timeseries',1) 140 141 if self.isprecipscaled==0: 142 lenp=float(np.size(self.precipitations_reconstructed,1)) 143 multp=np.ceil(lent/12.)*12. 144 md = checkfield(md,'fieldname','smb.precipitations_reconstructed','size',[md.mesh.numberofvertices+1,multt],'NaN',1,'Inf',1,'timeseries',1) 145 146 md = checkfield(md,'fieldname','smb.delta18o','NaN',1,'Inf',1,'size',[2,np.nan],'singletimeseries',1) 102 147 md = checkfield(md,'fieldname','smb.dpermil','>=',0,'numel',[1]) 103 148 md = checkfield(md,'fieldname','smb.f','>=',0,'numel',[1]) 149 150 if self.issetpddfac: 151 md = checkfield(md,'fieldname','smb.pddfac_snow','>=',0,'NaN',1,'Inf',1) 152 md = checkfield(md,'fieldname','smb.pddfac_ice','>=',0,'NaN',1,'Inf',1) 153 104 154 md = checkfield(md,'fieldname','masstransport.requested_outputs','stringrow',1) 105 155 106 156 return md 107 157 # }}} 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) 158 def marshall(self,prefix,md,fid): # {{{ 159 160 yts=md.constants.yts 161 162 WriteData(fid,prefix,'name','md.smb.model','data',5,'format','Integer') 163 164 WriteData(fid,prefix,'object',self,'class','smb','fieldname','ismungsm','format','Boolean') 165 WriteData(fid,prefix,'object',self,'class','smb','fieldname','isd18opd','format','Boolean') 166 WriteData(fid,prefix,'object',self,'class','smb','fieldname','issetpddfac','format','Boolean'); 167 WriteData(fid,prefix,'object',self,'class','smb','fieldname','desfac','format','Double') 168 WriteData(fid,prefix,'object',self,'class','smb','fieldname','s0p','format','DoubleMat','mattype',1); 169 WriteData(fid,prefix,'object',self,'class','smb','fieldname','s0t','format','DoubleMat','mattype',1); 170 WriteData(fid,prefix,'object',self,'class','smb','fieldname','rlaps','format','Double') 171 WriteData(fid,prefix,'object',self,'class','smb','fieldname','rlapslgm','format','Double') 172 WriteData(fid,prefix,'object',self,'class','smb','fieldname','Tdiff','format','DoubleMat','mattype',1,'timeserieslength',2,'yts',md.constants.yts) 173 WriteData(fid,prefix,'object',self,'class','smb','fieldname','sealev','format','DoubleMat','mattype',1,'timeserieslength',2,'yts',md.constants.yts) 123 174 124 175 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 176 WriteData(fid,prefix,'object',self,'class','smb','fieldname','temperatures_presentday','format','DoubleMat','mattype',1,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts) 177 WriteData(fid,prefix,'object',self,'class','smb','fieldname','precipitations_presentday','format','DoubleMat','mattype',1,'scale',1./yts,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts) 178 WriteData(fid,prefix,'object',self,'class','smb','fieldname','istemperaturescaled','format','Boolean') 179 WriteData(fid,prefix,'object',self,'class','smb','fieldname','isprecipscaled','format','Boolean') 180 181 if self.istemperaturescaled==0: 182 WriteData(fid,prefix,'object',self,'class','smb','fieldname','temperatures_reconstructed','format','DoubleMat','mattype',1,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts) 183 184 if self.isprecipscaled==0: 185 WriteData(fid,prefix,'object',self,'class','smb','fieldname','precipitations_reconstructed','format','DoubleMat','mattype',1,'scale',1./yts,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts) 186 187 WriteData(fid,prefix,'object',self,'class','smb','fieldname','delta18o','format','DoubleMat','mattype',1,'timeserieslength',2,'yts',md.constants.yts) 188 WriteData(fid,prefix,'object',self,'class','smb','fieldname','dpermil','format','Double') 189 WriteData(fid,prefix,'object',self,'class','smb','fieldname','f','format','Double') 190 191 if self.issetpddfac: 192 WriteData(fid,prefix,'object',self,'class','smb','fieldname','pddfac_snow','format','DoubleMat','mattype',1,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts) 193 WriteData(fid,prefix,'object',self,'class','smb','fieldname','pddfac_ice','format','DoubleMat','mattype',1,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts) 194 130 195 #process requested outputs 131 196 outputs = self.requested_outputs … … 134 199 outputscopy=outputs[0:max(0,indices[0]-1)]+self.defaultoutputs(md)+outputs[indices[0]+1:] 135 200 outputs =outputscopy 136 WriteData(fid, 'data',outputs,'enum',SmbRequestedOutputsEnum(),'format','StringArray')201 WriteData(fid,prefix,'data',outputs,'name','md.smb.requested_outputs','format','StringArray') 137 202 138 203 # }}}
Note:
See TracChangeset
for help on using the changeset viewer.