Changeset 26569


Ignore:
Timestamp:
11/09/21 06:58:37 (3 years ago)
Author:
bdef
Message:

CHG:modification to enable AMR plotting

Location:
issm/trunk-jpl/src/m/plot
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/plot/colormaps/demmap.py

    r24261 r26569  
    6464        cmx = nland * interval
    6565
    66     clim = [cmn, cmx]
    67 
    6866    if strcmpi(colorscheme, 'dem'):
    6967        # concatenate and transpose to match matplotlib's colormap format
  • issm/trunk-jpl/src/m/plot/plotmodel.py

    r26184 r26569  
    1414def plotmodel(md, *args):
    1515    '''
    16     PLOTMODEL - At command prompt, type 'plotdoc()' for additional 
     16    PLOTMODEL - At command prompt, type 'plotdoc()' for additional
    1717    documentation.
    1818
     
    3131    subplotwidth = ceil(sqrt(numberofplots))
    3232
    33     # TODO: Check that commenting this out is correct; we do not need a hold 
     33    # TODO: Check that commenting this out is correct; we do not need a hold
    3434    # under matplotlib, right?
    3535    #
     
    6060    # Go through plots
    6161    #
    62     # NOTE: The following is where Python + matplolib differs substantially in 
     62    # NOTE: The following is where Python + matplolib differs substantially in
    6363    #       implementation and inteface from MATLAB.
    6464    #
     
    8383            plotnum = None
    8484
    85         # NOTE: The inline comments for each of the following parameters are 
     85        # NOTE: The inline comments for each of the following parameters are
    8686        #       taken from https://matplotlib.org/api/_as_gen/mpl_toolkits.axes_grid1.axes_grid.ImageGrid.html
    8787        #
     
    9595        #
    9696        # TODO:
    97         # - Add 'edge' option (research if there is a corresponding option in 
     97        # - Add 'edge' option (research if there is a corresponding option in
    9898        #   MATLAB)?
    9999        #
     
    118118        #   rect(float, float, float, float) or int
    119119        #
    120         # The axes position, as a (left, bottom, width, height) tuple or as a 
     120        # The axes position, as a (left, bottom, width, height) tuple or as a
    121121        # three-digit subplot position code (e.g., "121").
    122122        #
     
    127127            direction=direction,
    128128            axes_pad=axes_pad,
    129             add_all=add_all,
    130129            share_all=share_all,
    131130            label_mode=label_mode,
  • issm/trunk-jpl/src/m/plot/processdata.py

    r26352 r26569  
    1515    See also: PLOTMODEL, PROCESSMESH
    1616    """
    17     # {{{ Initialization and grabbing auxiliaries
     17    # Initialization and grabbing auxiliaries {{{
    1818    # check format
    1919    if (len(data) == 0 or (len(data) == 1 and not isinstance(data, dict) and np.isnan(data).all())):
     
    2222    if 'numberofvertices2d' in dir(md.mesh):
    2323        numberofvertices2d = md.mesh.numberofvertices2d
    24         numberofelements2d = md.mesh.numberofelements2d
    2524    else:
    2625        numberofvertices2d = np.nan
    27         numberofelements2d = np.nan
     26
     27    if options.exist('amr'):
     28        step = options.getfieldvalue('amr', 0)
     29        numberofvertices = len(md.results.TransientSolution[step].MeshX)
     30        numberofelements = np.shape(md.results.TransientSolution[step].MeshElements)[0]
     31    else:
     32        numberofvertices = md.mesh.numberofvertices
     33        numberofelements = md.mesh.numberofelements
     34
    2835    procdata = np.copy(data)
    2936    #initialize datatype
     
    4451        raise ValueError('data passed to plotmodel has bad dimensions; check that column vectors are rank - 1')
    4552    # }}}
    46     # {{{ process NaN's if any
     53
     54    #  log {{{
     55    if options.exist('log'):
     56        cutoff = options.getfieldvalue('log', 1)
     57        procdata[np.where(procdata < cutoff)] = cutoff
     58    # }}}
     59
     60    #  quiver plot {{{
     61    if datasize[1] > 1 and datasize[0] != numberofvertices + 1:
     62        if datasize[0] == numberofvertices and datasize[1] == 2:
     63            datatype = 3
     64        else:
     65            raise ValueError('plotmodel error message: data should have two columns of length md.mesh.numberofvertices for a quiver plot')
     66    # }}}
     67
     68    #  element data{{{
     69    if datasize[0] == numberofelements and datasize[1] == 1:
     70        #initialize datatype if non patch
     71        if datatype != 4 and datatype != 5:
     72            datatype = 1
     73        # AMR {{{
     74        if options.exist('amr'):
     75            nonan = np.nonzero(~np.isnan(md.results.TransientSolution[step].MeshElements))
     76            procdata = procdata[nonan]
     77        # }}}
     78        # mask {{{
     79        if options.exist('mask'):
     80            flags = options.getfieldvalue('mask')
     81            hide = np.invert(flags)
     82            if np.size(flags) == numberofvertices:
     83                EltMask = np.asarray([np.any(np.in1d(index, np.where(hide))) for index in md.mesh.elements - 1])
     84                procdata = np.ma.array(procdata, mask=EltMask)
     85                options.addfielddefault('cmap_set_bad', 'w')
     86            elif np.size(flags) == numberofelements:
     87                procdata = np.ma.array(procdata, mask=hide)
     88                options.addfielddefault('cmap_set_bad', 'w')
     89            else:
     90                print('Warning: processdata.py: mask length not supported yet (supported length are md.mesh.numberofvertices and md.mesh.numberofelements')
     91        # }}}
     92
     93    # }}}
     94
     95    #  node data {{{
     96    if datasize[0] in [numberofvertices, numberofvertices2d] and datasize[1] == 1:
     97        datatype = 2
     98        # AMR {{{
     99        if options.exist('amr'):
     100            nonan = np.nonzero(~np.isnan(md.results.TransientSolution[step].MeshX))
     101            procdata = procdata[nonan]
     102        # }}}
     103        #  Mask {{{
     104        if options.exist('mask'):
     105            flags = options.getfieldvalue('mask')
     106            hide = np.invert(flags)
     107            if np.size(flags) == numberofvertices:
     108                procdata = np.ma.array(procdata, mask=hide)
     109                options.addfielddefault('cmap_set_bad', 'w')
     110            elif np.size(flags) == numberofelements:
     111                NodeMask = np.zeros(np.shape(md.mesh.x), dtype=bool)
     112                HideElt = md.mesh.elements[np.where(hide)[0]] - 1
     113                NodeMask[HideElt] = True
     114                procdata = np.ma.array(procdata, mask=NodeMask)
     115                options.addfielddefault('cmap_set_bad', 'w')
     116            else:
     117                print('Warning: processdata.py: mask length not supported yet (supported length are md.mesh.numberofvertices and md.mesh.numberofelements')
     118        # }}}
     119    # }}}
     120
     121    #  spc time series {{{
     122    if datasize[0] == numberofvertices + 1:
     123        datatype = 2
     124        spccol = options.getfieldvalue('spccol', 0)
     125        print('multiple-column spc field; specify column to plot using option "spccol"')
     126        print(('column ', spccol, ' plotted for time: ', procdata[-1, spccol]))
     127        procdata = procdata[0:-1, spccol]
     128
     129        #mask?
     130
     131        #layer projection?
     132
     133        #control arrow density if quiver plot
     134    # }}}
     135
     136    # convert rank - 2 array to rank - 1 {{{
     137    if np.ndim(procdata) == 2 and np.shape(procdata)[1] == 1:
     138        procdata = procdata.reshape(-1, )
     139    # }}}
     140
     141    #  process NaN's if any {{{
    47142    nanfill = options.getfieldvalue('nan', -9999)
    48143    if np.any(np.isnan(procdata)):
     
    53148            ub = ub + 0.5
    54149            nanfill = lb - 1
    55     #procdata[np.isnan(procdata)] = nanfill
     150        procdata[np.isnan(procdata)] = nanfill
    56151        procdata = np.ma.array(procdata, mask=np.isnan(procdata))
    57         options.addfielddefault('clim', [lb, ub])
     152        #clim looks to be deprecated and replaced by caxis
     153        #options.addfielddefault('clim', [lb, ub])
    58154        options.addfielddefault('cmap_set_under', '1')
    59155        print(("WARNING: nan's treated as", nanfill, "by default.  Change using pairoption 'nan', nan_fill_value in plotmodel call"))
    60156    # }}}
    61     # {{{ log
    62     if options.exist('log'):
    63         cutoff = options.getfieldvalue('log', 1)
    64         procdata[np.where(procdata < cutoff)] = cutoff
    65     # }}}
    66     # {{{ quiver plot
    67     if datasize[1] > 1 and datasize[0] != md.mesh.numberofvertices + 1:
    68         if datasize[0] == md.mesh.numberofvertices and datasize[1] == 2:
    69             datatype = 3
    70         else:
    71             raise ValueError('plotmodel error message: data should have two columns of length md.mesh.numberofvertices for a quiver plot')
    72     # }}}
    73     # {{{ element data
    74157
    75     if datasize[0] == md.mesh.numberofelements and datasize[1] == 1:
    76         #initialize datatype if non patch
    77         if datatype != 4 and datatype != 5:
    78             datatype = 1
    79     # {{{mask
    80         if options.exist('mask'):
    81             flags = options.getfieldvalue('mask')
    82             hide = np.invert(flags)
    83             if np.size(flags) == md.mesh.numberofvertices:
    84                 EltMask = np.asarray([np.any(np.in1d(index, np.where(hide))) for index in md.mesh.elements - 1])
    85                 procdata = np.ma.array(procdata, mask=EltMask)
    86                 options.addfielddefault('cmap_set_bad', 'w')
    87             elif np.size(flags) == md.mesh.numberofelements:
    88                 procdata = np.ma.array(procdata, mask=hide)
    89                 options.addfielddefault('cmap_set_bad', 'w')
    90             else:
    91                 print('Warning: processdata.py: mask length not supported yet (supported length are md.mesh.numberofvertices and md.mesh.numberofelements')
    92     # }}}
    93 
    94     # }}}
    95     # {{{ node data
    96     if datasize[0] == md.mesh.numberofvertices and datasize[1] == 1:
    97         datatype = 2
    98     # {{{ Mask
    99         if options.exist('mask'):
    100             flags = options.getfieldvalue('mask')
    101             hide = np.invert(flags)
    102             if np.size(flags) == md.mesh.numberofvertices:
    103                 procdata = np.ma.array(procdata, mask=hide)
    104                 options.addfielddefault('cmap_set_bad', 'w')
    105             elif np.size(flags) == md.mesh.numberofelements:
    106                 NodeMask = np.zeros(np.shape(md.mesh.x), dtype=bool)
    107                 HideElt = md.mesh.elements[np.where(hide)[0]] - 1
    108                 NodeMask[HideElt] = True
    109                 procdata = np.ma.array(procdata, mask=NodeMask)
    110                 options.addfielddefault('cmap_set_bad', 'w')
    111             else:
    112                 print('Warning: processdata.py: mask length not supported yet (supported length are md.mesh.numberofvertices and md.mesh.numberofelements')
    113     # }}}
    114     # }}}
    115     # {{{ spc time series
    116     if datasize[0] == md.mesh.numberofvertices + 1:
    117         datatype = 2
    118         spccol = options.getfieldvalue('spccol', 0)
    119         print('multiple-column spc field; specify column to plot using option "spccol"')
    120         print(('column ', spccol, ' plotted for time: ', procdata[-1, spccol]))
    121         procdata = procdata[0:-1, spccol]
    122 
    123     #mask?
    124 
    125     #layer projection?
    126 
    127     #control arrow density if quiver plot
    128     # }}}
    129     # {{{ convert rank - 2 array to rank - 1
    130     if np.ndim(procdata) == 2 and np.shape(procdata)[1] == 1:
    131         procdata = procdata.reshape(-1, )
    132     # }}}
    133     # {{{ if datatype is still zero, error out
     158    #  if datatype is still zero, error out {{{
    134159    if datatype == 0:
    135160        raise ValueError("processdata error: data provided not recognized or not supported")
  • issm/trunk-jpl/src/m/plot/processmesh.py

    r25456 r26569  
    4141    if hasattr(md.mesh, 'elements2d'):
    4242        elements2d = md.mesh.elements2d
     43        numofvertices2d = md.mesh.numberofvertices2d
     44        numofelements2d = md.mesh.numberofelements2d
     45    else:
     46        numofvertices2d = np.nan
     47        numofelements2d = np.nan
    4348
    4449    if options.exist('amr'):
    4550        step = options.getfieldvalue('amr')
    46         x = md.results.TransientSolution[step].MeshX
    47         y = md.results.TransientSolution[step].MeshY
    48         elements = md.results.TransientSolution[step].MeshElements
     51        nonan = np.nonzero(~np.isnan(md.results.TransientSolution[step].MeshX))
     52        x = md.results.TransientSolution[step].MeshX[nonan]
     53        y = md.results.TransientSolution[step].MeshY[nonan]
     54        nonan = np.nonzero(~np.isnan(md.results.TransientSolution[step].MeshElements))
     55        elements = md.results.TransientSolution[step].MeshElements[nonan] - 1
     56        eldim = np.shape(md.results.TransientSolution[step].MeshElements)[1]
     57        elements = np.reshape(elements, ((int(len(elements) / eldim), eldim)))
     58
    4959    else:
    50         elements = md.mesh.elements
     60        elements = md.mesh.elements - 1
    5161        if options.getfieldvalue('coord', 'xy') != 'latlon':
    5262            x = md.mesh.x
     
    6575        z = getattr(md, z)
    6676
     77    force2D = numofelements2d in np.shape(data) or numofvertices2d in np.shape(data)
    6778    #is it a 2D plot?
    68     if md.mesh.dimension() == 2 or options.getfieldvalue('layer', 0) >= 1:
     79    if md.mesh.dimension() == 2 or options.getfieldvalue('layer', 0) >= 1 or force2D:
    6980        is2d = 1
    7081    else:
    7182        is2d = 0
    7283
    73     elements = md.mesh.elements - 1
    74 
    7584    #layer projection?
    76     if options.getfieldvalue('layer', 0) >= 1:
     85    if options.getfieldvalue('layer', 0) >= 1 or force2D:
    7786        if options.getfieldvalue('coord', 'xy') == 'latlon':
    7887            raise Exception('processmesh error message: cannot work with 3D meshes for now')
Note: See TracChangeset for help on using the changeset viewer.