{"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.12.5"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":70367,"databundleVersionId":9188054,"sourceType":"competition"},{"sourceId":9793669,"sourceType":"datasetVersion","datasetId":5998787},{"sourceId":204949753,"sourceType":"kernelVersion"}],"dockerImageVersionId":30762,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"This code is released under the CC BY 4.0 license, which allows you to use and alter this code (including commercially). You must, however, ensure to give appropriate credit to the original author (Jeroen Cottaar). For details, see https://creativecommons.org/licenses/by/4.0/\n\nThis code visualizes the posterior of the Bayesian Inference fit for my ARIEL competition solution in various ways.\n\nIf you're looking for the code to run the full test set and make a submission, head here: https://www.kaggle.com/code/jeroencottaar/ariel-2nd-place-submission-notebook\n\nFor an explanation of what this is all about: https://www.kaggle.com/competitions/ariel-data-challenge-2024/discussion/543853","metadata":{}},{"cell_type":"code","source":"# Load libraries\nimport sys\nsys.path.append( \"/kaggle/input/my-ariel-library/\" )\nimport ariel_support as ars # general support functions and the data loader\nimport ariel_gp as arg # The model\nimport numpy as np\nimport copy\nimport matplotlib.pyplot as plt","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load data. Unlike the submisison code, we use constant time binning; this is easier to interpret in visualization.\nbaseline_loader = ars.DataLoader()\nbaseline_loader.loader_options = ars.baseline_loader()\nbaseline_loader.loader_options.options_AIRS.time_binning = baseline_loader.loader_options.options_AIRS.time_binning_near_transitions\nbaseline_loader.loader_options.options_FGS.time_binning  = baseline_loader.loader_options.options_FGS.time_binning_near_transitions\nbaseline_loader.planet_ids_to_load = [14485303] # select planet to load; use 496472369 for the plots in my solution thread\ndata = baseline_loader.load()","metadata":{"editable":true,"slideshow":{"slide_type":""},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Solve the model (i.e. find the posterior)\nmodel_options = arg.baseline_model().model.model.model_options\nmodel_options.retrain_pca = False # use PCA from training labels instead\nresults=arg.fit_gp(data[0], model_options=model_options)","metadata":{"editable":true,"slideshow":{"slide_type":""},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Visualize the content of each model component on the original measurement grid\ndef my_2d_plot(d):\n    plt.figure()\n    plt.imshow(d, interpolation='none', aspect='auto', extent = (np.min(data[0]['AIRS']['wavelengths']), np.max(data[0]['AIRS']['wavelengths']), np.max(data[0]['AIRS']['times']), np.min(data[0]['AIRS']['times'])))\n    plt.xlabel('Wavelength [um]')\n    plt.ylabel('Time [h]')\n    plt.colorbar();\ndef airs_mat_for_model(model):\n    obs = copy.deepcopy(results['obs'])\n    obs.labels = model.get_prediction(obs)\n    return obs.export_matrix(True)\nmy_2d_plot(airs_mat_for_model(results['model_mean']));plt.title('Measurement')\nmy_2d_plot(airs_mat_for_model(results['model_mean'].m['signal'].m['spectrum']));plt.title('Star spectrum');\nmy_2d_plot(airs_mat_for_model(results['model_mean'].m['signal'].m['transit']));plt.title('Transit');\nmy_2d_plot(airs_mat_for_model(results['model_mean'].m['signal'].m['drift']));plt.title('Drift');\nmy_2d_plot(airs_mat_for_model(results['model_mean'].m['noise']));plt.title('Noise');","metadata":{"editable":true,"slideshow":{"slide_type":""},"tags":[]},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Make a bunch of other plots visualizing the posterior\narg.visualize_gp(results['obs'],results['model_mean'],results['model_samples'], data[0], model_options, simple=False);","metadata":{"editable":true,"slideshow":{"slide_type":""},"tags":[]},"execution_count":null,"outputs":[]}]}