Ignore:
Timestamp:
08/08/12 15:50:07 (13 years ago)
Author:
jschierm
Message:

NEW: A bunch more python checkconsistency and marshall methods for sub-classes (plus other minor changes).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/classes/surfaceforcings.py

    r12123 r12949  
    11#module imports
    22from fielddisplay import fielddisplay
     3from EnumDefinitions import *
     4from checkfield import *
     5from WriteData import *
    36
    47class surfaceforcings:
     
    811                self.precipitation = float('NaN')
    912                self.mass_balance  = float('NaN')
     13                self.ispdd = 0
     14                self.issmbgradients = 0
     15                self.isdelta18o = 0
     16                self.hc = float('NaN')
     17                self.smb_pos_max = float('NaN')
     18                self.smb_pos_min = float('NaN')
     19                self.a_pos = float('NaN')
     20                self.b_pos = float('NaN')
     21                self.a_neg = float('NaN')
     22                self.b_neg = float('NaN')
     23                self.monthlytemperatures = float('NaN')
     24                self.delta18o = float('NaN')
     25                self.delta18o_surface = float('NaN')
     26                self.temperatures_presentday = float('NaN')
     27                self.temperatures_lgm = float('NaN')
     28                self.precipitations_presentday = float('NaN')
    1029
    1130                #set defaults
     
    1938                string="%s\n\n%s"%(string,fielddisplay(obj,'precipitation','surface precipitation [m/yr water eq]'))
    2039                string="%s\n%s"%(string,fielddisplay(obj,'mass_balance','surface mass balance [m/yr ice eq]'))
     40                string="%s\n%s"%(string,fielddisplay(obj,'ispdd','is pdd activated (0 or 1, default is 0)'))
     41                string="%s\n%s"%(string,fielddisplay(obj,'isdelta18o','is temperature and precipitation delta18o parametrisation activated (0 or 1, default is 0)'))
     42                string="%s\n%s"%(string,fielddisplay(obj,'monthlytemperatures','monthly surface temperatures [Kelvin], required if pdd is activated and delta18o not activated'))
     43                string="%s\n%s"%(string,fielddisplay(obj,'precipitation','surface precipitation [m/yr water eq]'))
     44                string="%s\n%s"%(string,fielddisplay(obj,'temperatures_presentday','monthly present day surface temperatures [Kelvin], required if pdd is activated and delta18o activated'))
     45                string="%s\n%s"%(string,fielddisplay(obj,'temperatures_lgm','monthly LGM surface temperatures [Kelvin], required if pdd is activated and delta18o activated'))
     46                string="%s\n%s"%(string,fielddisplay(obj,'precipitations_presentday','monthly surface precipitation [m/yr water eq], required if pdd is activated and delta18o activated'))
     47                string="%s\n%s"%(string,fielddisplay(obj,'delta18o','delta18o, required if pdd is activated and delta18o activated'))
     48                string="%s\n%s"%(string,fielddisplay(obj,'delta18o_surface','surface elevation of the delta18o site, required if pdd is activated and delta18o activated'))
     49                string="%s\n%s"%(string,fielddisplay(obj,'issmbgradients','is smb gradients method activated (0 or 1, default is 0)'))
     50                string="%s\n%s"%(string,fielddisplay(obj,'hc',' elevation of intersection between accumulation and ablation regime required if smb gradients is activated'))
     51                string="%s\n%s"%(string,fielddisplay(obj,'smb_pos_max',' maximum value of positive smb required if smb gradients is activated'))
     52                string="%s\n%s"%(string,fielddisplay(obj,'smb_pos_min',' minimum value of positive smb required if smb gradients is activated'))
     53                string="%s\n%s"%(string,fielddisplay(obj,'a_pos',' intercept of hs - smb regression line for accumulation regime required if smb gradients is activated'))
     54                string="%s\n%s"%(string,fielddisplay(obj,'b_pos',' slope of hs - smb regression line for accumulation regime required if smb gradients is activated'))
     55                string="%s\n%s"%(string,fielddisplay(obj,'a_neg',' intercept of hs - smb regression line for ablation regime required if smb gradients is activated'))
     56                string="%s\n%s"%(string,fielddisplay(obj,'b_neg',' slope of hs - smb regression line for ablation regime required if smb gradients is activated'))
    2157
    2258                return string
     
    2561        def setdefaultparameters(obj):
    2662                # {{{setdefaultparameters
     63                 
     64                #pdd method not used in default mode
     65                obj.ispdd=0
     66                obj.issmbgradients=0
     67                obj.isdelta18o=0
     68
    2769                return obj
    2870        #}}}
    2971
     72        def checkconsistency(self,md,solution,analyses):    # {{{
     73
     74                if PrognosticAnalysisEnum in analyses:
     75                        md = checkfield(md,'surfaceforcings.ispdd','numel',1,'values',[0,1])
     76                        md = checkfield(md,'surfaceforcings.issmbgradients','numel',1,'values',[0,1])
     77                        if   self.ispdd:
     78                                if not self.isdelta18o:
     79                                        md = checkfield(md,'surfaceforcings.monthlytemperatures','forcing',1,'NaN',1)
     80                                        md = checkfield(md,'surfaceforcings.precipitation','forcing',1,'NaN',1)
     81                                else:
     82                                        md = checkfield(md,'surfaceforcings.delta18o','NaN',1)
     83                                        md = checkfield(md,'surfaceforcings.delta18o_surface','NaN',1)
     84                                        md = checkfield(md,'surfaceforcings.temperatures_presentday','size',[md.mesh.numberofvertices+1,12],'NaN',1)
     85                                        md = checkfield(md,'surfaceforcings.temperatures_lgm','size',[md.mesh.numberofvertices+1,12],'NaN',1)
     86                                        md = checkfield(md,'surfaceforcings.precipitations_presentday','size',[md.mesh.numberofvertices+1,12],'NaN',1)
     87                        elif self.issmbgradients:
     88                                md = checkfield(md,'surfaceforcings.hc','forcing',1,'NaN',1)
     89                                md = checkfield(md,'surfaceforcings.smb_pos_max','forcing',1,'NaN',1)
     90                                md = checkfield(md,'surfaceforcings.smb_pos_min','forcing',1,'NaN',1)
     91                                md = checkfield(md,'surfaceforcings.a_pos','forcing',1,'NaN',1)
     92                                md = checkfield(md,'surfaceforcings.b_pos','forcing',1,'NaN',1)
     93                                md = checkfield(md,'surfaceforcings.a_neg','forcing',1,'NaN',1)
     94                                md = checkfield(md,'surfaceforcings.b_neg','forcing',1,'NaN',1)
     95                        else:
     96                                md = checkfield(md,'surfaceforcings.mass_balance','forcing',1,'NaN',1)
     97
     98                if BalancethicknessAnalysisEnum in analyses:
     99                        md = checkfield(md,'surfaceforcings.mass_balance','size',[md.mesh.numberofvertices],'NaN',1)
     100
     101                return md
     102        # }}}
     103
     104        def marshall(self,fid):    # {{{
     105                WriteData(fid,'object',self,'fieldname','precipitation','format','DoubleMat','mattype',1)
     106                WriteData(fid,'object',self,'fieldname','mass_balance','format','DoubleMat','mattype',1)
     107                WriteData(fid,'object',self,'fieldname','ispdd','format','Boolean')
     108                WriteData(fid,'object',self,'fieldname','isdelta18o','format','Boolean')
     109
     110                if self.ispdd:
     111                        if self.isdelta18o:
     112                                WriteData(fid,'object',self,'fieldname','temperatures_presentday','format','DoubleMat','mattype',1)
     113                                WriteData(fid,'object',self,'fieldname','temperatures_lgm','format','DoubleMat','mattype',1)
     114                                WriteData(fid,'object',self,'fieldname','precipitations_presentday','format','DoubleMat','mattype',1)
     115                                WriteData(fid,'object',self,'fieldname','delta18o_surface','format','DoubleMat','mattype',1)
     116                                WriteData(fid,'object',self,'fieldname','delta18o','format','DoubleMat','mattype',1)
     117                        else:
     118                                WriteData(fid,'object',self,'fieldname','monthlytemperatures','format','DoubleMat','mattype',1)
     119                                WriteData(fid,'object',self,'fieldname','precipitation','format','DoubleMat','mattype',1)
     120
     121                WriteData(fid,'object',self,'fieldname','issmbgradients','format','Boolean')
     122
     123                if self.issmbgradients:
     124                        WriteData(fid,'object',self,'fieldname','hc','format','DoubleMat','mattype',1)
     125                        WriteData(fid,'object',self,'fieldname','smb_pos_max','format','DoubleMat','mattype',1)
     126                        WriteData(fid,'object',self,'fieldname','smb_pos_min','format','DoubleMat','mattype',1)
     127                        WriteData(fid,'object',self,'fieldname','a_pos','format','DoubleMat','mattype',1)
     128                        WriteData(fid,'object',self,'fieldname','b_pos','format','DoubleMat','mattype',1)
     129                        WriteData(fid,'object',self,'fieldname','a_neg','format','DoubleMat','mattype',1)
     130                        WriteData(fid,'object',self,'fieldname','b_neg','format','DoubleMat','mattype',1)
     131        # }}}
     132
Note: See TracChangeset for help on using the changeset viewer.