{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":101849,"databundleVersionId":12846694,"sourceType":"competition"}],"dockerImageVersionId":31089,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport pandas as pd\nimport numpy as np\nfrom pathlib import Path","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-07-18T06:44:03.206588Z","iopub.execute_input":"2025-07-18T06:44:03.207461Z","iopub.status.idle":"2025-07-18T06:44:05.896279Z","shell.execute_reply.started":"2025-07-18T06:44:03.207424Z","shell.execute_reply":"2025-07-18T06:44:05.895088Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"DATA_DIR = Path(\"/kaggle/input/ariel-data-challenge-2025\")\n\ntrn_fldr = DATA_DIR/'train'\ntst_fldr = DATA_DIR/'test'\n\nadc_info = pd.read_csv(DATA_DIR/'adc_info.csv')\naxis_info = pd.read_parquet(DATA_DIR/'axis_info.parquet', engine='pyarrow')\nsmp_sub = pd.read_csv(DATA_DIR/'sample_submission.csv')\ntst_str_info = pd.read_csv(DATA_DIR/'test_star_info.csv')\ntrn_csv = pd.read_csv(DATA_DIR/'train.csv')\ntrn_str_info = pd.read_csv(DATA_DIR/'train_star_info.csv')\nwaves = pd.read_csv(DATA_DIR/'wavelengths.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-18T06:44:05.898521Z","iopub.execute_input":"2025-07-18T06:44:05.898916Z","iopub.status.idle":"2025-07-18T06:44:06.561767Z","shell.execute_reply.started":"2025-07-18T06:44:05.898892Z","shell.execute_reply":"2025-07-18T06:44:06.560393Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Check the shapes and basic info of metadata files\nprint(\"=== ADC Info ===\")\nprint(f\"Shape: {adc_info.shape}\")\nprint(adc_info.head())\nprint(\"\\n=== Axis Info ===\")\nprint(f\"Shape: {axis_info.shape}\")\nprint(axis_info.head())\nprint(\"\\n=== Training CSV ===\")\nprint(f\"Shape: {trn_csv.shape}\")\nprint(trn_csv.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-18T06:44:09.575682Z","iopub.execute_input":"2025-07-18T06:44:09.576011Z","iopub.status.idle":"2025-07-18T06:44:09.601052Z","shell.execute_reply.started":"2025-07-18T06:44:09.575978Z","shell.execute_reply":"2025-07-18T06:44:09.599996Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Check wavelengths and star info\nprint(\"=== Wavelengths ===\")\nprint(f\"Shape: {waves.shape}\")\nprint(waves.head())\nprint(\"\\n=== Training Star Info ===\")\nprint(f\"Shape: {trn_str_info.shape}\")\nprint(trn_str_info.head())\nprint(\"\\n=== Test Star Info ===\")\nprint(f\"Shape: {tst_str_info.shape}\")\nprint(tst_str_info.head())\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-18T06:44:14.775381Z","iopub.execute_input":"2025-07-18T06:44:14.776068Z","iopub.status.idle":"2025-07-18T06:44:14.795899Z","shell.execute_reply.started":"2025-07-18T06:44:14.775896Z","shell.execute_reply":"2025-07-18T06:44:14.794816Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Get list of planet IDs in training data\ntrain_planets = [p.name for p in trn_fldr.iterdir() if p.is_dir()]\ntest_planets = [p.name for p in tst_fldr.iterdir() if p.is_dir()]\n\nprint(f\"Number of training planets: {len(train_planets)}\")\nprint(f\"Number of test planets: {len(test_planets)}\")\nprint(f\"First 5 training planets: {train_planets[:5]}\")\nprint(f\"First 5 test planets: {test_planets[:5]}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-18T06:44:33.143724Z","iopub.execute_input":"2025-07-18T06:44:33.144061Z","iopub.status.idle":"2025-07-18T06:44:34.118132Z","shell.execute_reply.started":"2025-07-18T06:44:33.144034Z","shell.execute_reply":"2025-07-18T06:44:34.117213Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Check what files exist for the first training planet\nfirst_planet = train_planets[0]\nplanet_path = trn_fldr / first_planet\nprint(f\"Files for planet {first_planet}:\")\nfor item in sorted(planet_path.iterdir()):\n    print(f\"  {item.name}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-18T06:44:57.989953Z","iopub.execute_input":"2025-07-18T06:44:57.990288Z","iopub.status.idle":"2025-07-18T06:44:57.999046Z","shell.execute_reply.started":"2025-07-18T06:44:57.990256Z","shell.execute_reply":"2025-07-18T06:44:57.998168Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Load signal files for the first training planet\nplanet_id = train_planets[0]\nplanet_path = trn_fldr / planet_id\n\n# Load AIRS-CH0 signal\nairs_signal = pd.read_parquet(planet_path / 'AIRS-CH0_signal_0.parquet')\nprint(f\"AIRS-CH0 signal shape: {airs_signal.shape}\")\nprint(f\"AIRS-CH0 data type: {airs_signal.dtypes.iloc[0]}\")\nprint(f\"AIRS-CH0 value range: {airs_signal.iloc[0].min()} to {airs_signal.iloc[0].max()}\")\n\n# Load FGS1 signal\nfgs1_signal = pd.read_parquet(planet_path / 'FGS1_signal_0.parquet')\nprint(f\"FGS1 signal shape: {fgs1_signal.shape}\")\nprint(f\"FGS1 data type: {fgs1_signal.dtypes.iloc[0]}\")\nprint(f\"FGS1 value range: {fgs1_signal.iloc[0].min()} to {fgs1_signal.iloc[0].max()}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-18T06:45:17.362081Z","iopub.execute_input":"2025-07-18T06:45:17.362416Z","iopub.status.idle":"2025-07-18T06:45:21.103391Z","shell.execute_reply.started":"2025-07-18T06:45:17.362392Z","shell.execute_reply":"2025-07-18T06:45:21.102406Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Fixed ADC correction and reshape functions\ndef correct_and_reshape_airs(signal_data, adc_info):\n    # Get gain and offset for AIRS-CH0\n    gain = adc_info['AIRS-CH0_adc_gain'].iloc[0]\n    offset = adc_info['AIRS-CH0_adc_offset'].iloc[0]\n    \n    # Apply correction: divide by gain, add offset, convert to float64\n    corrected = (signal_data.values / gain + offset).astype(np.float64)\n    \n    # Reshape from flattened (11250, 11392) to (11250, 32, 356)\n    reshaped = corrected.reshape(11250, 32, 356)\n    \n    return reshaped\n\ndef correct_and_reshape_fgs1(signal_data, adc_info):\n    # Get gain and offset for FGS1\n    gain = adc_info['FGS1_adc_gain'].iloc[0]\n    offset = adc_info['FGS1_adc_offset'].iloc[0]\n    \n    # Apply correction: divide by gain, add offset, convert to float64\n    corrected = (signal_data.values / gain + offset).astype(np.float64)\n    \n    # Reshape from flattened (135000, 1024) to (135000, 32, 32)\n    reshaped = corrected.reshape(135000, 32, 32)\n    \n    return reshaped\n\n# Apply corrections\nairs_corrected = correct_and_reshape_airs(airs_signal, adc_info)\nfgs1_corrected = correct_and_reshape_fgs1(fgs1_signal, adc_info)\n\nprint(f\"AIRS-CH0 corrected shape: {airs_corrected.shape}\")\nprint(f\"FGS1 corrected shape: {fgs1_corrected.shape}\")\nprint(f\"AIRS-CH0 corrected range: {airs_corrected.min():.2f} to {airs_corrected.max():.2f}\")\nprint(f\"FGS1 corrected range: {fgs1_corrected.min():.2f} to {fgs1_corrected.max():.2f}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-18T06:48:20.438056Z","iopub.execute_input":"2025-07-18T06:48:20.438771Z","iopub.status.idle":"2025-07-18T06:48:23.212469Z","shell.execute_reply.started":"2025-07-18T06:48:20.438735Z","shell.execute_reply":"2025-07-18T06:48:23.211547Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Let's see the effect of ADC correction\nprint(\"=== ADC Correction Effect ===\")\nprint(f\"AIRS-CH0 gain: {adc_info['AIRS-CH0_adc_gain'].iloc[0]}\")\nprint(f\"AIRS-CH0 offset: {adc_info['AIRS-CH0_adc_offset'].iloc[0]}\")\nprint(f\"FGS1 gain: {adc_info['FGS1_adc_gain'].iloc[0]}\")\nprint(f\"FGS1 offset: {adc_info['FGS1_adc_offset'].iloc[0]}\")\n\n# Example transformation for a few values\nsample_raw = np.array([1000, 2000, 3000, 4000, 5000])\nsample_corrected = (sample_raw / 0.4369 + (-1000)).astype(np.float64)\nprint(f\"\\nSample raw values: {sample_raw}\")\nprint(f\"Sample corrected values: {sample_corrected}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-18T06:49:10.082652Z","iopub.execute_input":"2025-07-18T06:49:10.082933Z","iopub.status.idle":"2025-07-18T06:49:10.090687Z","shell.execute_reply.started":"2025-07-18T06:49:10.082913Z","shell.execute_reply":"2025-07-18T06:49:10.089575Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# Create a figure with subplots\nfig, axes = plt.subplots(2, 3, figsize=(15, 10))\n\n# Plot time series for AIRS-CH0 (sum over spatial dimensions)\nairs_time_series = airs_corrected.sum(axis=(1, 2))\naxes[0, 0].plot(airs_time_series)\naxes[0, 0].set_title('AIRS-CH0 Time Series (Total Flux)')\naxes[0, 0].set_xlabel('Time Step')\naxes[0, 0].set_ylabel('Total Flux')\n\n# Plot time series for FGS1 (sum over spatial dimensions)\nfgs1_time_series = fgs1_corrected.sum(axis=(1, 2))\naxes[1, 0].plot(fgs1_time_series)\naxes[1, 0].set_title('FGS1 Time Series (Total Flux)')\naxes[1, 0].set_xlabel('Time Step')\naxes[1, 0].set_ylabel('Total Flux')\n\n# Show a sample frame from AIRS-CH0\nim1 = axes[0, 1].imshow(airs_corrected[0], aspect='auto')\naxes[0, 1].set_title('AIRS-CH0 Frame 0')\nplt.colorbar(im1, ax=axes[0, 1])\n\n# Show a sample frame from FGS1\nim2 = axes[1, 1].imshow(fgs1_corrected[0])\naxes[1, 1].set_title('FGS1 Frame 0')\nplt.colorbar(im2, ax=axes[1, 1])\n\n# Show mean frame from AIRS-CH0\nim3 = axes[0, 2].imshow(airs_corrected.mean(axis=0), aspect='auto')\naxes[0, 2].set_title('AIRS-CH0 Mean Frame')\nplt.colorbar(im3, ax=axes[0, 2])\n\n# Show mean frame from FGS1\nim4 = axes[1, 2].imshow(fgs1_corrected.mean(axis=0))\naxes[1, 2].set_title('FGS1 Mean Frame')\nplt.colorbar(im4, ax=axes[1, 2])\n\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-18T07:24:48.071241Z","iopub.execute_input":"2025-07-18T07:24:48.071597Z","iopub.status.idle":"2025-07-18T07:24:56.09034Z","shell.execute_reply.started":"2025-07-18T07:24:48.071574Z","shell.execute_reply":"2025-07-18T07:24:56.089248Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}