-
Notifications
You must be signed in to change notification settings - Fork 4
Fake cluster #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shivangeerathi
wants to merge
15
commits into
master
Choose a base branch
from
fake_cluster
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fake cluster #16
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3856c6c
Test file
Catarina-Alves 814df5c
example fake cluster
shivangeerathi a0d59dc
making fake cluster
shivangeerathi 4a01de1
Merge branch 'master' of https://github.com/ignotur/Random-forest-ope…
shivangeerathi f5a3834
Merge branch 'fake_cluster' of https://github.com/AstroHackWeek2020/R…
shivangeerathi 426dbbe
added code to generate fake clusters
shivangeerathi 05a77c8
Merge branch 'fake_cluster' of https://github.com/ignotur/Random-fore…
shivangeerathi fcfae69
deleted obsolete files
shivangeerathi c9e0df5
removed more obsolete files
shivangeerathi c7f6ccc
more descriptive script name, moved data to the data folder
shivangeerathi f866c45
Rename isochrone.dat to data/isochrone.dat
glukhove c57ad60
Update create_non_clusters_isochrones.py
glukhove f25a145
Update create_non_clusters_isochrones.py
glukhove 6e14a03
moving isochrone to the 'data' folder
shivangeerathi 7850236
adding isochrones to the data folder
shivangeerathi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| ''' | ||
| -------------------------------------------------------------------------------- | ||
| Simple script to create non-clusters from isochrones. | ||
| Run as: | ||
| >> python create_non_clusters_isochrones.py <n> | ||
| where 'n' is the total number of desired non-clusters. | ||
| -------------------------------------------------------------------------------- | ||
| ''' | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| from numpy import random | ||
| import sys, os | ||
| import matplotlib.pyplot as plt | ||
|
|
||
| # add dust extinction | ||
| def add_dust_extinction(): | ||
| pass | ||
|
|
||
| def hess( col, mag ): | ||
| #histogram definition | ||
| xyrange = [[-1,2],[-5,4.0]] # data range | ||
| bins = [20,20] # number of bins | ||
| thresh = 3 #density threshold | ||
|
|
||
| # histogram the data | ||
| hh, locx, locy = np.histogram2d(col, mag, range=xyrange, bins=bins) | ||
| posx = np.digitize(col, locx) | ||
| posy = np.digitize(mag, locy) | ||
|
|
||
| #select points within the histogram | ||
| ind = (posx > 0) & (posx <= bins[0]) & (posy > 0) & (posy <= bins[1]) | ||
| hhsub = hh[posx[ind] - 1, posy[ind] - 1] | ||
| col1, mag1 = [], [] | ||
| hh[hh < thresh] = np.nan | ||
|
|
||
| return hh, xyrange | ||
|
|
||
| def plotHessDiagram(non_cluster_df): | ||
| # xlim, ylim = [-0.5, 2], [4, -5] | ||
| g = non_cluster_df['G'] | ||
| b_p = non_cluster_df['Bp'] | ||
| r_p = non_cluster_df['Rp'] | ||
|
|
||
| # plotting | ||
| fig = plt.figure(figsize=(5, 5)) | ||
| ax = fig.add_subplot(111) | ||
|
|
||
| hh, xyrange = hess( b_p - r_p, g ) | ||
| im = ax.imshow( np.flipud(hh.T), cmap="viridis", extent= np.array(xyrange).flatten(), | ||
| interpolation='nearest', origin='upper', aspect="auto") | ||
| cb = plt.colorbar(im, ax=ax) | ||
|
|
||
| ax.set_xlabel('$B_{p} - R_{p}$') | ||
| ax.set_ylabel('G') | ||
| ax.invert_yaxis() | ||
| outfile = "non_cluster.png" | ||
| fig.savefig(outfile, dpi=300) | ||
| plt.show() | ||
|
|
||
| def make_non_cluster(id): | ||
| # no. of stars in the non-cluster | ||
| n = np.random.randint(30, high=500) | ||
|
|
||
| # load isochrone | ||
| isochrone = np.loadtxt("isochrone.dat", comments="#") | ||
|
|
||
| # shuffle and select n stars | ||
| temp_list = np.arange( isochrone.shape[0] ) | ||
| np.random.shuffle( temp_list ) | ||
| subsetIdx = temp_list[ :n ] | ||
| subsetIdx = np.array( subsetIdx ) | ||
|
|
||
| non_cluster = np.column_stack((isochrone[subsetIdx, -3:], np.repeat(id, n))) | ||
|
|
||
| return non_cluster | ||
|
|
||
| if __name__=='__main__': | ||
| # no. of stars that you want in your cluster | ||
| n_non_cluster = int(sys.argv[1]) | ||
|
|
||
| non_clusters = [] | ||
| for id in range(n_non_cluster): | ||
| non_clusters.append( make_non_cluster(id) ) | ||
|
|
||
| # col_names = ['G', 'Bp', 'Rp', 'cluster_id'] | ||
| arr_non_clusters = np.concatenate([c for c in non_clusters]) | ||
| np.save("data/non_clusters_isochrones.npy", arr_non_clusters) | ||
|
|
||
|
|
||
| # cols = ['Zini', 'MH', 'logAge', 'Mini', 'int_IMF', 'Mass', 'logL', 'logTe',\ | ||
| # 'logg', 'label', 'McoreTP', 'C_O', 'period0', 'period1', 'pmode', 'Mloss',\ | ||
| # 'tau1m', 'X', 'Y', 'Xc', 'Xn', 'Xo', 'Cexcess', 'Z', 'mbolmag',\ | ||
| # 'Gmag', 'G_BPmag', 'G_RPmag'] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.