<jupyter_start><jupyter_text>Gaussian Process Modeling of Light CurvesIn this notebook we exemplify the modeling of the light curves using a Gaussian process (GP). Index1. [Import Packages](imports)2. [Load the Original Dataset](loadData)3. [Fit Gaussian Processes](gps)    1. [Set Path to Save GP Files](saveGps)    2. [Compute GP Fits](makeGps)4. [Light Curve Visualization](see) 1. Import Packages<jupyter_code>import collections
import os
import pickle
import sys
import time
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
from snmachine import gps, sndata
from utils.plasticc_pipeline import create_folder_structure, get_directories, load_dataset
%config Completer.use_jedi = False  # enable autocomplete<jupyter_output><empty_output><jupyter_text>Aestetic settings<jupyter_code>%matplotlib inline

sns.set(font_scale=1.3, style="ticks")<jupyter_output><empty_output><jupyter_text>2. Load DatasetFirst, **write** the path to the folder that contains the dataset we want to use, `folder_path`.<jupyter_code>folder_path = '../snmachine/example_data'<jupyter_output><empty_output><jupyter_text>Then, **write** in `data_file_name` the name of the file where your dataset is saved.In this notebook we use the dataset saved in [2_preprocess_data](2_preprocess_data.ipynb).<jupyter_code>data_file_name = 'example_dataset_gapless50.pckl'<jupyter_output><empty_output><jupyter_text>Load the dataset.<jupyter_code>data_path = os.path.join(folder_path, data_file_name)
dataset = load_dataset(data_path)<jupyter_output>Opening from binary pickle
Dataset loaded from pickle file as: <snmachine.sndata.PlasticcData object at 0x7fca47352150><jupyter_text>3. Fit Gaussian Processes 3.1. Set Path to Save GP FilesWe can now generate a folder structure to neatly save the files. Otherwise, you can directly write the path to the folder to save the GP files in `saved_gps_path`.**A)** Generate the folder structure.**Write** the name of the folder you want in `analysis_name`.<jupyter_code>analysis_name = data_file_name[:-5]
analysis_name<jupyter_output><empty_output><jupyter_text>Create the folder structure.<jupyter_code>create_folder_structure(folder_path, analysis_name)<jupyter_output>Folders already exist with this analysis name.

                Are you sure you would like to proceed, this will overwrite the
                example_dataset_gapless50 folder [Y/n]
                
Y
Overwriting existing folder..<jupyter_text>See the folder structure.<jupyter_code>directories = get_directories(folder_path, analysis_name) 
directories<jupyter_output><empty_output><jupyter_text>Set the path to the folder to save the GP files.<jupyter_code>path_saved_gps = directories['intermediate_files_directory']<jupyter_output><empty_output><jupyter_text>**B)** Directly choose where to save the GP files.**Write** the path to the folder to save the GP files in `saved_gps_path`. ```pythonsaved_gps_path = os.path.join(folder_path, data_file_name[:-5])```  3.2. Compute GP Fits**Choose**:- `t_min`: minimim time to evaluate the Gaussian Process Regression at.- `t_max`: maximum time to evaluate the Gaussian Process Regression at.- `gp_dim`: dimension of the Gaussian Process Regression. If  `gp_dim` is 1, the filters are fitted independently. If `gp_dim` is 2, the Matern kernel is used to fit light curves both in time and wavelength.- `number_gp`: number of points to evaluate the Gaussian Process Regression at.- `number_processes`: number of processors to use for parallelisation (**optional**).<jupyter_code>t_min = 0
t_max = 278

gp_dim = 2
number_gp = 276
number_processes = 1
gps.compute_gps(dataset, number_gp=number_gp, t_min=t_min, t_max=t_max, 
                gp_dim=gp_dim, output_root=path_saved_gps, 
                number_processes=number_processes)<jupyter_output>Performing Gaussian process regression.
Models fitted with the Gaussian Processes values.
Time taken for Gaussian process regression: 10.09s.<jupyter_text>[Go back to top.](index) 4. Light Curve VisualizationHere we show the light curve of an event and the Gaussian process used to fit it.<jupyter_code>obj_show = '7033'
sndata.PlasticcData.plot_obj_and_model(dataset.data[obj_show], 
                                       dataset.models[obj_show])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08284849895275774, 'fraction_numerical': 0.012334186641843147, 'mean_word_length': 5.736677115987461, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '490623', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1325, 'n_words': 412, 'path': 'examples/3_model_lightcurves.ipynb', 'repo_name': 'heather999/snmachine', 'size': '4297'}