Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. # Example - Generating the Dataframe and Panel objects - pulled from pyger_cases.py
  2. #
  3. # The code below was pieced together from snippets in pyger_cases.py and was not fully tested.
  4. # Testing is not entirely possible since some of it is fictitious to simplify the example.
  5. #
  6. # The dictionary values, pitch_set, hot_max, hot90, and cool90 are one dimensional numpy arrays
  7. # representing heating and cooling data for one case (i.e. set of conditions). Each case is designed
  8. # to limit the dwell time for one msid. For example, a set of cases would be used to represent the
  9. # dwell capability for each msid at their current planning limit along with a common number of ACIS
  10. # CCDs (where applicable).
  11. #
  12. colnames = ['pitch', 'hot_max', 'hot90', 'cool90']
  13. for case in cases:
  14. # Imaginary function to simplify this example
  15. pitch, hot_max, hot90, cool90 = fetch_simulation_data(case)
  16.  
  17. frame = table.Table([pitch, hot_max, hot90, cool90], names=colnames)
  18.  
  19. # Note that each key is the msid and the value is the dataframe
  20. panel_dict[case['msid']] = frame
  21.  
  22. cols2d = []
  23. msids = np.array([case['msid'] for case in cases])
  24. for colname in colnames:
  25. # This is what astropy table can do that Pandas cannot: support for arbitrary
  26. # dimensions in the column. Make a 2-d column with the axis=1 dimension being case.
  27. col2d = np.vstack([panel_dict[msid][colname] for msid in msids])
  28. cols2d.append(col2d.transpose())
  29. constraint_panel = table.Table(cols2d, names=colnames)
  30.  
  31. allowable_hot_time = np.min(constraint_panel['max_hot_time'], axis=1)
  32. allowable_max_hot_time_idx = np.argmin(constraint_panel['max_hot_time'], axis=1)
  33. allowable_max_hot_time_msid = msids[allowable_max_hot_time_idx]
  34.  
  35. panel_dict= {}
  36. for case in cases:
  37.  
  38. # Imaginary function to simplify this example
  39. pitch_set, hot_max, hot90, cool90 = fetch_simulation_data(case)
  40.  
  41. frame = pandas.DataFrame({'max_hot_time':hot_max, 'hot_dwell':hot90, 'cool_dwell':cool90},
  42. index=pitch_set)
  43.  
  44. # Note that each key is the msid and the value is the dataframe
  45. panel_dict[case['msid']] = frame
  46.  
  47. # 3 dimensional dataset
  48. constraint_panel = pandas.Panel(panel_dict)
  49.  
  50. # Determine the minimum values in the "max_hot_time" column for each pitch (2D table index) through
  51. # all cases (indexed by msid). To put it a different way, I want to know the minimum allowed time
  52. # (as listed in the "max_hot_time" column) at each pitch, given a set of cases where each case
  53. # represents the capability when limiting one msid.
  54. #
  55. allowable_hot_time = constraint_panel.minor_xs('max_hot_time').min(axis=1)
  56.  
  57. # Similar operation, only instead of storing the minimum value, I want the name of the case (msid)
  58. # that has the minimum value at each pitch.
  59. allowable_max_hot_time_msid = constraint_panel.minor_xs('max_hot_time').idxmin(axis=1)
  60.  
  61. # The last two lines of code use a method called "minor_xs" which grabs the slice of data for one
  62. # column into the third dimension (over all msids/cases). I then grab the minimum values along the
  63. # second axis (axis=1) using the "min" method. In this "sliced" table, axis=1 corresponds to the
  64. # different cases.
  65.  
  66. # This data can be combined into one datastructure to make it easier to pass around.
  67. max_hot_time = pd.DataFrame({'max_time': allowable_hot_time,
  68. 'limiting_msid': allowable_max_hot_time_msid})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement