Skip to content

Commit

Permalink
updating handling of cases with only one valid value per spectral typ…
Browse files Browse the repository at this point in the history
…e, and expanding tests to cover all colors and properties every time
  • Loading branch information
dsavransky committed Nov 13, 2018
1 parent 4df6ca7 commit e1ae49b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 37 deletions.
12 changes: 10 additions & 2 deletions MeanStars/MeanStars.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ def interpSpT(self, start, end):
for l in self.SpecTypes:
tmp = vals[self.MK==l]
if np.all(np.isnan(tmp)):
self.SpTinterps[name][l] = lambda x: np.nan
self.SpTinterps[name][l] = lambda x: np.array([np.nan]*len(np.array([x]).flatten()))
elif len(np.where(np.isfinite(tmp))[0]) == 1:
arg = float(self.MKn[self.MK==l][np.isfinite(tmp)][0])
tmp = tmp[np.isfinite(tmp)][0]
self.SpTinterps[name][l] = lambda x,tmp=tmp,arg=arg: np.array([tmp if y == arg else np.nan for y in np.array([x]).flatten()])
else:
self.SpTinterps[name][l] = \
scipy.interpolate.interp1d(self.MKn[self.MK==l][np.isfinite(tmp)].astype(float),\
Expand Down Expand Up @@ -361,7 +365,11 @@ def interpOtherSpT(self, key):
for l in self.SpecTypes:
tmp = vals[self.MK==l]
if np.all(np.isnan(tmp)):
self.SpTinterps[key][l] = lambda x: np.nan
self.SpTinterps[key][l] = lambda x: np.array([np.nan]*len(np.array([x]).flatten()))
elif len(np.where(np.isfinite(tmp))[0]) == 1:
arg = float(self.MKn[self.MK==l][np.isfinite(tmp)][0])
tmp = tmp[np.isfinite(tmp)][0]
self.SpTinterps[key][l] = lambda x,tmp=tmp,arg=arg: np.array([tmp if y == arg else np.nan for y in np.array([x]).flatten()])
else:
self.SpTinterps[key][l] = \
scipy.interpolate.interp1d(self.MKn[self.MK==l][np.isfinite(tmp)].astype(float),\
Expand Down
63 changes: 28 additions & 35 deletions tests/test_MeanStars.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,56 +55,49 @@ def test_searchgraph(self):

def test_TeffColor(self):

#grab color at random
cind = np.random.randint(0,high=len(self.ms.colors))

vals = self.ms.getFloatData(self.ms.colorstr[cind])
#do all the colors
for cind in np.arange(len(self.ms.colors)):
vals = self.ms.getFloatData(self.ms.colorstr[cind])
goodinds = np.isfinite(vals)

goodinds = np.isfinite(vals)

self.assertTrue(np.all(self.ms.TeffColor(self.ms.colors[cind][0],self.ms.colors[cind][1],self.ms.Teff[goodinds]) == vals[goodinds]),"Cannot reproduce colors from interpolant for %s"%self.ms.colorstr[cind])
self.assertTrue(np.all(self.ms.TeffColor(self.ms.colors[cind][0],self.ms.colors[cind][1],self.ms.Teff[goodinds]) == vals[goodinds]),"Cannot reproduce colors from interpolant for %s"%self.ms.colorstr[cind])


def test_SpTColor(self):

SpT = self.ms.data['SpT'].data.data

#grab color at random
cind = np.random.randint(0,high=len(self.ms.colors))

vals = self.ms.getFloatData(self.ms.colorstr[cind])
#do all the colors
for cind in np.arange(len(self.ms.colors)):
vals = self.ms.getFloatData(self.ms.colorstr[cind])
goodinds = np.isfinite(vals)

goodinds = np.isfinite(vals)

for v,s in zip(vals[goodinds],SpT[goodinds]):
m = self.ms.specregex.match(s)
self.assertTrue(m,"Couldn't decompose spectral type from data.")
self.assertTrue(self.ms.SpTColor(self.ms.colors[cind][0],self.ms.colors[cind][1],m.groups()[0],m.groups()[1]) == v,"Cannot reproduce colors from interpolant for %s"%self.ms.colorstr[cind])
for v,s in zip(vals[goodinds],SpT[goodinds]):
m = self.ms.specregex.match(s)
self.assertTrue(m,"Couldn't decompose spectral type from data.")
self.assertTrue(self.ms.SpTColor(self.ms.colors[cind][0],self.ms.colors[cind][1],m.groups()[0],float(m.groups()[1])) == v,"Cannot reproduce colors from interpolant for %s"%self.ms.colorstr[cind])


def test_TeffOther(self):

#grab property at random
key = self.ms.noncolors[np.random.randint(0,high=len(self.ms.noncolors))]

vals = self.ms.getFloatData(key)

goodinds = np.isfinite(vals)

self.assertTrue(np.all(self.ms.TeffOther(key,self.ms.Teff[goodinds]) == vals[goodinds]),"Cannot reproduce values from interpolant for %s"%key)
#do all the properties
for key in self.ms.noncolors:
vals = self.ms.getFloatData(key)
goodinds = np.isfinite(vals)

self.assertTrue(np.all(self.ms.TeffOther(key,self.ms.Teff[goodinds]) == vals[goodinds]),"Cannot reproduce values from interpolant for %s"%key)

def test_SpTOther(self):

SpT = self.ms.data['SpT'].data.data

#grab property at random
key = self.ms.noncolors[np.random.randint(0,high=len(self.ms.noncolors))]

vals = self.ms.getFloatData(key)
#do all the properties
for key in self.ms.noncolors:
vals = self.ms.getFloatData(key)
goodinds = np.isfinite(vals)

goodinds = np.isfinite(vals)

for v,s in zip(vals[goodinds],SpT[goodinds]):
m = self.ms.specregex.match(s)
self.assertTrue(m,"Couldn't decompose spectral type from data.")
self.assertTrue(self.ms.SpTOther(key,m.groups()[0],m.groups()[1]) == v,"Cannot reproduce values from interpolant for %s"%key)
for v,s in zip(vals[goodinds],SpT[goodinds]):
m = self.ms.specregex.match(s)
self.assertTrue(m,"Couldn't decompose spectral type from data.")
self.assertTrue(self.ms.SpTOther(key,m.groups()[0],float(m.groups()[1])) == v,"Cannot reproduce values from interpolant for %s"%key)

0 comments on commit e1ae49b

Please sign in to comment.