def generate_signal(sig_type='constant', line_width=0.02**3, level=10, bias_no_drift=0, **kwargs): # bias no drift is fraction of the time drift rate should be set to 0 start_index = np.random.randint(0, fchans) if np.random.uniform(0, 1) < bias_no_drift: drift_rate = 0 else: drift_rate = np.random.uniform(-start_index*df/(tsamp*tchans), (fchans-1-start_index)*df/(tsamp*tchans)) # Placeholder for non rfi types, which would have spread = 0 anyway spread = 0 if sig_type == 'noise': signal = stg.generate(ts, fs, stg.constant_path(f_start = fs[start_index], drift_rate = drift_rate), stg.constant_t_profile(level = 0), stg.gaussian_f_profile(width = line_width), stg.constant_bp_profile(level = 1.0), integrate = False) elif sig_type == 'constant': signal = stg.generate(ts, fs, stg.constant_path(f_start = fs[start_index], drift_rate = drift_rate), stg.constant_t_profile(level = level), stg.gaussian_f_profile(width = line_width), stg.constant_bp_profile(level = 1.0), integrate = True) elif sig_type == 'simple_rfi': spread = kwargs['spread'] # np.random.uniform(0.0002, 0.0003) signal = stg.generate(ts, fs, stg.choppy_rfi_path(f_start = fs[start_index], drift_rate = drift_rate, spread=spread, spread_type='gaussian'), stg.constant_t_profile(level = level), stg.gaussian_f_profile(width = line_width), stg.constant_bp_profile(level = 1.0), integrate = True) elif sig_type == 'scintillated': period = kwargs['period'] # np.random.uniform(1,5) phase = kwargs['phase'] # np.random.uniform(0, period) sigma = kwargs['sigma'] # np.random.uniform(0.1, 2) pulse_dir = kwargs['pulse_dir'] #'rand' width = kwargs['width'] # np.random.uniform(0.1, 2) pnum = kwargs['pnum'] # 10 amplitude = kwargs['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) return signal, [start_index, drift_rate, line_width, level, spread]
def generate_frame(sig_num=True, sig_db=10, rfi_num=0, rfi_db=25, means_dist=None, stds_dist=None, mins_dist=None, **kwargs): noise_mean, noise_std, noise_min = make_normal(means_dist, stds_dist, mins_dist, 1) noise_frame = np.maximum( np.random.normal(noise_mean, noise_std, [tchans, fchans]), noise_min) frame = noise_frame rfi_indices = [] rfi_widths = [] for i in range(rfi_num): rfi_snr = np.power(10, rfi_db / 10) rfi_level = noise_std * rfi_snr / np.sqrt(tchans) rfi_start_index = np.random.randint(0, fchans) rfi_indices.append(rfi_start_index) rfi_line_width = np.random.uniform(1e-6, 30e-6) rfi_widths.append(rfi_line_width) rfi_signal = stg.generate( ts, fs, stg.constant_path(f_start=fs[rfi_start_index], drift_rate=0), stg.constant_t_profile(level=rfi_level), stg.gaussian_f_profile(width=rfi_line_width), stg.constant_bp_profile(level=1.0)) frame += rfi_signal if sig_num == 1: snr = np.power(10, sig_db / 10) level = noise_std * snr / np.sqrt(tchans) start_index = np.random.randint(0, fchans) drift_rate = np.random.uniform(-start_index * df / (tsamp * tchans), (fchans - 1 - start_index) * df / (tsamp * tchans)) line_width = np.random.uniform(1e-6, 30e-6) signal = stg.generate( ts, fs, stg.constant_path(f_start=fs[start_index], drift_rate=drift_rate), stg.constant_t_profile(level=level), stg.gaussian_f_profile(width=line_width), stg.constant_bp_profile(level=1.0)) frame += signal else: level = 0 start_index = -1 drift_rate = 0 line_width = 0 return frame, [ sig_num, sig_db, start_index, drift_rate, line_width, rfi_num, rfi_db, rfi_indices, rfi_widths ]
#drift_rate = 0 level = np.random.uniform(1, 5) level = 5 period = np.random.uniform(1, 5) phase = np.random.uniform(0, period) sigma = np.random.uniform(0.1, 2) pulse_dir = 'rand' 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):
#drift_rate = 0 level = np.random.uniform(1,5) level = SNR period = np.random.uniform(2,4) phase = np.random.uniform(0,period) sigma = np.random.uniform(0.1, 2) pulse_dir = 'rand' width = np.random.uniform(np.random.uniform(0.1,2)) pnum = 10 amplitude = np.random.uniform(min(1, level/2.), level) # amplitude = np.random.uniform(min(1, level/2.), level/2) 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/%s_%04d.png' % (dir,SNR,name,'not_present','not_present',i) start_index = np.random.randint(0,fchans) drift_rate = np.random.uniform(-start_index*df/(tsamp*tchans),
def generate_frame(sig_num=0, sig_db=10, rfi_num=0, rfi_db=25, means_dist=None, stds_dist=None, mins_dist=None, **kwargs): noise_mean, noise_std, noise_min = make_normal(means_dist, stds_dist, mins_dist, 1) noise_frame = np.maximum( np.random.normal(noise_mean, noise_std, [tchans, fchans]), noise_min) frame = noise_frame frame_info = { 'noise_mean': noise_mean, 'noise_std': noise_std, 'noise_min': noise_min, 'signals': [], } rfi_indices = [] rfi_widths = [] for i in range(rfi_num): rfi_snr = np.power(10, rfi_db / 10) rfi_level = noise_std * rfi_snr / np.sqrt(tchans) rfi_start_index = np.random.randint(0, fchans) rfi_end_index = rfi_start_index rfi_drift_rate = 0 rfi_indices.append(rfi_start_index) rfi_line_width = np.random.uniform(1e-6, 30e-6) rfi_widths.append(rfi_line_width) rfi_signal = stg.generate( ts, fs, stg.constant_path(f_start=fs[rfi_start_index], drift_rate=rfi_drift_rate), stg.constant_t_profile(level=rfi_level), stg.gaussian_f_profile(width=rfi_line_width), stg.constant_bp_profile(level=1.0)) sig_info = { 'class': 'rfi', 'start_index': rfi_start_index, 'end_index': rfi_end_index, 'line_width': rfi_line_width, 'snr': rfi_snr, } sig_info = np.array( [rfi_start_index, rfi_end_index, rfi_line_width, rfi_snr, 1]) frame += rfi_signal frame_info['signals'].append(sig_info) for i in range(sig_num): snr = np.power(10, sig_db / 10) level = noise_std * snr / np.sqrt(tchans) start_index = np.random.randint(0, fchans) end_index = np.random.randint(0, fchans) drift_rate = (end_index - start_index) * df / (tsamp * tchans) # drift_rate = np.random.uniform(-start_index*df/(tsamp*tchans), # (fchans-1-start_index)*df/(tsamp*tchans)) line_width = np.random.uniform(1e-6, 30e-6) signal = stg.generate( ts, fs, stg.constant_path(f_start=fs[start_index], drift_rate=drift_rate), stg.constant_t_profile(level=level), stg.gaussian_f_profile(width=line_width), stg.constant_bp_profile(level=1.0)) sig_info = { 'class': 'constant', 'start_index': start_index, 'end_index': end_index, 'line_width': line_width, 'snr': snr, } sig_info = np.array([start_index, end_index, line_width, snr, 0]) frame += signal frame_info['signals'].append(sig_info) else: level = 0 start_index = -1 drift_rate = 0 line_width = 0 return frame, frame_info
total_image_num = 50000 with open(csv_fn, 'w') as f: writer = csv.writer(f) for i in range(0, 50000): output_fn = dir_name + '%06d.npy' % i start_index = np.random.randint(0, fchans) drift_rate = np.random.uniform(-start_index * df / (tsamp * tchans), (fchans - 1 - start_index) * df / (tsamp * tchans)) line_width = np.random.uniform(0.04, 0.05)**3 level = 10 signal = stg.generate(ts, fs, stg.constant_path(f_start=fs[start_index], drift_rate=drift_rate), stg.constant_t_profile(level=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) np.save(output_fn, signal) writer.writerow([output_fn, start_index, drift_rate, line_width]) print('%06d saved' % i)
def generate_frame(sig_num=0, max_sig_num=10, rfi_frac=0.5, sig_snr_range=(25, 250), width_range=(5, 10), means_dist=None, stds_dist=None, mins_dist=None, **kwargs): noise_mean, noise_std, noise_min = make_normal(means_dist, stds_dist, mins_dist, 1) noise_frame = np.maximum( np.random.normal(noise_mean, noise_std, [tchans, fchans]), noise_min) frame = noise_frame frame_info = { 'noise': [noise_mean[0], noise_std[0], noise_min[0]], 'signals': [], 'frame_params': [ sig_num, rfi_frac, sig_snr_range[0], sig_snr_range[1], width_range[0], width_range[1] ], } for i in range(sig_num): snr = np.random.uniform(sig_snr_range[0], sig_snr_range[1]) level = noise_std * snr / np.sqrt(tchans) start_index = np.random.randint(0, fchans) if np.random.rand() > rfi_frac: end_index = np.random.randint(0, fchans) else: end_index = start_index drift_rate = (end_index - start_index) / tchans * (df / tsamp) line_width = np.random.uniform(width_range[0], width_range[1]) * np.abs(df) signal = stg.generate( ts, fs, stg.constant_path(f_start=fs[start_index], drift_rate=drift_rate), stg.constant_t_profile(level=level), stg.gaussian_f_profile(width=line_width), stg.constant_bp_profile(level=1.0)) # sig_info = { # 'class': 'constant', # 'start_index': start_index, # 'end_index': end_index, # 'line_width': line_width, # 'snr': snr, # } sig_info = np.array([ start_index / fchans, end_index / fchans, (end_index - start_index) / tchans, line_width / np.abs(df), snr ]) frame += signal frame_info['signals'].append(sig_info) for i in range(max_sig_num - sig_num): frame_info['signals'].append([-1, -1, 0, 0, -1]) return frame, frame_info
-start_index * df / (tsamp * tchans), (fchans - 1 - start_index) * df / (tsamp * tchans)) #drift_rate = 0 level = np.random.uniform(2, 5) width = np.random.uniform(0.02, 0.05)**3 amplitude = np.random.uniform(level / 4, level) # amplitude = level period = np.random.uniform(50, 100) # width = np.random.uniform(0.000009, 0.000225) signal = stg.generate( ts, fs, stg.constant_path(f_start=fs[start_index], drift_rate=drift_rate), stg.sine_t_profile(period=period, phase=0, amplitude=amplitude, level=level), stg.gaussian_f_profile(width=width), stg.constant_bp_profile(level=1.0)) if set == 'raw': signal = stg.inject_noise(signal) elif set == 'normalized': signal = stg.normalize(stg.inject_noise(signal), cols=0, exclude=0.0, use_median=False) elif set == 'normalized_excluded': signal = stg.normalize(stg.inject_noise(signal), cols=1,