Ignore:
Timestamp:
08/25/22 16:50:29 (3 years ago)
Author:
Mathieu Morlighem
Message:

merged trunk-jpl and trunk for revision 27230

Location:
issm/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk

  • issm/trunk/src

  • issm/trunk/src/m/plot/processdata.py

    r26744 r27232  
    88    datatype = 2 -> nodes
    99    datatype = 3 -> node quivers
    10     datatype = 4 -> patch
     10    datatype = 4 -> P1 patch
     11    datatype = 5 -> P0 patch
     12    datatype = 6 -> edges
    1113
    1214    Usage:
     
    2426    else:
    2527        numberofvertices2d = np.nan
     28
     29    try:
     30        numberofedges = md.mesh.numberofedges
     31    except AttributeError:
     32        numberofedges = np.nan
    2633
    2734    if options.exist('amr'):
     
    5259    # }}}
    5360
    54     #  log {{{
     61    # log {{{
    5562    if options.exist('log'):
    5663        cutoff = options.getfieldvalue('log', 1)
     
    5865    # }}}
    5966
    60     #  quiver plot {{{
     67    # quiver plot {{{
    6168    if datasize[1] > 1 and datasize[0] != numberofvertices + 1:
    62         if datasize[0] == numberofvertices and datasize[1] == 2:
     69        if datasize[0] == numberofvertices and datasize[1] in [2, 3]:
    6370            datatype = 3
     71            if md.mesh.dimension() == 3:
     72                if datasize[1] == 2:
     73                    data = np.hstack(data, np.zeros((datasize[0])))
     74                elif datasize[1] > 3:
     75                    raise ValueError('plotmodel error message: data should have two or three columns of length md.mesh.numberofvertices for a quiver plot')
    6476        else:
    65             raise ValueError('plotmodel error message: data should have two columns of length md.mesh.numberofvertices for a quiver plot')
     77            #we should have a patch
     78            print("Assuming that data provided is a patch")
     79            datatype = 4
     80            index = md.mesh.elements
     81            if np.shape(data)[1] < np.shape(index)[1]:
     82                    raise ValueError('plotmodel error message: data should have more columns than vertices per elements to plot a patch')
     83            procdata = np.zeros((numberofvertices))
     84            procdata[md.mesh.elements -1] = data[:, 0:np.shape(index)[1]]
     85            datasize = [numberofvertices, 1]
     86
    6687    # }}}
    6788
    68     #  element data{{{
     89    # element data{{{
    6990    if datasize[0] == numberofelements and datasize[1] == 1:
    7091        #initialize datatype if non patch
     
    93114    # }}}
    94115
    95     #  node data {{{
    96     if datasize[0] in [numberofvertices, numberofvertices2d] and datasize[1] == 1:
     116    # node data {{{
     117    elif datasize[0] in [numberofvertices, numberofvertices2d] and datasize[1] == 1:
    97118        datatype = 2
    98119        # AMR {{{
     
    101122            procdata = procdata[nonan]
    102123        # }}}
    103         #  Mask {{{
     124        # Mask {{{
    104125        if options.exist('mask'):
    105126            flags = options.getfieldvalue('mask')
     
    119140    # }}}
    120141
    121     #  spc time series {{{
    122     if datasize[0] == numberofvertices + 1:
     142    # edge data {{{
     143    elif datasize[0] in [numberofedges] and datasize[1] == 1:
     144        datatype = 6
     145        procdata = np.zeros((md.mesh.numberofelements))
     146        repeat = np.zeros((md.mesh.numberofelements))
     147        for index, edge in enumerate(md.mesh.edges[:, -2:]):
     148            procdata[edge - 1] += data[index] * np.asarray(edge - 1 > -1, dtype=int)
     149            repeat[edge - 1] += np.asarray(edge - 1 > -1, dtype=int)
     150        procdata = procdata / repeat
     151
     152        # }}}
     153    # }}}
     154
     155    # spc time series {{{
     156    elif datasize[0] == numberofvertices + 1:
    123157        datatype = 2
    124158        spccol = options.getfieldvalue('spccol', 0)
     
    127161        procdata = procdata[0:-1, spccol]
    128162
    129         #mask?
    130 
    131         #layer projection?
    132 
    133         #control arrow density if quiver plot
    134163    # }}}
    135164
    136     # convert rank - 2 array to rank - 1 {{{
     165    # convert rank -2 array to rank -1 {{{
    137166    if np.ndim(procdata) == 2 and np.shape(procdata)[1] == 1:
    138167        procdata = procdata.reshape(-1, )
     
    142171    nanfill = options.getfieldvalue('nan', -9999)
    143172    if np.any(np.isnan(procdata)):
    144         lb = np.nanmin(procdata)
    145         ub = np.nanmax(procdata)
    146         if lb == ub:
    147             lb = lb - 0.5
    148             ub = ub + 0.5
    149             nanfill = lb - 1
     173        if options.exist('caxis'):
     174            [lb, ub] = options.getfieldvalue('caxis')
     175        else:
     176            lb = np.nanmin(procdata)
     177            ub = np.nanmax(procdata)
     178            if lb == ub:
     179                lb = lb - 0.5
     180                ub = ub + 0.5
     181                nanfill = lb - 1
     182            options.addfielddefault('caxis', [lb, ub])
     183
    150184        procdata[np.isnan(procdata)] = nanfill
    151185        procdata = np.ma.array(procdata, mask=np.isnan(procdata))
    152         #clim looks to be deprecated and replaced by caxis
    153         #options.addfielddefault('clim', [lb, ub])
    154         options.addfielddefault('cmap_set_under', '1')
    155         print(("WARNING: nan's treated as", nanfill, "by default.  Change using pairoption 'nan', nan_fill_value in plotmodel call"))
     186        if nanfill < lb:
     187            options.addfielddefault('cmap_set_under', 'r')
     188        elif nanfill > ub:
     189            options.addfielddefault('cmap_set_over', 'k')
     190        if nanfill < ub and nanfill > lb:
     191            print(("WARNING: nan's treated as", nanfill, "by default. Which is in your data interval, change it with ['nan', value] in plotmodel options"))
    156192    # }}}
    157193
Note: See TracChangeset for help on using the changeset viewer.