Ignore:
Timestamp:
Nov 6, 2011, 9:28:12 PM (13 years ago)
Author:
aslmd
Message:

PYTHON: improvements on handling 1D 2D slices for gcm and meso. a few minor corrections added for the scripts to work better. it might be possible at some point to merge meso.py and gcm.py, wait and see.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MESOSCALE/LMD_MM_MARS/SRC/PYTHON/myplot.py

    r349 r350  
    6868    output = input
    6969    error = False
    70     ### this is needed to cope the case where d4,d3,d2,d1 are single integers and not arrays
     70    #### this is needed to cope the case where d4,d3,d2,d1 are single integers and not arrays
    7171    if d4 is not None and not isinstance(d4, np.ndarray): d4=[d4]
    7272    if d3 is not None and not isinstance(d3, np.ndarray): d3=[d3]
     
    7777        if   d2 >= shape[0]: error = True
    7878        elif d1 >= shape[1]: error = True
    79         elif d1 is not None and d2 is not None:  output = input[d2,d1]
    80         elif d1 is not None:         output = input[:,d1]
    81         elif d2 is not None:         output = input[d2,:]
     79        elif d1 is not None and d2 is not None:  output = mean(input[d2,:],axis=0); output = mean(output[d1],axis=0)
     80        elif d1 is not None:         output = mean(input[:,d1],axis=1)
     81        elif d2 is not None:         output = mean(input[d2,:],axis=0)
    8282    elif dimension == 3:
    8383        if   max(d4) >= shape[0]: error = True
    8484        elif max(d2) >= shape[1]: error = True
    8585        elif max(d1) >= shape[2]: error = True
    86         elif d4 is not None and d2 is not None and d1 is not None:  output = input[d4,d2,d1]
     86        elif d4 is not None and d2 is not None and d1 is not None: 
     87            output = mean(input[d4,:,:],axis=0); output = mean(output[d2,:],axis=0); output = mean(output[d1],axis=0)
    8788        elif d4 is not None and d2 is not None:    output = mean(input[d4,:,:],axis=0); output=mean(output[d2,:],axis=0)
    8889        elif d4 is not None and d1 is not None:    output = mean(input[d4,:,:],axis=0); output=mean(output[:,d1],axis=1)
     
    9697        elif max(d2) >= shape[2]: error = True
    9798        elif max(d1) >= shape[3]: error = True
    98         elif d4 is not None and d3 is not None and d2 is not None and d1 is not None:  output = input[d4,d3,d2,d1]
    99         elif d4 is not None and d3 is not None and d2 is not None:         output = input[d4,d3,d2,:]
    100         elif d4 is not None and d3 is not None and d1 is not None:         output = input[d4,d3,:,d1]
    101         elif d4 is not None and d2 is not None and d1 is not None:         output = input[d4,:,d2,d1]
    102         elif d3 is not None and d2 is not None and d1 is not None:         output = input[:,d3,d2,d1]
     99        elif d4 is not None and d3 is not None and d2 is not None and d1 is not None: 
     100            output = mean(input[d4,:,:,:],axis=0); output = mean(output[d3,:,:],axis=0); output = mean(output[d2,:],axis=0); output = mean(output[d1],axis=0)
     101        elif d4 is not None and d3 is not None and d2 is not None:
     102            output = mean(input[d4,:,:,:],axis=0); output = mean(output[d3,:,:],axis=0); output = mean(output[d2,:],axis=0)
     103        elif d4 is not None and d3 is not None and d1 is not None:
     104            output = mean(input[d4,:,:,:],axis=0); output = mean(output[d3,:,:],axis=0); output = mean(output[:,d1],axis=1)
     105        elif d4 is not None and d2 is not None and d1 is not None:
     106            output = mean(input[d4,:,:,:],axis=0); output = mean(output[:,d2,:],axis=1); output = mean(output[:,d1],axis=1)
     107        elif d3 is not None and d2 is not None and d1 is not None:
     108            output = mean(input[:,d3,:,:],axis=1); output = mean(output[:,d2,:],axis=1); output = mean(output[:,d1],axis=1)
    103109        elif d4 is not None and d3 is not None:  output = mean(input[d4,:,:,:],axis=0); output = mean(output[d3,:,:],axis=0)
    104110        elif d4 is not None and d2 is not None:  output = mean(input[d4,:,:,:],axis=0); output = mean(output[:,d2,:],axis=1)
     
    107113        elif d3 is not None and d1 is not None:  output = mean(input[:,d3,:,:],axis=1); output = mean(output[:,:,d1],axis=0)
    108114        elif d2 is not None and d1 is not None:  output = mean(input[:,:,d2,:],axis=2); output = mean(output[:,:,d1],axis=2)
    109         elif d1 is not None:                       output = input[:,:,:,d1]
    110         elif d2 is not None:                       output = input[:,:,d2,:]
    111         elif d3 is not None:                       output = input[:,d3,:,:]
    112         elif d4 is not None:                       output = input[d4,:,:,:]
     115        elif d1 is not None:                     output = mean(input[:,:,:,d1],axis=3)
     116        elif d2 is not None:                     output = mean(input[:,:,d2,:],axis=2)
     117        elif d3 is not None:                     output = mean(input[:,d3,:,:],axis=1)
     118        elif d4 is not None:                     output = mean(input[d4,:,:,:],axis=0)
    113119    dimension = np.array(output).ndim
    114120    shape = np.array(output).shape
     
    801807   shape = what_I_plot.shape
    802808   if indextime is None:
     809      print "axis is time"
    803810      x = time
    804811      count = count+1
    805812   if indexlon is None:
     813      print "axis is lon"
    806814      if count == 0: x = lon
    807815      else: y = lon
    808816      count = count+1
    809817   if indexlat is None:
     818      print "axis is lat"
    810819      if count == 0: x = lat
    811820      else: y = lat
    812821      count = count+1
    813822   if indexvert is None and dim0 is 4:
     823      print "axis is vert"
    814824      if vertmode == 0: # vertical axis is as is (GCM grid)
    815825         if count == 0: x=range(len(vert))
     
    822832   x = array(x)
    823833   y = array(y)
     834   print "what_I_plot.shape", what_I_plot.shape
     835   print "x.shape, y.shape", x.shape, y.shape
    824836   if len(shape) == 1:
    825       if shape != len(x):
     837      print shape[0]
     838      if shape[0] != len(x):
    826839         print "WARNING HERE !!!"
    827840         x = y
Note: See TracChangeset for help on using the changeset viewer.