width = np.random.uniform(0.1, 2) pnum = 10 amplitude = np.random.uniform(level * 2 / 3, level) signal = stg.generate(ts, fs, stg.constant_path(f_start=fs[start_index], drift_rate=drift_rate), stg.periodic_gaussian_t_profile( period, phase, sigma, pulse_dir, width, pnum, amplitude, level), stg.gaussian_f_profile(width=line_width), stg.constant_bp_profile(level=1.0), integrate=True) signal = stg.normalize(stg.inject_noise(signal), cols=128, exclude=0.2, use_median=False) plt.imsave(output_fn, signal) print('Saved %s of %s scintillated data for %s' % (i + 1, num, name)) for i in range(num): output_fn = '/datax/scratch/bbrzycki/data/%s/%s/%s/%s_%04d.png' % ( dir, name, 'constant', 'constant', i) start_index = np.random.randint(0, fchans) drift_rate = np.random.uniform(-start_index * df / (tsamp * tchans), (fchans - 1 - start_index) * df /
except OSError as e: if e.errno != errno.EEXIST: raise # Make csv to save data csv_fn = '%s/%s' % (prefix, 'labels.csv') # Generate training and validation data! datasets = [('train', 5000), ('validation', 500)] with open(csv_fn, 'w') as f: writer = csv.writer(f) for label in labels: for process, num in datasets: for i in range(num): output_prefix = '%s/%s/%s/%s_%04d' % (prefix, process, label, label, i,) ############################################################################## # Generate signals -- these parameters should be tuned to whatever makes sense signal, [start_index, drift_rate, line_width, level, spread] = generate_training0_signal(label=label) # Normalize and write data normalized_signal = stg.normalize(stg.inject_noise(signal), cols = 128, exclude = 0.2, use_median=False) plt.imsave(output_prefix + '.png', normalized_signal) np.save(output_prefix + '.npy', normalized_signal) writer.writerow([output_prefix, start_index, drift_rate, line_width, level, spread]) print([output_prefix, start_index, drift_rate, line_width, level, spread]) print('Saved %s of %s signal data for %s, %s' % (i + 1, num, label, process))