Changeset 4195

Show
Ignore:
Timestamp:
06/18/07 16:24:56 (8 years ago)
Author:
DrewCormier
Message:

standardizing method API's so that the user does not have to change code in AWG.py for basic use

Location:
experimental/AWG/trunk/AWG
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • experimental/AWG/trunk/AWG/AWG.py

    r4194 r4195  
    1919        self.parent = parent 
    2020 
    21     def get_signal(self, signal_type, file_name): 
     21    def get_signal(self, signal_index, file_name): 
    2222        #signal I want is hard-coded for now 
    23         self.signal_type = signal_type 
     23        self.signal_index = signal_index 
    2424        self.signal_len = 8192   #length of packet 
    2525        self.frequency = 5   #cycles per packet 
    26         rand_type = 'random' 
     26        self.rand_type = 'random' 
    2727        self.file_name = file_name 
    28         delimiter = ',' 
     28        self.delimiter = ',' 
    2929 
    3030        my_signal = sources.sources(self)    #instance of signals class 
    31  
    32         self.signal_type = self.signal_type.lower()  #makes comparison case insesitive 
    33         if self.signal_type == 'sine': 
    34             self.the_signal = my_signal.gen_sine(self.frequency, self.signal_len) 
    35         elif self.signal_type == 'cosine': 
    36             self.the_signal = my_signal.gen_cosine(self.frequency, self.signal_len) 
    37         elif self.signal_type == 'random': 
    38             self.the_signal = my_signal.gen_random_data(self.signal_len, rand_type) 
    39         elif self.signal_type == 'file': 
    40             self.the_signal = my_signal.read_file(self.file_name, delimiter)  
    41         elif self.signal_type == 'zeros': 
    42             self.the_signal = my_signal.gen_zeros(self.signal_len) 
    43         else: 
    44             print "signals other than sine,cosine, rand, zeros, and readfile are not supported yet in _get_signal" 
     31        self.the_signal = my_signal.gen_signal() 
    4532 
    4633        return self.the_signal               
     
    196183        self.q_file_name = self.qFileNameEditor.GetLineText(0) 
    197184        AWG_instance = AWG(self) 
    198         i_source_selected = self.iSourceChoice.GetStringSelection() 
    199         q_source_selected = self.qSourceChoice.GetStringSelection() 
     185        i_source_selected = self.iSourceChoice.GetSelection() 
     186        q_source_selected = self.qSourceChoice.GetSelection() 
    200187        self.I = AWG_instance.get_signal(i_source_selected, self.i_file_name) 
    201188        self.Q = AWG_instance.get_signal(q_source_selected, self.q_file_name) 
  • experimental/AWG/trunk/AWG/sources.py

    r4194 r4195  
    88        self.parent = parent 
    99        self.available_sources = ['file', 'sine', 'cosine', 'random', 'zeros'] 
     10        #IMPORTANT: corresponding_methods must be in the same order as the available_sources 
    1011        self.corresponding_methods = ['read_file','gen_sine', 'gen_cosine', 'gen_random_data', 'gen_zeros'] 
    1112 
     
    1617 
    1718    def gen_signal(self): 
    18         pass 
     19        eval_string = "self." + self.corresponding_methods[parent.signal_index] + "()" 
     20        return eval(eval_string)  #return the signal generated by the corresponding method 
    1921 
    20     def read_file(self, file_name, delimiter): 
    21  
     22    def read_file(self): 
     23         
    2224        try: 
    23             my_file = open(file_name, 'r') 
     25            my_file = open(self.parent.file_name, 'r') 
    2426        except IOError: 
    25             print "no file named " + file_name 
     27            print "no file named " + self.parent.file_name 
    2628            return []  #return an empty packet 
    2729 
     
    3335        data_from_file.strip(']')   #]'s will not be tollerated 
    3436 
    35         data_from_file = data_from_file.split(delimiter)  #break string into a list 
     37        data_from_file = data_from_file.split(self.parent.delimiter)  #break string into a list 
    3638 
    3739        return data_from_file 
    3840 
    3941 
    40     def gen_sine(self, freq, len): 
     42    def gen_sine(self): 
    4143        '''freq is frequency in cycles per packet.  len is the length of the packet.  type is the data type to return (e.g., "float", "short", "int")''' 
    4244 
    4345        count = 0 
    4446        sine = [] 
    45         while count < len: 
    46             sine.append(math.sin(freq*2*math.pi*count/len)) 
     47        while count < self.parent.len: 
     48            sine.append(math.sin(self.parent.freq*2*math.pi*count/self.parent.len)) 
    4749            count = count + 1 
    4850 
     
    5052 
    5153 
    52     def gen_cosine(self, freq, len): 
     54    def gen_cosine(self): 
    5355        '''freq is frequency in cycles per packet.  len is the length of the packet.  type is the data type to return (e.g., "float", "short", "int")''' 
    5456 
    5557        count = 0 
    5658        cosine = [] 
    57         while count < len: 
    58             cosine.append(math.cos(freq*2*math.pi*count/len)) 
     59        while count < self.parent.len: 
     60            cosine.append(math.cos(self.parent.freq*2*math.pi*count/self.parent.len)) 
    5961            count = count + 1 
    6062 
     
    6365 
    6466 
    65     def gen_random_data(self, len, rand_type): 
     67    def gen_random_data(self): 
    6668        '''the rand_type variable defines which function call to use in the random module''' 
    6769 
    6870        data = [] 
    69         rand_type = rand_type.lower()  #makes comparison case insensitive 
    70         if rand_type == 'random': 
     71        tmp_rand_type = self.parent.rand_type.lower()  #makes comparison case insensitive 
     72        if tmp_rand_type == 'random': 
    7173            count = 0 
    72             while count < len: 
     74            while count < self.parent.len: 
    7375                data.append(random.random()) 
    7476                count = count + 1 
    75         elif rand_type == 'uniform': 
     77        elif tmp_rand_type == 'uniform': 
    7678            count = 0 
    77             while count < len: 
     79            while count < self.parent.len: 
    7880                data.append(random.uniform()) 
    7981                count = count + 1 
     
    8385        return data 
    8486                 
    85     def gen_zeros(self, len): 
     87    def gen_zeros(self): 
    8688        '''returns a list of zeros''' 
    8789        data = [] 
    88         for n in range(len): 
     90        for n in range(self.parent.len): 
    8991            data.append(0) 
    9092        return data