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

#!/usr/bin/env python 

""" 

@file ion/core/object/cdm_methods/dataset.py 

@brief Wrapper methods for the cdm dataset object 

@author David Stuebe 

@author Tim LaRocque 

TODO: 

""" 

 

# Get the object decorator used on wrapper methods! 

from ion.core.object.object_utils import _gpb_source 

 

from ion.core.object.object_utils import OOIObjectError, CDM_GROUP_TYPE 

import ion.util.ionlog 

log = ion.util.ionlog.getLogger(__name__) 

 

 

#-------------------------------------# 

# Wrapper_Dataset Specialized Methods # 

#-------------------------------------# 

 

@_gpb_source 

def _make_root_group(self, name=''): 

    """ 

    Specialized method for CDM (dataset) Objects to append a group object with the given name 

    """ 

    if not isinstance(name, (str, unicode)): 

        raise TypeError('Type mismatch for argument "name" -- Expected %s; received %s with value: "%s"' % (repr(str), type(name), str(name))) 

    if self.root_group is not None: 

        raise OOIObjectError('Cannot make the root group when one already exists!') 

 

    group = self.Repository.create_object(CDM_GROUP_TYPE) 

    group.name = name 

    self.root_group = group 

 

 

@_gpb_source 

def _get_variable_names(self): 

    """ 

    """ 

    def _recurse_get_variable_names(group): 

        result = "" 

        group_name = '"%s"' % str(group.name) 

        for var in group.variables: 

            var_name = '"%s"' % str(var.name) 

            result += 'Group: %-20s Variable: %s\n' % (group_name, var_name) 

        for inner_group in group.groups: 

            result += _recurse_get_variable_names(inner_group) 

        return result 

 

    return _recurse_get_variable_names(self.root_group) 

 

@_gpb_source 

def _get_group_attributes_for_display(self, group=None): 

    """ 

    """ 

    if group is None: 

        group = self.root_group 

 

    result = "" 

    for atrib in group.attributes: 

        name = str(atrib.name) 

        vals = str(group.FindAttributeByName(name).GetValues()) 

        idx = int(group.FindAttributeIndexByName(name)) 

        result += "(%02i) %-35s%s\n" % (idx, name, vals) 

 

    return result 

 

@_gpb_source 

def _get_variable_attributes_for_display(self): 

    """ 

    """ 

    def _recurse_get_variable_atts(group, group_namespace=None): 

        result = "" 

        group_name = group_namespace or "" 

        group_name += group.name 

        for var in group.variables: 

            result += "\n\n%s.%s" % (str(group_name), str(var.name)) 

            for atrib in var.attributes: 

                name = str(atrib.name) 

                vals = str(var.FindAttributeByName(name).GetValues()) 

                idx = var.FindAttributeIndexByName(name) 

                result += "\n(%03i) %-30s\t\t%s" % (idx, name, vals) 

 

        for inner_group in group.groups: 

            result += _recurse_get_variable_atts(inner_group, group_name + '.') 

 

        return result 

 

    return _recurse_get_variable_atts(self.root_group)