Changeset 27970


Ignore:
Timestamp:
10/26/23 12:27:53 (17 months ago)
Author:
jdquinn
Message:

CHG: MATLAB -> Python; cleanup

Location:
issm/trunk-jpl
Files:
4 edited

Legend:

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

    r27967 r27970  
    4848                                md = checkfield(md,'fieldname','smb.smbref','timeseries',1,'NaN',1,'Inf',1);
    4949                                if max(max(abs(md.smb.smbref(1:end-1,:))))<1
    50               disp('!!! Warning: SMBgradients now expects smbref to be in m/yr ice eq. instead of mm/yr water eq.');
    51             end
     50                                        disp('!!! Warning: SMBgradients now expects smbref to be in m/yr ice eq. instead of mm/yr water eq.');
     51                                end
    5252                                md = checkfield(md,'fieldname','smb.b_pos','timeseries',1,'NaN',1,'Inf',1);
    5353                                md = checkfield(md,'fieldname','smb.b_neg','timeseries',1,'NaN',1,'Inf',1);
     
    6161
    6262                        disp(sprintf('\n   SMB gradients parameters:'));
    63                         fielddisplay(self,'href',' reference elevation from which deviation is used to calculate SMB adjustment in smb gradients method [m]');
    64                         fielddisplay(self,'smbref',' reference smb from which deviation is calculated in smb gradients method [m/yr ice equiv]');
    65                         fielddisplay(self,'b_pos',' slope of hs - smb regression line for accumulation regime required if smb gradients is activated');
    66                         fielddisplay(self,'b_neg',' slope of hs - smb regression line for ablation regime required if smb gradients is activated');
     63                        fielddisplay(self,'href','reference elevation from which deviation is used to calculate SMB adjustment in smb gradients method [m]');
     64                        fielddisplay(self,'smbref','reference smb from which deviation is calculated in smb gradients method [m/yr ice equiv]');
     65                        fielddisplay(self,'b_pos','slope of hs - smb regression line for accumulation regime required if smb gradients is activated');
     66                        fielddisplay(self,'b_neg','slope of hs - smb regression line for ablation regime required if smb gradients is activated');
    6767                        fielddisplay(self, 'steps_per_step', 'number of smb steps per time step');
    6868                        fielddisplay(self, 'averaging', 'averaging methods from short to long steps');
     
    9090                        pos  = find(ismember(outputs,'default'));
    9191                        if ~isempty(pos),
    92                                 outputs(pos) = [];                         %remove 'default' from outputs
     92                                outputs(pos) = [];                                %remove 'default' from outputs
    9393                                outputs      = [outputs defaultoutputs(self,md)]; %add defaults
    9494                        end
  • issm/trunk-jpl/src/m/classes/SMBgradients.py

    r27458 r27970  
     1import numpy as np
    12from fielddisplay import fielddisplay
    23from checkfield import checkfield
     
    56
    67class SMBgradients(object):
    7     """
    8     SMBgradients Class definition
     8    """SMBgradients Class definition
    99
    10        Usage:
    11           SMBgradients = SMBgradients();
     10    Usage:
     11        SMBgradients = SMBgradients();
    1212    """
    1313
    1414    def __init__(self):  # {{{
    15         self.href = float('NaN')
    16         self.smbref = float('NaN')
    17         self.b_pos = float('NaN')
    18         self.b_neg = float('NaN')
     15        self.href = np.nan
     16        self.smbref = np.nan
     17        self.b_pos = np.nan
     18        self.b_neg = np.nan
    1919        self.steps_per_step = 1
    2020        self.averaging = 0
     
    2626
    2727    def __repr__(self):  # {{{
    28         string = "   surface forcings parameters:"
     28        s = '   surface forcings parameters:\n'
     29        s += '{}\n'.format(fielddisplay(self, 'issmbgradients', 'is smb gradients method activated (0 or 1, default is 0)'))
     30        s += '{}\n'.format(fielddisplay(self, 'href', 'reference elevation from which deviation is used to calculate SMB adjustment in smb gradients method'))
     31        s += '{}\n'.format(fielddisplay(self, 'smbref', 'reference smb from which deviation is calculated in smb gradients method [m/yr ice equiv]'))
     32        s += '{}\n'.format(fielddisplay(self, 'b_pos', 'slope of hs - smb regression line for accumulation regime required if smb gradients is activated'))
     33        s += '{}\n'.format(fielddisplay(self, 'b_neg', 'slope of hs - smb regression line for ablation regime required if smb gradients is activated'))
     34        s += '{}\n'.format(fielddisplay(self, 'steps_per_step', 'number of smb steps per time step'))
     35        s += '{}\n'.format(fielddisplay(self, 'averaging', 'averaging methods from short to long steps'))
     36        s += '\t\t{}\n'.format('0: Arithmetic (default)')
     37        s += '\t\t{}\n'.format('1: Geometric')
     38        s += '\t\t{}\n'.format('2: Harmonic')
     39        s += '{}\n'.format(fielddisplay(self, 'requested_outputs', 'additional outputs requested'))
    2940
    30         string = "%s\n%s" % (string, fielddisplay(self, 'issmbgradients', 'is smb gradients method activated (0 or 1, default is 0)'))
    31         string = "%s\n%s" % (string, fielddisplay(self, 'href', ' reference elevation from which deviation is used to calculate SMB adjustment in smb gradients method'))
    32         string = "%s\n%s" % (string, fielddisplay(self, 'smbref', ' reference smb from which deviation is calculated in smb gradients method'))
    33         string = "%s\n%s" % (string, fielddisplay(self, 'b_pos', ' slope of hs - smb regression line for accumulation regime required if smb gradients is activated'))
    34         string = "%s\n%s" % (string, fielddisplay(self, 'b_neg', ' slope of hs - smb regression line for ablation regime required if smb gradients is activated'))
    35         string = "%s\n%s" % (string, fielddisplay(self, 'steps_per_step', 'number of smb steps per time step'))
    36         string = "%s\n%s" % (string, fielddisplay(self, 'averaging', 'averaging methods from short to long steps'))
    37         string = "%s\n\t\t%s" % (string, '0: Arithmetic (default)')
    38         string = "%s\n\t\t%s" % (string, '1: Geometric')
    39         string = "%s\n\t\t%s" % (string, '2: Harmonic')
    40         string = "%s\n%s" % (string, fielddisplay(self, 'requested_outputs', 'additional outputs requested'))
    41 
    42         return string
     41        return s
    4342    # }}}
    4443
    4544    def extrude(self, md):  # {{{
    46         #Nothing for now
     45        # Nothing for now
    4746        return self
    4847    # }}}
     
    5958
    6059    def initialize(self, md):  # {{{
    61         #Nothing for now
     60        # Nothing for now
    6261        return self
    6362    # }}}
    6463
    65     def checkconsistency(self, md, solution, analyses):    # {{{
     64    def checkconsistency(self, md, solution, analyses):  # {{{
    6665        if 'MasstransportAnalysis' in analyses:
    6766            md = checkfield(md, 'fieldname', 'smb.href', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
    6867            md = checkfield(md, 'fieldname', 'smb.smbref', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
     68            if np.max(np.max(np.abs(md.smb.smbref[0:-1,]))) < 1:
     69                print('!!! Warning: SMBgradients now expects smbref to be in m/yr ice eq. instead of mm/yr water eq.')
    6970            md = checkfield(md, 'fieldname', 'smb.b_pos', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
    7071            md = checkfield(md, 'fieldname', 'smb.b_neg', 'timeseries', 1, 'NaN', 1, 'Inf', 1)
     
    7677    # }}}
    7778
    78     def marshall(self, prefix, md, fid):    # {{{
     79    def marshall(self, prefix, md, fid):  # {{{
    7980        yts = md.constants.yts
    8081
     
    8788        WriteData(fid, prefix, 'object', self, 'fieldname', 'averaging', 'format', 'Integer')
    8889
    89         #process requested outputs
     90        # Process requested outputs
    9091        outputs = self.requested_outputs
    9192        indices = [i for i, x in enumerate(outputs) if x == 'default']
     
    9495            outputs = outputscopy
    9596        WriteData(fid, prefix, 'data', outputs, 'name', 'md.smb.requested_outputs', 'format', 'StringArray')
    96 
    9797    # }}}
  • issm/trunk-jpl/test/NightlyRun/test328.py

    r24633 r27970  
    1414md = setflowequation(md, 'SSA', 'all')
    1515md.smb = SMBgradients()
    16 md.smb.b_pos = -100. + 0.00005 * md.mesh.x - 0.0001 * md.mesh.y
    17 md.smb.b_neg = 250. + 0.000051 * md.mesh.x - 0.00011 * md.mesh.y
     16md.smb.b_pos = (-100. + 0.00005 * md.mesh.x - 0.0001 * md.mesh.y) / 1000. * md.materials.rho_freshwater / md.materials.rho_ice
     17md.smb.b_neg = (250. + 0.000051 * md.mesh.x - 0.00011 * md.mesh.y) / 1000. * md.materials.rho_freshwater / md.materials.rho_ice
    1818md.transient.requested_outputs = ['default', 'TotalSmb']
    1919md.smb.href = copy.deepcopy(md.geometry.surface)
    20 md.smb.smbref = 1000. - 0.001 * md.mesh.x - 0.005 * md.mesh.y
     20md.smb.smbref= (1000. - 0.001 * md.mesh.x - 0.005 * md.mesh.y) / 1000. * md.materials.rho_freshwater / md.materials.rho_ice
    2121md.cluster = generic('name', gethostname(), 'np', 3)
    2222md = solve(md, 'Transient')
  • issm/trunk-jpl/test/NightlyRun/test329.py

    r24261 r27970  
    1515md = setflowequation(md, 'HO', 'all')
    1616md.smb = SMBgradients()
    17 md.smb.b_pos = -100. + 0.00005 * md.mesh.x - 0.0001 * md.mesh.y
    18 md.smb.b_neg = 250. + 0.000051 * md.mesh.x - 0.00011 * md.mesh.y
     17md.smb.b_pos = (-100. + 0.00005 * md.mesh.x - 0.0001 * md.mesh.y) / 1000. * md.materials.rho_freshwater / md.materials.rho_ice
     18md.smb.b_neg = (250. + 0.000051 * md.mesh.x - 0.00011 * md.mesh.y) / 1000. * md.materials.rho_freshwater / md.materials.rho_ice
    1919md.smb.href = copy.deepcopy(md.geometry.surface)
    20 md.smb.smbref = 1000. - 0.001 * md.mesh.x - 0.005 * md.mesh.y
     20md.smb.smbref = (1000. - 0.001 * md.mesh.x - 0.005 * md.mesh.y) / 1000. * md.materials.rho_freshwater / md.materials.rho_ice
    2121md.transient.requested_outputs = ['default', 'TotalSmb']
    2222md.cluster = generic('name', gethostname(), 'np', 3)
Note: See TracChangeset for help on using the changeset viewer.