In [23]:
#Load a specific lightcurve file for testing purposes
import json
import sys
import numpy as np
import emcee
import george
import matplotlib.pyplot as plt
sys.path.append('../classification')
import os
import bandMap
import featureExtraction
lightcurve_directory = '../gen_lightcurves/gp_smoothed/'
filenames = ['SN2005el_gpsmoothed.json','SDSS-II SN 18165_gpsmoothed.json','SN2004dj_gpsmoothed.json', 'SDSS-II SN 13184_gpsmoothed.json']
file_datas = {}
for filename in filenames:
name = filename[:-16]
file_datas[name] = {}
filepath = lightcurve_directory + filename
with open(filepath, 'r') as f:
temp_file_datas = json.load(f)
print(temp_file_datas.keys())
for key in temp_file_datas:
file_datas[name][key] = temp_file_datas[key]
print(file_datas.keys())
In [24]:
wavelet_coeffs = {}
num_band_coeffs = 10
wavelet_type = 'bagidis'
wavelet_level = 1
num_bands = 3
num_coeffs = num_band_coeffs * num_bands
num_classes = 3
In [25]:
for lightcurve in filenames:
lightcurve_path = lightcurve_directory + lightcurve
if not os.path.isfile(lightcurve_path):
print("Cant find {}".format(lightcurve_path))
continue
with open(lightcurve_path, 'r') as f:
file_data = json.load(f)
#This hack removes the '_gpsmoothed.json' from the string to return the objname
objname = lightcurve[:-16]
#print(objname)
#print(list(file_data.keys()))
deleted_filters = 0
## For now, take only filter 'g'
lightcurve_mapped = bandMap.remapBands(file_data)
print(list(lightcurve_mapped.keys()))
req_filters = set(['g','r','i'])
if req_filters.issubset(set(lightcurve_mapped.keys())):
for filt in list(lightcurve_mapped.keys()):
if filt not in ['g', 'r', 'i']:
deleted_filters += 1
#print("Deleted {}".format(filt))
del lightcurve_mapped[filt]
else:
#print("Does not contain all bands")
continue
#print("{} filters deleted".format(deleted_filters))
if len(lightcurve_mapped) == 0:
print("No values in the file")
continue
wavelet_coeffs[objname] = {}
all_coeffs = np.zeros((num_coeffs,))
for i, filt in enumerate(lightcurve_mapped):
#mjd = lightcurve_mapped[filt]['mjd']
#mag = lightcurve_mapped[filt]['mag']
#mag_err = lightcurve_mapped[filt]['dmag']
model_phase = lightcurve_mapped[filt]['modeldate']
model_mag = lightcurve_mapped[filt]['modelmag']
#bspline_mag = file_data[filt]['bsplinemag']
#goodstatus = lightcurve_mapped[filt]['goodstatus']
object_type = lightcurve_mapped[filt]['type']
raw_coeffs = featureExtraction.general_wavelet_coeffs(wavelet_type, model_phase,\
model_mag, num_coeffs=num_band_coeffs)
#Unravel the different filters by appending the information
#print("Left: ", i*num_band_coeffs)
#print("Right: ", (i+1)*num_band_coeffs)
#print(raw_coeffs.reshape(num_band_coeffs))
all_coeffs[i*num_band_coeffs:(i+1)*num_band_coeffs] = raw_coeffs.reshape(num_band_coeffs)
#print(all_coeffs)
wavelet_coeffs[objname]['coeffs'] = all_coeffs
#print(raw_coeffs)
wavelet_coeffs[objname]['type'] = object_type
#print(i)
#if i > 8:
# break
#Write all lightcurve parameters to a file (json format)
print(wavelet_coeffs)
In [ ]:
In [ ]: