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())


dict_keys(['B_', 'B__CSP', 'B_kait3', 'H_PAIRITEL', 'H__CSP', 'I_kait3', 'J_PAIRITEL', 'J__CSP', 'Ks_PAIRITEL', 'R_kait3', 'U_', 'V_', 'V__CSP', 'V_kait3', 'Y__CSP', 'g__CSP', 'i__CSP', 'r__CSP', 'u__CSP'])
dict_keys(['gprime_SDSS_SDSS', 'rprime_SDSS_SDSS'])
dict_keys(['B_', 'I_', 'R_', 'U_', 'V_'])
dict_keys(['gprime_SDSS_SDSS', 'iprime_SDSS_SDSS', 'rprime_SDSS_SDSS'])
dict_keys(['SN2005el', 'SDSS-II SN 18165', 'SN2004dj', 'SDSS-II SN 13184'])

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)


['u', 'g', 'r', 'i', 'Y']
{'SN2005el': {'coeffs': array([ 169.39548978,  -11.79044162,   -3.80905478,   -1.98315614,
         -1.96940626,   -1.02722576,   -0.85057462,   -0.73597442,
         -0.70742168,   -0.46443375,  162.25505073,   -9.24618659,
         -4.21741415,   -1.68445406,   -1.57675959,   -1.55665855,
         -0.77349662,   -0.65735869,   -0.62997854,   -0.50885044,
        165.17156984,   -8.84111205,   -3.50112672,   -2.22591535,
         -2.15286346,   -1.15657317,   -0.62653659,   -0.59466361,
         -0.49173405,   -0.40061099]), 'type': 'Ia'}}
['g', 'r']
Does not contain all bands
[]
Does not contain all bands
['g', 'r', 'i']
{'SN2005el': {'coeffs': array([ 169.39548978,  -11.79044162,   -3.80905478,   -1.98315614,
         -1.96940626,   -1.02722576,   -0.85057462,   -0.73597442,
         -0.70742168,   -0.46443375,  162.25505073,   -9.24618659,
         -4.21741415,   -1.68445406,   -1.57675959,   -1.55665855,
         -0.77349662,   -0.65735869,   -0.62997854,   -0.50885044,
        165.17156984,   -8.84111205,   -3.50112672,   -2.22591535,
         -2.15286346,   -1.15657317,   -0.62653659,   -0.59466361,
         -0.49173405,   -0.40061099]), 'type': 'Ia'}, 'SDSS-II SN 13184': {'coeffs': array([  2.12921593e+02,   5.11070427e-01,  -1.95785578e-01,
         1.72586044e-01,   1.57506099e-01,  -1.41925853e-01,
        -9.52140808e-02,   8.88691704e-02,   6.91471721e-02,
        -8.50176820e-02,   2.12115389e+02,   9.15061506e-01,
         4.33607392e-01,   2.22595211e-01,  -1.45886480e-01,
        -1.28895447e-01,   1.39046926e-01,  -9.69777208e-02,
         5.73118322e-02,  -7.76049930e-02,   1.93181514e+02,
         9.88965860e-01,  -6.44228185e-01,   4.32366384e-01,
        -2.16765995e-01,  -1.85923730e-01,   1.77851944e-01,
         1.75225080e-01,  -1.47296517e-01,  -8.90014929e-02]), 'type': 'II'}}

In [ ]:


In [ ]: