def cluster_age_analysis(df, cluster_label : int, cluster_name : str, cost_function : str): df_group = df.loc[df['label'] == cluster_label] group_cluster = cluster(df_group, cluster_name, error_type = cost_function) #group_cluster.photometric_cuts() # group_cluster.output_cluster(directory = cluster_output_directory) iso_grid = grid.large_grid(isochrone_filepath) cluster_fitter = fitter(group_cluster, iso_grid) age = cluster_fitter.return_best_fit(type_fit = 'chi2', plot = True, save = True) #for g in iso_grid: # g.plot_grid(stellar_pop = group_cluster) return age, df_group
delivs["Delivery Volume"][i], delivs["Adj Nodes"][i]) for i in range(len(delivs)) ] #Establish set Outside, which tracks the nodes that are not assigned to a cluster Outside = [Node[i].index for i in range(len(Node))] #Create set that tracks the nodes that have been assigned to a cluster Assigned_Nodes = [] #Cluster Initialization: #Clusters take a Node object that will be the centroid, a balance target for the cluster, and a capacity. #This line creates 3 clusters with the facilities as the central locations. Cluster = [ cluster(Node[i], delivs["Delivery Volume"][i], 999999999) for i in range(465, 468) ] #This section of code assigns what are considered to be "better" initial centroids. """ Cluster = [] Cluster.append(cluster(Node[376], target_weight[i], 999999999)) Cluster.append(cluster(Node[49], target_weight[i], 999999999)) Cluster.append(cluster(Node[68], target_weight[i], 999999999)) """ #Give clusters indicies for easy indentification i = 0 for i in range(len(Cluster)): Cluster[i].index = i
Node = [node(i, (deliv_517["Longitude"][i], deliv_517["Latitude"][i]), deliv_517["Delivery Volume"][i], deliv_517["Adj Nodes"][i]) for i in range(len(deliv_517))] #Establish set Outside, which tracks the nodes that are not assigned to a cluster Outside = [] i = 0 for i in range(len(Node)): Outside.append(Node[i].index) #Create set that tracks the nodes that have been assigned to a cluster Assigned_Nodes = [] #Cluster Initialization #The last three nodes are the facilities. We are using them as the initial nodes in order to build the algorithm. #Clusters take a Node object that will be the centroid, a target weight for the cluster, and a capacity. Cluster = [cluster(Node[i], target_weight, deliv_517["Delivery Volume"][i]) for i in range(465,468)] #Give cluster indices in order to easily identify them i = 0 for i in range(len(Cluster)): Cluster[i].index = i #Update cluster information i = 0 for i in range(len(Cluster)): #Assign the centroid into the cluster's Node list Cluster[i].Nodes.append(Cluster[i].centroid) Cluster[i].nodes_idx.append(Cluster[i].centroid.index) #Assign the associated cluster to its centroid Cluster[i].centroid.cluster = Cluster[i].index
from Cluster import cluster #Create Node set Node = [node(i, (delivs["Longitude"][i], delivs["Latitude"][i]), delivs["Delivery Volume"][i], delivs["Adj Nodes"][i]) for i in range(len(delivs))] #Establish set Outside, which tracks the nodes that are not assigned to a cluster Outside = [Node[i] for i in range(len(Node))] #Create set that tracks the nodes that have been assigned to a cluster Assigned_Nodes = [] #Cluster Initialization: #Clusters take a Node object that will be the centroid, a balance target for the cluster, and a capacity. #This line creates 3 clusters with the facilities as the central locations. Cluster = [cluster(Node[i], target_card, delivs["Delivery Volume"][i], 999999999) for i in range(455,458)] #This section of code assigns what are considered to be "better" initial centroids. """ Cluster = [] Cluster.append(cluster(Node[376], target_weight[i], 999999999)) Cluster.append(cluster(Node[49], target_weight[i], 999999999)) Cluster.append(cluster(Node[68], target_weight[i], 999999999)) """ #Give clusters indicies for easy indentification i = 0 for i in range(len(Cluster)): Cluster[i].index = i #Update cluster information i = 0
def createClusters(data, title): p1.title=title temp_Cluster=cluster(np.asarray(data, dtype=float)) temp_Cluster.makeCluster() Cluster_Plot_Result(temp_Cluster) return temp_Cluster
import numpy as np import pandas as pd from isofit import grid, fitter from Cluster import cluster isochrone_filepath = '/Users/admin/Desktop/astro_research/orion/orion_populations/parsec_colibri_isochrones/output44.dat' df = pd.read_csv( '/Users/admin/Desktop/astro_research/orion/orion_populations/apogee_gaia_sample.csv' ) my_grid = grid(isochrone_filepath) lambda_orion_df = df.loc[df.label == 4] lambda_orion = cluster(lambda_orion_df, 'Lambda Orion') lambda_orion.photometric_cuts() my_grid.plot_grid(lambda_orion) #my_fitter = fitter(lambda_orion, my_grid) #my_fitter.plot_best_fit()