def get_chord_single_offline(chord): quality = quality_filter(chord) remaining_extensions = remaining_extension_filter(chord, quality) quality_semitones = quality_to_semitones(quality) first_semitone_revision, remaining_extensions = suspension_scanner( remaining_extensions, quality_semitones) final_semitone_revision = extension_scanner(remaining_extensions, first_semitone_revision, quality) if final_semitone_revision is None: pass elif repeated_interval_filter(final_semitone_revision) is not True: final_semitone_strings, semitone_indices_to_replace = \ extension_replacement_scan( semitones_to_strings(final_semitone_revision), chord) final_semitone_revision = remove_element_by_index_scan( final_semitone_revision, semitone_indices_to_replace) return chord, final_semitone_revision, final_semitone_strings
def there_is_quality_overlap(chord): quality_order_search_index = len(quality_filter(chord)) for i in dictionaries.doubled_potential_quality_orders(): if i in chord[:quality_order_search_index] and i in chord[ quality_order_search_index:]: return True return False
def get_chord_web(chord): chord = space_bracket_comma_filter(chord) chord = chord[0].upper() + chord[1:] chord, no3_flag = no3_filter(chord) chord, slash_content, slash_found = slash_chord_filter(chord) root, rootless_chord = root_filter(chord, True) quality = quality_filter(chord, root) root_position = root_position_filter(root) output_template = get_chord_single(rootless_chord, quality) try: all_extensions, semitone_jumps, interval_strings = output_template except TypeError: return if no3_flag: semitone_jumps, interval_strings = no3_scanner(semitone_jumps, interval_strings) else: pass default_keyboard_values = semitones_to_keyboard_inputs( root, semitone_jumps) interval_strings.insert(0, "R") interval_indices = semitones_to_indices(semitone_jumps, root_position) interval_notes = indices_to_notes(interval_indices, root) if slash_found is True: scan_interval_notes, scan_interval_strings, scan_keyboard_values = \ slash_chord_scanner(slash_content, list(interval_notes), interval_strings, default_keyboard_values) return slash_chord_recursion_scanner(interval_notes, scan_interval_notes, scan_interval_strings, scan_keyboard_values) else: final_object_template = interval_notes, interval_strings, default_keyboard_values return final_object_template
def get_chord_multiple(): chord_inputs = open("COMBINED_PRE_QUALS.txt", "r") for i in chord_inputs: stripped_chord = i.replace("\n", "") quality = quality_filter(stripped_chord) remaining_extensions = remaining_extension_filter( stripped_chord, quality) quality_semitones = quality_to_semitones(quality) first_semitone_revision, remaining_extensions = suspension_scanner( remaining_extensions, quality_semitones) final_semitone_revision = extension_scanner(remaining_extensions, first_semitone_revision, quality) final_output_template = [] if final_semitone_revision is None: pass elif repeated_interval_filter(final_semitone_revision) is not True: final_semitone_strings, semitone_indices_to_replace = \ extension_replacement_scan(semitones_to_strings( final_semitone_revision), stripped_chord) final_semitone_revision = remove_element_by_index_scan( final_semitone_revision, semitone_indices_to_replace) final_output_template.insert(0, final_semitone_strings) final_output_template.insert(0, final_semitone_revision) final_output_template.insert(0, [stripped_chord]) print(final_output_template, file=open("database.txt", "a"))
def user_input(): """Receives input from user. Scans and filters to segment chord into root, quality, and extensions Args: No arguments Returns: Tuple of root, quality and extensions (string, string, string) """ chord = input("Enter chord: ") chord = chord[0].upper() + chord[1:] root = root_filter(chord) quality = quality_filter(chord, root) remaining_extensions = remaining_extension_filter(chord, quality, root) final_input = root, quality, remaining_extensions return final_input
if (mode == 0): print('mode = 0: running only on real data') elif (mode == 1): print('mode = 1: running on real data and simulated data') # inject objects for simulated object of mc_source_id sim_data = simple_utils.construct_sim_data(pix_nside_neighbors, mc_source_id) data = simple_utils.inject_sim(data, sim_data, mc_source_id) elif (mode == 2): print('mode = 2: running only on real data') else: print('No/unsupported mode specified; running only on real data') # Quality cut quality = filters.quality_filter(survey, data) data = data[quality] # Deredden magnitudes data = filters.dered_mag(survey, data) print('Found {} objects...').format(len(data)) if (len(data) == 0): print('Ending search prematurely. Look at data for debugging.') nan_array = [np.nan] simple_utils.write_output(results_dir, nside, pix_nside_select, nan_array, nan_array, nan_array, nan_array, nan_array, nan_array, nan_array, nan_array, [mc_source_id], mode, outfile) exit()
def analysis(targ_ra, targ_dec, mod, mc_source_id): """Analyze a candidate""" pix_nside_select = ugali.utils.healpix.angToPix(nside, targ_ra, targ_dec) ra_select, dec_select = ugali.utils.healpix.pixToAng( nside, pix_nside_select) pix_nside_neighbors = np.concatenate([[pix_nside_select], healpy.get_all_neighbours( nside, pix_nside_select)]) # Construct data #data = simple_utils.construct_modal_data(mode, pix_nside_neighbors) data = simple_utils.construct_real_data(pix_nside_neighbors) if (mode == 0): print('mode = 0: running only on real data') elif (mode == 1): print('mode = 1: running on real data and simulated data') # inject objects for simulated object of mc_source_id sim_data = simple_utils.construct_sim_data(pix_nside_neighbors, mc_source_id) data = simple_utils.inject_sim(data, sim_data, mc_source_id) else: print('No mode specified; running only on real data') print('Loading data...') data = simple_utils.construct_modal_data(mode, pix_nside_neighbors, mc_source_id) quality_cut = filters.quality_filter(survey, data) data = data[quality_cut] print('Found {} objects...').format(len(data)) data = filters.dered_mag(survey, data) # This should be generalized to also take the survey iso = isochrone_factory(name=isoname, survey=isosurvey, age=12, z=0.0001, distance_modulus=mod, band_1=band_1.lower(), band_2=band_2.lower()) # g_radius estimate filter = filters.star_filter(survey, data) iso_filter = simple_utils.cut_isochrone_path(data[mag_dered_1], data[mag_dered_2], data[mag_err_1], data[mag_err_2], iso, radius=0.1, return_all=False) angsep = ugali.utils.projector.angsep(targ_ra, targ_dec, data[basis_1], data[basis_2]) bins = np.linspace(0, 0.4, 21) # deg centers = 0.5 * (bins[1:] + bins[0:-1]) area = np.pi * (bins[1:]**2 - bins[0:-1]**2) * 60**2 hist = np.histogram(angsep[(angsep < 0.4) & filter & iso_filter], bins=bins)[0] # counts f_interp = interpolate.interp1d( np.linspace(centers[0], centers[-1], len(hist)), hist / area, 'cubic') f_range = np.linspace(centers[0], centers[-1], 1000) f_val = f_interp(f_range) pairs = zip(f_range, f_val) peak = max(pairs[:len(pairs) / 4], key=lambda x: x[1]) # find peak within first quarter def peak_index(pairs, peak): for i in range(len(pairs)): if pairs[i] == peak: return i osc = int( 0.04 / 0.4 * 1000) # +/- 0.04 (rounded down) deg oscillation about local extremum relmin = argrelextrema(f_val, np.less, order=osc)[0] try: if len(relmin) > 0: #half_point = f_range[relmin[0]] i = 0 while ((f_range[relmin[i]] <= f_range[peak_index(pairs, peak)]) & (i <= len(relmin) - 1)): i += 1 half_point = f_range[relmin[i]] elif len(relmin) == 0: half_peak = ( peak[1] + np.mean(f_val[len(f_val) / 4:]) ) / 2. # normalized to background (after first quarter) #half_peak = np.mean(f_val[len(f_val)/4:]) half_pairs = [] for i in pairs[peak_index(pairs, peak):len(pairs) / 2]: # start after peak, stay within first quarter if i != peak: half_pairs.append((i[0], abs(i[1] - half_peak))) half_point = min(half_pairs, key=lambda x: x[1])[0] # deg except: half_point = 0.1 # fixed value to catch errors g_min = 0.5 / 60. # deg g_max = 12. / 60. # deg if half_point < g_min: g_radius = g_min elif half_point > g_max: g_radius = g_max else: g_radius = half_point # deg angsep = ugali.utils.projector.angsep(targ_ra, targ_dec, data[basis_1], data[basis_2]) nbhd = (angsep < g_radius) return (data, iso, g_radius, nbhd)