In [38]:
%matplotlib notebook
In [39]:
# imports
import numpy as np
from matplotlib import pyplot as plt
from astropy.table import Table
from desisim.spec_qa.redshifts import match_truth_z
In [3]:
path = '/scratch/DESI_SCRATCH/18.3/'
In [4]:
simz_tab = Table.read(path+'truth.fits')
In [5]:
zb_tab = Table.read(path+'zcatalog-mini.fits')
In [6]:
match_truth_z(simz_tab, zb_tab, mini_read=True)
In [8]:
simz_tab
Out[8]:
In [11]:
np.unique(simz_tab['ZWARN'])
Out[11]:
In [16]:
measured_z = simz_tab['ZWARN'].mask == False
np.unique(simz_tab[measured_z]['SPECTYPE']), np.unique(simz_tab[measured_z]['TRUESPECTYPE'])
Out[16]:
In [18]:
# Cut the table
cut_simz = simz_tab[measured_z]
In [27]:
# Strip those columns
strip_ttypes = np.char.rstrip(cut_simz['TRUESPECTYPE'])
strip_stypes = np.char.rstrip(cut_simz['SPECTYPE'])
In [29]:
# All TRUE types
ttypes = np.unique(strip_ttypes)
ttypes
Out[29]:
In [30]:
# All SPEC types
stypes = np.unique(strip_stypes)
stypes
Out[30]:
In [31]:
# Init
results = {}
for ttype in ttypes:
results[ttype] = {}
In [36]:
for ttype in ttypes:
itrue = strip_ttypes == ttype
# Init correct answer in case there are none
results[ttype][ttype] = 0
#import pdb; pdb.set_trace()
for stype in stypes:
results[ttype][stype] = np.sum(strip_stypes[itrue] == stype)
In [37]:
results
Out[37]:
In [53]:
confuse = np.zeros((ttypes.size, ttypes.size))
In [54]:
for ii,ttype in enumerate(ttypes):
for jj,ottype in enumerate(ttypes):
if ottype in results[ttype].keys():
confuse[ii,jj] = results[ttype][ottype]
confuse
Out[54]:
In [55]:
for kk in range(confuse.shape[0]):
confuse[kk,:] /= np.sum(confuse[kk,:])
confuse
Out[55]:
In [60]:
#plt.clf()
plt.matshow(confuse)
plt.colorbar()
plt.xlabel('True')
plt.ylabel('Predicted')
plt.show()
In [ ]: