In [1]:
!ls
In [16]:
import json
import numpy as np
import os
import sys
from collections import Counter
import matplotlib.pyplot as plt
sys.path.append('../classification')
In [3]:
path_to_SNe = '../gen_lightcurves/gp_smoothed/'
SNe_lightcurves = os.listdir(path_to_SNe)
In [4]:
filters = []
for lcurve in SNe_lightcurves:
lightcurve_path = path_to_SNe + lcurve
if lightcurve_path.endswith('LIST'):
continue
#print(lightcurve_path)
with open(path_to_SNe + lcurve) as f:
lcurve_data = json.load(f)
filters += [lcurve_data[list(lcurve_data)[0]]['mapping']]
print(set(filters))
In [5]:
print(len(set(filters)))
unique = list(set(filters))
unique = np.array(unique)
#print(unique)
surveys_ranked = ['cfa', 'csp','kait', 'swift', 'vega','pairitel', 'sdss','landolt','standard']
total = 0
found = 0
unmatched = []
for i, filt in enumerate(filters):
total += 1
#print(filt.lower())
for survey in surveys_ranked:
if survey in filt.lower():
found += 1
break
else:
unmatched += [filt.lower()]
print(total)
print(found/total)
print(Counter(unmatched))
print(402/6717)
#test = np.array(['test', 'testing', 'abcdefghijklmnopq', 'PAIR', 'pair'])
#print(np.where('testing' in test))
#print([x for x in test if 'PAIR' in x])
In [6]:
import itertools
import operator
from collections import Counter
def most_common(L):
# get an iterable of (item, iterable) pairs
SL = sorted((x, i) for i, x in enumerate(L))
# print 'SL:', SL
groups = itertools.groupby(SL, key=operator.itemgetter(0))
# auxiliary function to get "quality" for an item
def _auxfun(g):
item, iterable = g
count = 0
min_index = len(L)
for _, where in iterable:
count += 1
min_index = min(min_index, where)
# print 'item %r, count %r, minind %r' % (item, count, min_index)
return count, -min_index
# pick the highest-count/earliest item
return max(groups, key=_auxfun)[0]
most_common(filters)
Counter(filters)
Out[6]:
In [7]:
count = 0
total = 0
for filt in filters:
total+=1
if filt[0] in ['g','r','i','z', 'u', 'U', 'B','V','R', 'I', 'Y']:
count += 1
else:
if filt != 'C_Catalina Schmidt':
pass
#print(filt)
print(count)
print(total)
print(count/total)
In [8]:
filters_B = []
for filt in filters:
if filt[0] == 'u':
filters_B.append(filt)
c = Counter(filters_B)
print(c)
In [11]:
count = 0
failed = 0
filters = []
filter_set = set(['g','r','i'])
filter_counter = []
for i, lcurve in enumerate(SNe_lightcurves):
if lcurve.endswith('LIST'):
continue
with open(path_to_SNe + lcurve) as f:
lcurve_data = json.load(f)
filters = list(lcurve_data.keys())
if filter_set.issubset(set(filters)):
count += 1
#print(filters)
else:
failed += 1
#append all to the filter Counter
filter_counter.append(set(filters))
total = count + failed
print(count)
print(count/total)
In [12]:
from itertools import combinations
#print(list(combinations([1,2,3],2)))
combinations_length = range(1,4)
filters_all = ['g','r','i','z']
for comb_len in combinations_length:
print(comb_len)
print(list(combinations(filters_all, comb_len)))
#print(filter_counter)
In [13]:
import bandMap
from collections import Counter
In [14]:
#### FIX BANDMAP to return what mapped to what
count = 0
failed = 0
total = 0
filters = []
filter_set = set(['g'])
obj_type = Counter()
survey = Counter()
for i, lcurve in enumerate(SNe_lightcurves):
total += 1
if lcurve.endswith('LIST'):
continue
with open(path_to_SNe + lcurve) as f:
lcurve_data = json.load(f)
#print(lcurve)
lcurve_remapped = lcurve_data
out_filters = set(lcurve_remapped.keys())
if filter_set.issubset(set(out_filters)):
count += 1
filt_test = list(lcurve_remapped.keys())[0]
obj_type.update([lcurve_remapped[filt_test]['type']])
#survey_name = lcurve_remapped.keys()
survey.update(lcurve_data.keys())
#print(filters)
elif out_filters is not None:
failed += 1
print(count)
print(count/total)
print(obj_type)
print(survey)
In [15]:
num_objs = len(filter_counter)
comb_counter = Counter()
filters_all = ['g','r','i','z','u','Y']
for i, filter_set in enumerate(filter_counter):
combinations_length = range(2,4)
for comb_len in combinations_length:
comb_all = combinations(filters_all, comb_len)
for comb_unique in comb_all:
if set(comb_unique).issubset(set(filter_set)):
comb_counter.update([comb_unique])
#if i > 20:
# break
print(num_objs)
print(comb_counter)
In [99]:
print(sorted(comb_counter, key=lambda x: comb_counter[x], reverse=True))
In [98]:
%matplotlib notebook
plt.figure(figsize=(35,4))
plt.bar(np.array(range(len(comb_counter)))*2, sorted(comb_counter.values(), reverse=True), tick_label=sorted(comb_counter, key=lambda x: comb_counter[x], reverse=True))
plt.show()
In [76]:
vals = np.array(list(comb_counter.values()))
keys = np.array(list(comb_counter.keys()))
thresh = 200
num_above_thresh = len(np.where(vals > thresh)[0])
print(num_above_thresh)
print(keys[np.where(vals > thresh)])
In [ ]: