Skip to content

Commit

Permalink
added for loop to slow writing
Browse files Browse the repository at this point in the history
  • Loading branch information
jmakous committed Aug 6, 2020
1 parent 9f4a428 commit bbf8b66
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions python/csv_filesink.py
Expand Up @@ -52,40 +52,44 @@ def __init__(self, vec_length, samp_rate, freq, prefix, save_toggle, integration
self.spectrum = np.zeros(vec_length)

def work(self, input_items, output_items):
in0 = input_items[0]
self.spectrum[:] = in0
# in0 = input_items[0]
# self.spectrum[:] = in0

in0_buffer = input_items[0]

for in0 in in0_buffer:

# <+signal processing here+>

if self.save_toggle == "True": #If true, capture the spectrum to a new .csv text file each integration.
if self.integration_select == 0:
current_time = time.time()
self.timenow = datetime.now().strftime("%Y-%m-%d_%H.%M.%S.%f")[:-5]
#write (freq, output) as a column array to a text file, titled e.g. "2018-07-24_15.15.49_spectrum.txt"
# The "prefix", i.e. the file path, is defined in the prefix variable box in the .grc program.
self.textfilename = self.prefix + self.timenow + "_" + self.location + "_" + self.az + "_" + self.elev + "_spectrum.csv"
self.data_array[:,0] = np.round(self.frequencies/1e6, decimals=4)
self.data_array[:,1] = np.round(self.spectrum, decimals=4)
np.savetxt(self.textfilename, self.data_array, delimiter=',')

self.N_long_counter = self.N_long_counter + 1 #Increase counter for long integration print to .csv

else:
if self.N_long_counter >= self.short_long_time_scale-1:
if self.save_toggle == "True": #If true, capture the spectrum to a new .csv text file each integration.
if self.integration_select == 0:
current_time = time.time()
self.timenow = datetime.now().strftime("%Y-%m-%d_%H.%M.%S.%f")[:-5]
#write (freq, output) as a column array to a text file, titled e.g. "2018-07-24_15.15.49_spectrum.txt"
# The "prefix", i.e. the file path, is defined in the prefix variable box in the .grc program.
self.textfilename = self.prefix + self.timenow + "_" + self.location + "_" + self.az + "_" + self.elev + "_spectrum.csv"
self.data_array[:,0] = np.round(self.frequencies/1e6, decimals=4)
self.data_array[:,1] = np.round(self.spectrum, decimals=4)
self.data_array[:,1] = np.round(in0, decimals=4)
np.savetxt(self.textfilename, self.data_array, delimiter=',')
#
self.N_long_counter = 0
else:

self.N_long_counter = self.N_long_counter + 1 #Increase counter for long integration print to .csv

else:
if self.N_long_counter >= self.short_long_time_scale-1:
current_time = time.time()
self.timenow = datetime.now().strftime("%Y-%m-%d_%H.%M.%S.%f")[:-5]
#write (freq, output) as a column array to a text file, titled e.g. "2018-07-24_15.15.49_spectrum.txt"
# The "prefix", i.e. the file path, is defined in the prefix variable box in the .grc program.
self.textfilename = self.prefix + self.timenow + "_" + self.location + "_" + self.az + "_" + self.elev + "_spectrum.csv"
self.data_array[:,0] = np.round(self.frequencies/1e6, decimals=4)
self.data_array[:,1] = np.round(in0, decimals=4)
np.savetxt(self.textfilename, self.data_array, delimiter=',')
#
self.N_long_counter = 0
else:
self.N_long_counter = self.N_long_counter + 1 #Increase counter for long integration print to .csv

return len(input_items[0])
return len(input_items[0])

def set_save_toggle(self, save_toggle):
self.save_toggle = save_toggle
Expand Down

0 comments on commit bbf8b66

Please sign in to comment.