Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

import numpy as np 

from m_pool.axis_obj import Axis 

 

def axis_obj_dammit( axOrD ): 

'''No Matter What, return an Axis obj''' 

if type( axOrD ) == dict: 

return Axis( axOrD ) # make an axis from a dictionary 

 

if type( axOrD ) == Axis: 

return axOrD # it's already an Axis 

 

return Axis() # a default Axis 

 

 

class AxisPool(object): 

'''An AxisPool object is a Collection of Axis objects.  

It is used to define a collection of Matrix objects 

 

*** Structured to easily pickle via a dictionary of named values for properties. *** 

''' 

 

def __init__(self, D={'axesDefL':None} ): 

'''Initialize with a dictionary so that pickle files can easily save and read objects''' 

 

axesDefL = D.get('axesDefL', None) 

 

if axesDefL: 

self.axisL = [axis_obj_dammit(axOrD) for axOrD in axesDefL] 

else: 

self.axisL = [] 

 

# uses self.axisD to get an Axis object by name 

self.make_supt_objects() 

 

def add_axis(self, axOrD): 

self.axisL.append( axis_obj_dammit(axOrD) ) 

 

self.make_supt_objects() 

 

def make_supt_objects(self): 

# use axisD to get an Axis object by name 

self.axisD = {} 

for A in self.axisL: 

self.axisD[A.name] = A 

 

def connectMatrixToAxes(self, matrixObj, axisNameL): 

'''Be sure that axisNameL is the correct order for the axes''' 

for i,name in enumerate(axisNameL): 

self.axisD[name].connectMatrix( i, matrixObj ) 

 

def add_value_to_Axis(self, axisName, val): 

A = self.axisD[ axisName ] 

i = A.add_value( val ) 

return i 

 

def __str__(self): 

sL = ['AxisPool'] 

for A in self.axisL: 

sL.append( str(A) ) 

return '\n'.join( sL ) 

 

def __len__(self): 

return len( self.axisL ) 

 

def __iter__(self): 

for value in self.axisL: 

yield value 

 

def __getitem__(self, axisName): 

return self.axisD.get( axisName, None) 

 

if __name__=="__main__": 

 

epsAxis = Axis({'name':'eps', 'valueL':[10., 20., 30., 40., 50.], 

'units':'', 'transform':'log10'}) 

 

# Just a dict, not an Axis obj 

pcAxis = {'name':'pc', 'valueL':[100.,200.,300,400], 'units':'psia', 'transform':'log10'} 

 

mrAxis = Axis({'name':'mr', 'valueL':[1,2,3], 

'units':'', 'transform':''}) 

 

axesDefL = [epsAxis, pcAxis] 

 

AP = AxisPool( {'axesDefL':axesDefL} ) 

 

print(AP) 

#print AP.axisD 

print('_'*20,'Add another axis called "mr"','_'*20) 

AP.add_axis( mrAxis ) 

print(AP) 

print('_'*20,'Add value 2.5 to axis "mr"','_'*20) 

i =AP.add_value_to_Axis( 'mr', 2.5 ) 

print('Added 2.5 at position',i,'in "mr"') 

print(AP)