Skip to content
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

modify add_models() #28

Open
wants to merge 1 commit into
base: refactor
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions isochrones/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
from .dartmouth import Dartmouth_Isochrone
from .utils import addmags

def get_mag_leaf(leaves):
label = leaves.label
label = label.split('@')[0]
label = label.split('(')[1]
label = label.split(',')[0]
return float(label)

class NodeTraversal(Traversal):
"""
Custom subclass to traverse tree for ascii printing
Expand Down Expand Up @@ -783,7 +790,7 @@ def define_models(self, ic, leaves=None, N=1, index=0):
This bugs up if you call it multiple times. If you want
to re-do a call to this function, please re-define the tree.
"""

self.clear_models()

if leaves is None:
Expand All @@ -797,6 +804,48 @@ def define_models(self, ic, leaves=None, N=1, index=0):
# index = [index]
if np.isscalar(index):
index = (np.ones_like(N)*index).astype(int)

self._N = N
self._index = index

length = len(index)
maxVal = max(index)
listlist = []
#only when there is index with multiple occurances
#assume there is no skipped index
if maxVal < length-1:
for i in range(0, maxVal+1, 1):
count = 0
duplicatedIndex = []
for j,k in enumerate(index):
if k == i:
count += 1
duplicatedIndex.append(j)
else:
continue
if count > 1:
listlist.append(duplicatedIndex)

maxIndexList = []
for item in listlist:
maxMag = np.inf
maxIndex = -1
for i in item:
mag = get_mag_leaf(leaves[i])
if mag < maxMag:
maxMag = mag
maxIndex = i
maxIndexList.append(maxIndex)

# force _0 for brightest star in the system
maxIndexList = sorted(maxIndexList, reverse=True)
for i in maxIndexList:
leaves[i].remove_children()
leaves[i].add_model(ic, N[i], index[i])
leaves.pop(i)
np.delete(N,i)
N = np.delete(N,i)
index = np.delete(index,i)

# Add the appropriate number of model nodes to each
# star in the highest-resoluion image
Expand All @@ -808,9 +857,6 @@ def define_models(self, ic, leaves=None, N=1, index=0):
# Make sure there are no model-less hanging leaves.
self.trim()

self._N = N
self._index = index

self._clear_all_leaves()

def clear_models(self):
Expand Down