Changeset 26760


Ignore:
Timestamp:
01/10/22 02:56:47 (3 years ago)
Author:
bdef
Message:

CHG:fixing formating

File:
1 edited

Legend:

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

    r26750 r26760  
    4343    def setdefaultparameters(self):  # {{{
    4444        # Type of stabilization used
    45         self.isstochasticforcing = 0 # stochasticforcing is turned off by default
    46         self.fields = [] # Need to initialize to list to avoid "RuntimeError: object of type 'float' has no len()" on import of class
    47         self.randomflag = 1 # true randomness is implemented by default
     45        self.isstochasticforcing = 0  # stochasticforcing is turned off by default
     46        self.fields = []  # Need to initialize to list to avoid "RuntimeError: object of type 'float' has no len()" on import of class
     47        self.randomflag = 1  # true randomness is implemented by default
    4848        return self
    4949    #}}}
     
    6363
    6464        # Check that all fields agree with the corresponding md class and if any field needs the default params
    65         checkdefaults = False # Need to check defaults only if one of the fields does not have its own dimensionality
     65        checkdefaults = False  # Need to check defaults only if one of the fields does not have its own dimensionality
    6666        structstoch = self.structstochforcing()
    6767        for field in self.fields:
     
    9191                if (type(md.friction).__name__ != mdname):
    9292                    raise TypeError('stochasticforcing field {} is only implemented for default friction'.format(field))
    93                 if (md.friction.coupling!=0 and md.friction.coupling!=1 and md.friction.coupling!=2):
     93                if md.friction.coupling not in[0, 1, 2]:
    9494                    raise TypeError('stochasticforcing field {} is only implemented for cases md.friction.coupling 0 or 1 or 2'.format(field))
    95                 if (np.any(md.friction.q==0)):
    96                         raise TypeError('stochasticforcing field {} requires non-zero q exponent'.format(field))
     95                if (np.any(md.friction.q == 0)):
     96                    raise TypeError('stochasticforcing field {} requires non-zero q exponent'.format(field))
    9797
    9898            # Checking for specific dimensions
    99             if not (field == 'SMBautoregression' or field == 'FrontalForcingsRignotAutoregression'):
    100                 checkdefaults = True # field with non-specific dimensionality
     99            if field not in['SMBautoregression', 'FrontalForcingsRignotAutoregression']:
     100                checkdefaults = True  # field with non-specific dimensionality
    101101
    102102        # Retrieve sum of all the field dimensionalities
    103103        size_tot = self.defaultdimension * num_fields
    104         indSMBar = -1 # About to check for index of SMBautoregression
    105         indTFar = -1 # About to check for index of FrontalForcingsRignotAutoregression
     104        indSMBar = -1  # About to check for index of SMBautoregression
     105        indTFar = -1  # About to check for index of FrontalForcingsRignotAutoregression
    106106        if ('SMBautoregression' in self.fields):
    107107            size_tot = size_tot - self.defaultdimension + md.smb.num_basins
    108             indSMBar = self.fields.index('SMBautoregression') # Index of SMBar, now check for consistency with TFar timestep (08Nov2021)
     108            indSMBar = self.fields.index('SMBautoregression')  # Index of SMBar, now check for consistency with TFar timestep (08Nov2021)
    109109        if ('FrontalForcingsRignotAutoregression' in self.fields):
    110110            size_tot = size_tot - self.defaultdimension + md.frontalforcings.num_basins
    111             indTFar = self.fields.index('FrontalForcingsRignotAutoregression') # Index of TFar, now check for consistency with SMBar timestep (08Nov2021)
    112         if (indSMBar != -1 and indTFar != -1): # Both autoregressive models are used: check autoregressive time step consistency
     111            indTFar = self.fields.index('FrontalForcingsRignotAutoregression')  # Index of TFar, now check for consistency with SMBar timestep (08Nov2021)
     112        if (indSMBar != -1 and indTFar != -1):  # Both autoregressive models are used: check autoregressive time step consistency
    113113            covsum = self.covariance[np.sum(self.defaultdimensions[0:indSMBar]).astype(int):np.sum(self.defaultdimensions[0:indSMBar + 1]).astype(int), np.sum(self.defaultdimensions[0:indTFar]).astype(int):np.sum(self.defaultdimensions[0:indTFar + 1]).astype(int)]
    114114            if((md.smb.ar_timestep != md.frontalforcings.ar_timestep) and np.any(covsum != 0)):
     
    121121        if (checkdefaults):
    122122            md = checkfield(md, 'fieldname', 'stochasticforcing.defaultdimension', 'numel', 1, 'NaN', 1, 'Inf', 1, '>', 0)
    123             md = checkfield(md, 'fieldname', 'stochasticforcing.default_id','Inf',1,'NaN',1,'>=',0,'<=',self.defaultdimension,'size', [md.mesh.numberofelements])
     123            md = checkfield(md, 'fieldname', 'stochasticforcing.default_id', 'Inf', 1, 'NaN', 1, '>=', 0, '<=', self.defaultdimension, 'size', [md.mesh.numberofelements])
    124124        return md
    125125    # }}}
     
    139139        else:
    140140            # Retrieve dimensionality of each field
    141             dimensions = self.defaultdimension * np.ones((num_fields,))
     141            dimensions = self.defaultdimension * np.ones((num_fields))
    142142            for ind, field in enumerate(self.fields):
    143143                # Checking for specific dimensions
     
    148148
    149149            # Scaling covariance matrix (scale column-by-column and row-by-row)
    150             scaledfields = ['DefaultCalving','FloatingMeltRate','SMBautoregression','SMBforcing'] # list of fields that need scaling * 1/yts
     150            scaledfields = ['DefaultCalving', 'FloatingMeltRate', 'SMBautoregression', 'SMBforcing'] # list of fields that need scaling * 1/yts
    151151            tempcovariance = np.copy(self.covariance)
    152152            for i in range(num_fields):
     
    161161                self.default_id = np.zeros(md.mesh.numberofelements)
    162162            # Reshape dimensions as column array for marshalling
    163             dimensions = dimensions.reshape(1,len(dimensions))
     163            dimensions = dimensions.reshape(1, len(dimensions))
    164164
    165165            WriteData(fid, prefix, 'data', num_fields, 'name', 'md.stochasticforcing.num_fields', 'format', 'Integer')
    166166            WriteData(fid, prefix, 'object', self, 'fieldname', 'fields', 'format', 'StringArray')
    167             WriteData(fid, prefix, 'data', dimensions, 'name', 'md.stochasticforcing.dimensions', 'format', 'IntMat','mattype',2)
     167            WriteData(fid, prefix, 'data', dimensions, 'name', 'md.stochasticforcing.dimensions', 'format', 'IntMat', 'mattype', 2)
    168168            WriteData(fid, prefix, 'object', self, 'fieldname', 'default_id', 'format', 'IntMat', 'mattype', 2)  #12Nov2021 make sure this is zero-indexed!
    169169            WriteData(fid, prefix, 'object', self, 'fieldname', 'defaultdimension', 'format', 'Integer')
Note: See TracChangeset for help on using the changeset viewer.