Ignore:
Timestamp:
01/31/19 07:34:11 (6 years ago)
Author:
bdef
Message:

CHG: python scripts after 2to3 and indentation fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/py3/classes/SMBd18opdd.py

    r19898 r23670  
    1 import numpy
     1import numpy as np
    22from fielddisplay import fielddisplay
    3 from EnumDefinitions import *
    43from checkfield import checkfield
    54from WriteData import WriteData
     
    2120                self.rlapslgm                  = 0.
    2221                self.dpermil                   = 0.
     22                self.f                         = 0.
    2323                self.Tdiff                     = float('NaN')
    2424                self.sealev                    = float('NaN')
    2525                self.ismungsm                  = 0
    2626                self.isd18opd                  = 0
     27                self.issetpddfac               = 0
     28                self.istemperaturescaled       = 0
     29                self.isprecipscaled            = 0
    2730                self.delta18o                  = float('NaN')
    2831                self.delta18o_surface          = float('NaN')
    2932                self.temperatures_presentday   = float('NaN')
    3033                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')
    3138
    3239                #set defaults
     
    3845
    3946                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)'))
    4048                string="%s\n%s"%(string,fielddisplay(self,'desfac','desertification elevation factor (between 0 and 1, default is 0.5) [m]'))
    4149                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]'))
     
    4553                        string="%s\n%s"%(string,fielddisplay(self,'temperatures_presentday','monthly present day surface temperatures [K], required if delta18o/mungsm is activated'))
    4654                        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
    4764                        string="%s\n%s"%(string,fielddisplay(self,'delta18o','delta18o [per mil], required if pdd is activated and delta18o activated'))
    4865                        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]'))
    4971                string="%s\n%s"%(string,fielddisplay(self,'requested_outputs','additional outputs requested'))
    5072
     
    5577                if self.isd18opd: self.temperatures_presentday=project3d(md,'vector',self.temperatures_presentday,'type','node')
    5678                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')
    5784                self.s0p=project3d(md,'vector',self.s0p,'type','node')
    5885                self.s0t=project3d(md,'vector',self.s0t,'type','node')
     
    6592        def initialize(self,md): # {{{
    6693
    67                 if numpy.all(numpy.isnan(self.s0p)):
    68                         self.s0p=numpy.zeros((md.mesh.numberofvertices,1))
     94                if np.all(np.isnan(self.s0p)):
     95                        self.s0p=np.zeros((md.mesh.numberofvertices))
    6996                        print("      no SMBd18opdd.s0p specified: values set as zero")
    7097
    71                 if numpy.all(numpy.isnan(self.s0t)):
    72                         self.s0t=numpy.zeros((md.mesh.numberofvertices,1))
     98                if np.all(np.isnan(self.s0t)):
     99                        self.s0t=np.zeros((md.mesh.numberofvertices))
    73100                        print("      no SMBd18opdd.s0t specified: values set as zero")
    74101                       
     
    80107                self.ismungsm   = 0
    81108                self.isd18opd   = 1
     109                self.istemperaturescaled = 1
     110                self.isprecipscaled = 1
    82111                self.desfac     = 0.5
    83112                self.rlaps      = 6.5
    84113                self.rlapslgm   = 6.5
    85114                self.dpermil    = 2.4
    86 
     115                self.f          = 0.169
     116                self.issetpddfac = 0
    87117                return self
    88118        #}}}
    89119        def checkconsistency(self,md,solution,analyses):    # {{{
    90120
    91                 if MasstransportAnalysisEnum() in analyses:
     121                if 'MasstransportAnalysis' in analyses:
    92122                        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])
    95125                        md = checkfield(md,'fieldname','smb.rlaps','>=',0,'numel',[1])
    96126                        md = checkfield(md,'fieldname','smb.rlapslgm','>=',0,'numel',[1])
    97127
    98128                        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.
    99133                                md = checkfield(md,'fieldname','smb.temperatures_presentday','size',[md.mesh.numberofvertices+1,12],'NaN',1,'Inf',1,'timeseries',1)
    100134                                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)
    102147                                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
    104154                md = checkfield(md,'fieldname','masstransport.requested_outputs','stringrow',1)
    105155
    106156                return md
    107157        # }}}
    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)
    123174
    124175                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
    130195                #process requested outputs
    131196                outputs = self.requested_outputs
     
    134199                        outputscopy=outputs[0:max(0,indices[0]-1)]+self.defaultoutputs(md)+outputs[indices[0]+1:]
    135200                        outputs    =outputscopy
    136                 WriteData(fid,'data',outputs,'enum',SmbRequestedOutputsEnum(),'format','StringArray')
     201                WriteData(fid,prefix,'data',outputs,'name','md.smb.requested_outputs','format','StringArray')
    137202
    138203        # }}}
Note: See TracChangeset for help on using the changeset viewer.