def process_remainder(cat, number, stage, success): """ Optional processing remainder. All sources are split as a multi-group. :param cat: Inputted catalogue of sources as yet unsolved. :param number: The number of epochs included. :param stage: The name of the stage so output can be sorted. :param success: The percentage of sources solved by the beginning of this stage. :return: stage information including catalogues of sources solved and unsolved. """ regroup_start_time = time.time() # record start time islands = [cat] bug_count = 0 eps = 0 for t in range(len(islands)): print(len(islands[t])) total_count = len(islands) print("%d islands created\n" % total_count) goodies = [] badies = [] islands[0] = sorted(islands[0]) seperated_group = complete_island_splitting(islands[0], number, stage) goodies.extend(seperated_group) for i in range(int(len(seperated_group))): light_curve(seperated_group[i], stage, number) badies.extend([item for item in islands[0] if item not in np.ravel(seperated_group)]) goodies = sorted(goodies) for i in range(len(goodies)): print(goodies[i]) goodies = np.ravel(goodies) badies = np.ravel(badies) badies = sorted(badies) write_catalog("./results/goodies/%d_epochs/goodies_%s_%depochs.csv" % (number, stage, number), goodies, fmt='csv') write_catalog("./results/badies/%d_epochs/badies_%s_%depochs.csv" %(number, stage, number), badies, fmt='csv') goodies_cat = sorted(goodies) print(goodies_cat) print(badies) percentage_solved = 100*(success/100 + (1-success/100)*(len(goodies)/(len(goodies)+len(badies)))) print("\nSuccess rate = %f%%" % percentage_solved) run_time = (time.time() - regroup_start_time) print("%s --- %f seconds ---" % (stage, run_time)) return {'eps': eps, 'goodies': goodies, 'badies': badies, 'percentage_solved': percentage_solved, 'time': run_time, 'bug_count': bug_count}
def multigroup_plot(island, stage, num, group_size): """ Plot the combined light curve of multiple objects. :param island: The combined catalogue of sources for multiple sources. :param stage: The name of the current stage. :param num: The number of epochs included. :param group_size: Number of objects included in the multi plot. :return: Nothing. Only plots combined light curve and generates multi-group csv. """ x = [] y = [] flux_error = [] for i in range(len(island)): x.append(island[i].island) y.append(island[i].peak_flux) flux_error.append(island[i].err_peak_flux) which_srcs = [] for k in range(group_size): which_srcs.append(island[k].source) if (len(island) / num) < 30: plot_name = str(which_srcs).strip('[]') else: plot_name = str(len(island)) plt.plot(x, y, linestyle='none', marker='o', color='red') plt.xlabel('Epoch number') plt.ylabel('peak_flux (Jy)') plt.xlim(-1, num) plt.ylim(0, max(y[0], y[1], y[2], y[3]) + 2) plt.suptitle('Light Curve %s' % plot_name) plt.savefig('./results/plots/%d_epochs/%s/multiplot_%s.png' % (num, stage, plot_name)) plt.gcf().clear() write_catalog('./results/plots/%d_epochs/%s/plot_%s.csv' % (num, stage, plot_name), island, fmt='csv')
def light_curve(island, stage, num): """ Plot the light for a inputted group. :param island: The group of sources that have been associated and deemed good. :param stage: The name of the current stage. :param num: The number of epochs included. :return: Nothing. Only plots light curve and generates group csv. """ x = [] y = [] flux_error = [] for i in range(len(island)): x.append(island[i].island) y.append(island[i].peak_flux) flux_error.append(island[i].err_peak_flux) which_src = island[0].source which_first_island = island[0].island plt.errorbar(x, y, yerr=flux_error, marker='o', color='red', ecolor='blue', capsize=2, elinewidth=1) plt.xlabel('Epoch number') plt.ylabel('peak_flux (Jy)') plt.xlim(-1, num) plt.ylim(0, y[0] + 1) plt.suptitle('Light Curve %d' % which_src) plt.savefig('./results/plots/%d_epochs/%s/plot_%d - %d.png' % (num, stage, which_src, which_first_island)) plt.gcf().clear() write_catalog('./results/plots/%d_epochs/%s/plot_%d - %d.csv' % (num, stage, which_src, which_first_island), island, fmt='csv')
def process_regrouping_fractionislands(cat, number, eps, stage, dist_func, success, looseness=1): """ Processing for each stage of layer three of the program. Where partial groups can be accepted and processed. :param cat: Inputted catalogue of sources as yet unsolved. :param number: The number of epochs included. :param eps: The set range parameter for grouping for this stage. :param stage: The name of the stage so output can be sorted. :param dist_func: The name of the separation function to be used in regrouping. :param success: The percentage of sources solved by the beginning of this stage. :param looseness: Looseness selection for scaling of allowance for partial islands. :return: stage information including catalogues of sources solved and unsolved. """ regroup_start_time = time.time() # record start time regroup_return = regroup(cat, eps, number, far=None, dist=dist_func, partial= True) islands = regroup_return['islands'] bug_count = regroup_return['bug_counter'] for t in range(len(islands)): print(len(islands[t])) total_count = len(islands) print("%d islands created\n" % total_count) goodies = [] badies = [] for i in range(len(islands)): islands[i] = sorted(islands[i]) flux_sum = 0 local_rms_sum = 0 err_peak_flux_sum = 0 for k in range(len(islands[i])): flux_sum += islands[i][k].peak_flux local_rms_sum += islands[i][k].local_rms if math.isnan(islands[i][k].err_peak_flux) or islands[i][k].err_peak_flux > 1000: err_peak_flux_sum += 0.04 else: err_peak_flux_sum += islands[i][k].err_peak_flux average_flux = flux_sum/(len(islands[i])) average_local_rms = local_rms_sum/(len(islands[i])) average_err_peak_flux = err_peak_flux_sum/(len(islands[i])) allowance = math.ceil(looseness*number*(1/((average_flux-average_local_rms)/average_err_peak_flux))) if allowance < 0: allowance = 2*number/3 if len(islands[i]) <= number and len(islands[i]) > (number - allowance) and len(islands[i]) > number/3: goodies.extend(islands[i]) print(islands[i]) light_curve(islands[i], stage, number) else: badies.extend(islands[i]) badies = np.ravel(badies) badies = sorted(badies) write_catalog("./results/goodies/%d_epochs/goodies_%s_%depochs.csv" % (number, stage, number), goodies, fmt='csv') write_catalog("./results/badies/%d_epochs/badies_%s_%depochs.csv" %(number, stage, number), badies, fmt='csv') goodies_cat = sorted(goodies) print(goodies_cat) print(badies) percentage_solved = 100*(success/100 + (1-success/100)*(len(goodies)/(len(goodies)+len(badies)))) print("\nSuccess rate = %f%%" % percentage_solved) run_time = (time.time() - regroup_start_time) print("%s --- %f seconds ---" % (stage, run_time)) return {'eps': eps, 'goodies': goodies, 'badies': badies, 'percentage_solved': percentage_solved, 'time': run_time, 'bug_count': bug_count}
def process_regrouping_allislands(cat, number, eps, stage, dist_func, success): """ Processing for each stage of layer two of the program. Regrouping followed by flux splitting. :param cat: Inputted catalogue of sources as yet unsolved. :param number: The number of epochs included. :param eps: The set range parameter for grouping for this stage. :param stage: The name of the stage so output can be sorted. :param dist_func: The name of the separation function to be used in regrouping. :param success: The percentage of sources solved by the beginning of this stage. :return: stage information including catalogues of sources solved and unsolved. """ regroup_start_time = time.time() # record start time regroup_return = regroup(cat, eps, number, far=None, dist=dist_func) islands = regroup_return['islands'] bug_count = regroup_return['bug_counter'] for t in range(len(islands)): print(len(islands[t])) total_count = len(islands) print("%d islands created\n" % total_count) goodies = [] badies = [] for i in range(len(islands)): islands[i] = sorted(islands[i]) if len(islands[i]) == number: goodies.append(islands[i]) light_curve(islands[i], stage, number) elif len(islands[i])% number == 0: seperated_group = complete_island_splitting(islands[i], number, stage) goodies.extend(seperated_group) for i in range(int(len(seperated_group))): light_curve(seperated_group[i], stage, number) else: badies.extend(islands[i]) goodies = sorted(goodies) for i in range(len(goodies)): print(goodies[i]) goodies = np.ravel(goodies) badies = np.ravel(badies) badies = sorted(badies) write_catalog("./results/goodies/%d_epochs/goodies_%s_%depochs.csv" % (number, stage, number), goodies, fmt='csv') write_catalog("./results/badies/%d_epochs/badies_%s_%depochs.csv" %(number, stage, number), badies, fmt='csv') goodies_cat = sorted(goodies) print(goodies_cat) print(badies) percentage_solved = 100*(success/100 + (1-success/100)*(len(goodies)/(len(goodies)+len(badies)))) print("\nSuccess rate = %f%%" % percentage_solved) run_time = (time.time() - regroup_start_time) print("%s --- %f seconds ---" % (stage, run_time)) return {'eps': eps, 'goodies': goodies, 'badies': badies, 'percentage_solved': percentage_solved, 'time': run_time, 'bug_count': bug_count}