Changeset 574


Ignore:
Timestamp:
10/03/12 15:27:58 (4 years ago)
Author:
mmckerns
Message:

enable 2D scenario plots, by passing a tuple to 'mask'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mystic/scripts/support_hypercube_scenario.py

    r573 r574  
    2323will label the axes with standard LaTeX math formatting. Note that the leading 
    2424space is required, while the trailing space aligns the text with the axis 
    25 instead of the plot frame.  The option 'filter' is used to select datapoints 
    26 from a given dataset, and takes a quoted list. 
     25instead of the plot frame.  The option "filter" is used to select datapoints 
     26from a given dataset, and takes a quoted list.  A "mask" can be given as an 
     27integer or a tuple of integers; when the mask is a tuple, the plot will be 2D.   
     28The option "vertical" will plot the dataset values on the vertical axis; for 
     292D plots, cones are always plotted on the vertical axis. 
    2730 
    2831Required Inputs: 
     
    3336""" 
    3437ZERO = 1.0e-6  # zero-ish 
    35 _2D = False # use 2d plots 
    3638 
    3739#### building the cone primitive #### 
     
    102104def plot_bowtie(ax, data, slope, bounds, color='0.75', axis=None): 
    103105  if axis not in range(len(bounds)-1): return ax 
    104   from numpy import asarray 
     106  from numpy import asarray, inf 
    105107  data = asarray(data) 
    106   ylo = slope[axis] * (bounds[0][0] - data.T[0]) + data.T[1] 
    107   yhi = slope[axis] * (bounds[0][1] - data.T[0]) + data.T[1] 
    108   zhi = -slope[axis] * (bounds[0][0] - data.T[0]) + data.T[1] 
    109   zlo = -slope[axis] * (bounds[0][1] - data.T[0]) + data.T[1] 
     108  sl = slope[axis] 
     109  ylo = sl * (bounds[0][0] - data.T[0]) + data.T[1] 
     110  yhi = sl * (bounds[0][1] - data.T[0]) + data.T[1] 
     111  zhi = -sl * (bounds[0][0] - data.T[0]) + data.T[1] 
     112  zlo = -sl * (bounds[0][1] - data.T[0]) + data.T[1] 
    110113  xlb = bounds[0][0] 
    111114  xub = bounds[0][1] 
     
    203206  return ax 
    204207 
    205 def get_slope(data, replace=None): 
     208def get_slope(data, replace=None, mask=None): 
    206209  """ replace one slope in a list of slopes with '1.0' 
    207210  (i.e. replace a slope from the dataset with the unit slope) 
     
    211214  """ 
    212215  slope = data.lipschitz 
     216  if mask in range(len(slope)): 
     217    slope = swap(slope, mask) 
    213218  if replace not in range(len(slope)):  # don't replace an axis 
    214219    return slope 
    215220  return slope[:replace] + [1.0] + slope[replace+1:] 
    216221 
    217 def get_coords(data, replace=None): 
     222def get_coords(data, replace=None, mask=None): 
    218223  """ replace one coordiate axis in a 3-D data set with 'data values' 
    219224  (i.e. replace an 'x' axis with the 'y' values of the data) 
     
    225230  coords = data.coords 
    226231  values = data.values 
     232  if mask in range(len(slope)): 
     233    coords = [swap(pt,mask) for pt in coords] 
    227234  if replace not in range(len(slope)):  # don't replace an axis 
    228235    return coords 
     
    371378    scale = 1.0 # color = color**scale 
    372379 
    373   try: # select which axis to plot 'values' on 
     380  _2D = False # if False, use 3D plots; if True, use 3D plots 
     381  cs = None 
     382  try: # select which axis to plot 'values' on  (3D plot) 
    374383    xs = int(parsed_opts.replace) 
    375384  except: 
    376     xs = None # don't plot values; plot values on 'x' axis with xs = 0 
     385    try: # select which axes to mask (2D plot) 
     386      xs = eval(parsed_opts.replace)  # format is "(1,2)" 
     387      xs = list(reversed(sorted(set(xs)))) 
     388      cs = int(xs[-1]) if xs[-1] != xs[0] else None 
     389      xs = int(xs[0]) 
     390      xs,cs = cs,xs # cs will swap coord axes; xs will swap with value axis 
     391      _2D = True #NOTE: always apply cs swap before xs swap 
     392    except: 
     393      xs = None # don't plot values; plot values on 'x' axis with xs = 0 
    377394 
    378395  try: # always plot cones on vertical axis 
     
    380397  except: 
    381398    vertical_cones = False 
     399  if _2D: # always plot cones on vertical axis 
     400    vertical_cones = True 
    382401 
    383402  # ensure all terms of bounds are tuples 
     
    407426  # get dataset coords (and values) for selected axes 
    408427  if data: 
    409     slope = get_slope(data, xs) 
    410     coords = get_coords(data, xs) 
     428    slope = get_slope(data, xs, cs) 
     429    coords = get_coords(data, xs, cs) 
    411430    #print "bounds: %s" % bounds 
    412431    #print "slope: %s" % slope 
     
    433452    if bounds[i][1] is None: bounds[i][1] = 1 
    434453 
    435   # swap the axes appropriately when plotting cones 
    436   if vertical_cones and xs in range(len(bounds)): # we are replacing an axis 
     454  # swap the axes appropriately when plotting cones (when replacing an axis) 
     455  if _2D and xs == 0: 
     456    if data: 
     457      slope[0],slope[1] = slope[1],slope[0] 
     458      coords = [list(reversed(pt[:2]))+pt[2:] for pt in coords] 
     459   #bounds[0],bounds[1] = bounds[1],bounds[0] 
     460   #label[0],label[1] = label[1],label[0] 
     461    axis = xs #None 
     462  elif not _2D and vertical_cones and xs in range(len(bounds)): 
    437463    # adjust slope, bounds, and data so cone axis is last  
    438464    if data: 
     
    529555      t = str((s/qp)**scale) 
    530556      # get and plot dataset coords for selected axes       
    531       _coords = get_coords(d, xs) 
    532       if vertical_cones and xs in range(len(bounds)): # we are replacing an axis 
     557      _coords = get_coords(d, xs, cs) 
     558      # check if we are replacing an axis 
     559      if _2D and xs == 0: 
     560        if data: # adjust data so cone axis is last  
     561          _coords = [list(reversed(pt[:2]))+pt[2:] for pt in _coords] 
     562      elif not _2D and vertical_cones and xs in range(len(bounds)): 
    533563        if data: # adjust data so cone axis is last  
    534564          _coords = [swap(pt,xs) for pt in _coords] 
Note: See TracChangeset for help on using the changeset viewer.