{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":39763,"databundleVersionId":11756775,"sourceType":"competition"}],"dockerImageVersionId":31012,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# データ読み込み箇所","metadata":{}},{"cell_type":"code","source":"import os\nimport sys\nimport json\nimport glob\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly.express as px\nimport torch\nimport pandas as pd\nfrom torchvision.transforms import Compose\nimport torch.nn as nn\nfrom pathlib import Path\nfrom tqdm.auto import tqdm\nfrom torch.utils.data import Dataset, DataLoader\nfrom typing import List\nimport logging\nimport csv\nimport torch.nn.functional as F\nimport csv\n\n# Configure logging\nlogging.basicConfig(format='[%(levelname)s] %(message)s', level=logging.INFO)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:41:17.783872Z","iopub.execute_input":"2025-05-08T08:41:17.784267Z","iopub.status.idle":"2025-05-08T08:41:28.449696Z","shell.execute_reply.started":"2025-05-08T08:41:17.784237Z","shell.execute_reply":"2025-05-08T08:41:28.448924Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import statistics\nimport math","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:41:28.450856Z","iopub.execute_input":"2025-05-08T08:41:28.451355Z","iopub.status.idle":"2025-05-08T08:41:28.457004Z","shell.execute_reply.started":"2025-05-08T08:41:28.451323Z","shell.execute_reply":"2025-05-08T08:41:28.456386Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Root Paths\nBASE_DIR = '/kaggle/input/waveform-inversion'\nTRAIN_DIR = os.path.join(BASE_DIR, 'train_samples')\nTEST_DIR = os.path.join(BASE_DIR, 'test')\n\nprint(\"Train Folders:\", os.listdir(TRAIN_DIR))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:41:28.457808Z","iopub.execute_input":"2025-05-08T08:41:28.458084Z","iopub.status.idle":"2025-05-08T08:41:28.481590Z","shell.execute_reply.started":"2025-05-08T08:41:28.458065Z","shell.execute_reply":"2025-05-08T08:41:28.480707Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def load_dataset_config(config_path, dataset_name):\n    \"\"\"Loads normalization parameters from dataset_config.json.\"\"\"\n    try:\n        with open(config_path) as f:\n            ctx = json.load(f)[dataset_name]\n        print(f\"Loaded config for dataset: {dataset_name}\")\n        return ctx\n    except FileNotFoundError:\n        print(f\"Error: {config_path} not found.\")\n        sys.exit(1)\n    except KeyError:\n        print(f\"Error: Dataset '{dataset_name}' not found in {config_path}.\")\n        sys.exit(1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:41:28.483405Z","iopub.execute_input":"2025-05-08T08:41:28.483649Z","iopub.status.idle":"2025-05-08T08:41:28.499273Z","shell.execute_reply.started":"2025-05-08T08:41:28.483630Z","shell.execute_reply":"2025-05-08T08:41:28.498474Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def get_transforms(ctx, k):\n    \"\"\"Gets the transformations for data and label based on test.py.\"\"\"\n    log_data_min = T.log_transform(ctx['data_min'], k=k)\n    log_data_max = T.log_transform(ctx['data_max'], k=k)\n    transform_data = Compose([\n        T.LogTransform(k=k),\n        T.MinMaxNormalize(log_data_min, log_data_max),\n    ])\n\n    return transform_data\n    \n# ================================================================\n# Flexible Exploration for Any Family\n# Auto-Skip empty folders\n# ================================================================","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:41:28.500216Z","iopub.execute_input":"2025-05-08T08:41:28.500479Z","iopub.status.idle":"2025-05-08T08:41:28.516988Z","shell.execute_reply.started":"2025-05-08T08:41:28.500458Z","shell.execute_reply":"2025-05-08T08:41:28.516162Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def explore_family(folder_name):\n    folder_path = os.path.join(TRAIN_DIR, folder_name)\n    print(f\"\\nExploring {folder_name} Dataset\")\n    print(\"Available Files:\", os.listdir(folder_path))\n\n    seis_files = sorted([f for f in os.listdir(folder_path) if f.startswith('seis')])\n    vel_files = sorted([f for f in os.listdir(folder_path) if f.startswith('vel')])\n\n    print(f\"Found {len(seis_files)} Seismic files\")\n    print(f\"Found {len(vel_files)} Velocity files\")\n\n    # Check before loading\n    if seis_files and vel_files:\n        example_seis = load_npy(os.path.join(folder_path, seis_files[0]))\n        example_vel = load_npy(os.path.join(folder_path, vel_files[0]))\n        example_vel = np.squeeze(example_vel)\n\n        print(\"Seismic Shape:\", example_seis.shape)\n        print(\"Velocity Shape:\", example_vel.shape)\n    else:\n        print(\"Skipping... No seismic or velocity files found.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:41:28.517647Z","iopub.execute_input":"2025-05-08T08:41:28.517948Z","iopub.status.idle":"2025-05-08T08:41:28.537482Z","shell.execute_reply.started":"2025-05-08T08:41:28.517919Z","shell.execute_reply":"2025-05-08T08:41:28.536576Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def load_npy(file_path):\n    return np.load(file_path)\n    \n# =============================================================================\n# 1. Data Preparation\n# =============================================================================\ndef collect_input_files(data_dir: str) -> list:\n    \"\"\"\n    Recursively search for .npy files in data_dir that contain 'seis' or 'data' in their filename.\n    \"\"\"\n    return [f for f in Path(data_dir).rglob(\"*.npy\") if (\"seis\" in f.stem) or (\"data\" in f.stem)]\n\ndef map_input_to_output(input_files: list) -> list:\n    \"\"\"\n    Map each input file to its corresponding output file by replacing keywords.\n    \"\"\"\n    return [Path(str(f).replace(\"seis\", \"vel\").replace(\"data\", \"model\")) for f in input_files]\n\n# Define training sample directory\nTRAIN_DIR = \"/kaggle/input/waveform-inversion/train_samples\"\ninputs_all = collect_input_files(TRAIN_DIR)\noutputs_all = map_input_to_output(inputs_all)\n\n# Check all output files exist\nassert all(f.exists() for f in outputs_all)\n\n# Split dataset into training and validation based on sampling frequency\ntrain_inputs = [inputs_all[i] for i in range(0, len(inputs_all), 2)]\nvalid_inputs = [f for f in inputs_all if f not in train_inputs]\ntrain_outputs = map_input_to_output(train_inputs)\nvalid_outputs = map_input_to_output(valid_inputs)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:41:28.538505Z","iopub.execute_input":"2025-05-08T08:41:28.538818Z","iopub.status.idle":"2025-05-08T08:41:28.625972Z","shell.execute_reply.started":"2025-05-08T08:41:28.538790Z","shell.execute_reply":"2025-05-08T08:41:28.625122Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# =============================================================================\n# 2. Dataset Definition\n# =============================================================================\nclass SeismicDataset(Dataset):\n    \"\"\"\n    Dataset handling seismic files with multiple examples per file.\n    \"\"\"\n    def __init__(self, in_files: list, out_files: list, examples_per_file: int = 500):\n        assert len(in_files) == len(out_files)\n        self.in_files = in_files\n        self.out_files = out_files\n        self.examples_per_file = examples_per_file\n\n    def __len__(self):\n        return len(self.in_files) * self.examples_per_file\n\n    def __getitem__(self, idx: int):\n        file_index = idx // self.examples_per_file\n        sample_index = idx % self.examples_per_file\n\n        # Memory map the file to reduce memory usage\n        x_data = np.load(self.in_files[file_index], mmap_mode=\"r\")\n        y_data = np.load(self.out_files[file_index], mmap_mode=\"r\")\n        try:\n            return x_data[sample_index].copy(), y_data[sample_index].copy()\n        finally:\n            del x_data, y_data\n\n# Create DataLoaders for training and validation\ntrain_dataset = SeismicDataset(train_inputs, train_outputs, examples_per_file=500)\nvalid_dataset = SeismicDataset(valid_inputs, valid_outputs, examples_per_file=500)\n\ntrain_loader = DataLoader(\n    train_dataset, batch_size=64, shuffle=True, pin_memory=True,\n    drop_last=True, num_workers=4, persistent_workers=True\n)\nvalid_loader = DataLoader(\n    valid_dataset, batch_size=64, shuffle=False, pin_memory=True,\n    drop_last=False, num_workers=4, persistent_workers=True\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:41:34.658418Z","iopub.execute_input":"2025-05-08T08:41:34.658721Z","iopub.status.idle":"2025-05-08T08:41:34.668640Z","shell.execute_reply.started":"2025-05-08T08:41:34.658701Z","shell.execute_reply":"2025-05-08T08:41:34.667442Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# =============================================================================\n# 3. Model Architecture: SmartConvNet\n# =============================================================================\nclass SmartConvNet(nn.Module):\n    \"\"\"A convolutional network with adaptive pooling and dense layers.\"\"\"\n    def __init__(self, input_channels: int = 5, output_size: int = 70 * 70):\n        super().__init__()\n        # Convolutional feature extractor\n        self.feature_extractor = nn.Sequential(\n            nn.Conv2d(input_channels, 16, kernel_size=3, stride=2, padding=1),  # spatial reduction\n            nn.BatchNorm2d(16),\n            nn.ReLU(),\n            nn.Conv2d(16, 32, kernel_size=3, stride=2, padding=1),  # further reduction\n            nn.BatchNorm2d(32),\n            nn.ReLU(),\n            nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1),\n            nn.BatchNorm2d(64),\n            nn.ReLU(),\n        )\n        # Pool output to a fixed size\n        self.pool = nn.AdaptiveAvgPool2d((7, 7))\n        # Fully connected head\n        self.fc = nn.Sequential(\n            nn.Linear(64 * 7 * 7, 512),\n            nn.ReLU(),\n            nn.Dropout(0.3),\n            nn.Linear(512, output_size),\n        )\n\n    def forward(self, x):\n        batch_size = x.shape[0]\n        feat = self.feature_extractor(x)\n        pooled = self.pool(feat)\n        flat = pooled.view(batch_size, -1)\n        out = self.fc(flat)\n        # Reshape output to (batch_size, 1, 70, 70) and apply scaling and bias\n        return out.view(batch_size, 1, 70, 70) * 1000 + 1500","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:41:35.106402Z","iopub.execute_input":"2025-05-08T08:41:35.106756Z","iopub.status.idle":"2025-05-08T08:41:35.115456Z","shell.execute_reply.started":"2025-05-08T08:41:35.106720Z","shell.execute_reply":"2025-05-08T08:41:35.114377Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"curve_fault_a_path = os.path.join(TRAIN_DIR, 'CurveFault_A')\nprint(\"Files in CurveFault_A:\", os.listdir(curve_fault_a_path))\nseis_file = os.path.join(curve_fault_a_path, 'seis2_1_0.npy')\nvel_file = os.path.join(curve_fault_a_path, 'vel2_1_0.npy')\n\nseis = load_npy(seis_file)\nvel = load_npy(vel_file)\n\nprint(\"Seismic Data shape:\", seis.shape)  \nprint(\"Velocity Data shape:\", vel.shape)\n\n## np.squeezeはサイズが1の次元をすべて削除\nvel = np.squeeze(vel)  \n\nprint(\"Velocity Shape after squeeze:\", vel.shape)\n\nsample_id = 0","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:41:46.607804Z","iopub.execute_input":"2025-05-08T08:41:46.608224Z","iopub.status.idle":"2025-05-08T08:41:46.974799Z","shell.execute_reply.started":"2025-05-08T08:41:46.608199Z","shell.execute_reply":"2025-05-08T08:41:46.973795Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Seisデータ","metadata":{}},{"cell_type":"code","source":"# seisは震源ごとにデータを分ける\nreceiver_box_data = []  # 5個分のデータを格納\n\nfor i in range(5):\n    # 各Receiverのデータ: shape = (500, 1000, 70)\n    receiver_i = seis[:, i, :, :]\n    # flatten: shape = (500*1000*70,)\n    receiver_i_flat = receiver_i.reshape(-1)\n    receiver_box_data.append(receiver_i_flat)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:41:49.001025Z","iopub.execute_input":"2025-05-08T08:41:49.001385Z","iopub.status.idle":"2025-05-08T08:41:49.221670Z","shell.execute_reply.started":"2025-05-08T08:41:49.001364Z","shell.execute_reply":"2025-05-08T08:41:49.220677Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 震源別のデータ(振幅)\nfor i, data in enumerate(receiver_box_data):\n    print(f\"震源{i}\")\n    print(\"最大値：\", max(data))\n    print(\"最小値：\", min(data))\n    print(\"中央値：\", statistics.median(data))\n    print(\"最頻値：\", statistics.mode(data))\n    print(\"分散：\", statistics.pvariance(data))\n    print(\"\\n\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:41:49.417640Z","iopub.execute_input":"2025-05-08T08:41:49.418360Z","iopub.status.idle":"2025-05-08T08:51:19.112102Z","shell.execute_reply.started":"2025-05-08T08:41:49.418334Z","shell.execute_reply":"2025-05-08T08:51:19.111206Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 箱ひげ図の描画\nplt.figure(figsize=(10, 6))\nplt.boxplot(receiver_box_data, showfliers=False)\nplt.title(\"Seismic Data Distribution by Source\")\nplt.xlabel(\"Source Index (0 to 4)\")\nplt.ylabel(\"Amplitude\")\nplt.grid(True)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:51:19.113721Z","iopub.execute_input":"2025-05-08T08:51:19.114060Z","iopub.status.idle":"2025-05-08T08:51:24.817527Z","shell.execute_reply.started":"2025-05-08T08:51:19.114034Z","shell.execute_reply":"2025-05-08T08:51:24.816639Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 箱ひげ図の描画 外れ値描写あり\nplt.figure(figsize=(10, 6))\nplt.boxplot(receiver_box_data, showfliers=True)\nplt.title(\"Seismic Data Distribution by Source\")\nplt.xlabel(\"Source Index (0 to 4)\")\nplt.ylabel(\"Amplitude\")\nplt.grid(True)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:51:24.818491Z","iopub.execute_input":"2025-05-08T08:51:24.819346Z","iopub.status.idle":"2025-05-08T08:52:35.590432Z","shell.execute_reply.started":"2025-05-08T08:51:24.819317Z","shell.execute_reply":"2025-05-08T08:52:35.589601Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# データを(震源, 受信機)の組み合わせで分ける\nseismic_by_source_receiver = {}\n\nfor s in range(5):          # 震源\n    for r in range(70):     # レシーバー\n        # shape: (500, 1000) を取得\n        data_sr = seis[:, s, :, r]\n        # flatten: (500 * 1000,)\n        data_sr_flat = data_sr.reshape(-1)\n        seismic_by_source_receiver[(s, r)] = data_sr_flat","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:52:35.591828Z","iopub.execute_input":"2025-05-08T08:52:35.592094Z","iopub.status.idle":"2025-05-08T08:52:37.716397Z","shell.execute_reply.started":"2025-05-08T08:52:35.592075Z","shell.execute_reply":"2025-05-08T08:52:37.715565Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 箱ひげ図にするために、受信機を10個ずつまとめる\ngrouped_data = []\nfor i in range(0, 70, 10):\n    group = seis[:, 0, :, i:i+10].reshape(-1)\n    grouped_data.append(group)\n\nplt.boxplot(grouped_data, showfliers=True)\nplt.title(\"Receiver Groups (10 each) for Source 0\")\nplt.xlabel(\"Group Index\")\nplt.ylabel(\"Amplitude\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T08:52:37.717215Z","iopub.execute_input":"2025-05-08T08:52:37.717428Z","iopub.status.idle":"2025-05-08T08:52:52.304472Z","shell.execute_reply.started":"2025-05-08T08:52:37.717411Z","shell.execute_reply":"2025-05-08T08:52:52.303597Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## 受信のヒストグラム","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\n\n# ヒストグラムを描画（重ねる or 並べる）\nplt.figure(figsize=(12, 6))\n\nfor idx, group in enumerate(grouped_data):\n    plt.hist(group, bins=100, alpha=0.5, label=f\"Group {idx}\")\n\nplt.title(\"Amplitude Histogram, Grouped by Receiver 10s\")\nplt.xlabel(\"Amplitude\")\nplt.ylabel(\"Frequency\")\nplt.legend()\nplt.grid(True)\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T09:34:54.211382Z","iopub.execute_input":"2025-05-08T09:34:54.211737Z","iopub.status.idle":"2025-05-08T09:34:56.055193Z","shell.execute_reply.started":"2025-05-08T09:34:54.211717Z","shell.execute_reply":"2025-05-08T09:34:56.054364Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\n\n# grouped_data を再作成（±1を除く）\ngrouped_data = []\nfor i in range(0, 70, 10):\n    group = seis[:, 0, :, i:i+10].reshape(-1)\n    # ±1の範囲を除外\n    group_filtered = group[(group < -1) | (group > 1)]\n    grouped_data.append(group_filtered)\n\n# ヒストグラムを描画（重ねる or 並べる）\nplt.figure(figsize=(12, 6))\n\nfor idx, group in enumerate(grouped_data):\n    plt.hist(group, bins=100, alpha=0.5, label=f\"Group {idx}\")\n\nplt.title(\"Amplitude Histogram (|x| > 1), Grouped by Receiver 10s\")\nplt.xlabel(\"Amplitude\")\nplt.ylabel(\"Frequency\")\nplt.legend()\nplt.grid(True)\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T09:34:56.056477Z","iopub.execute_input":"2025-05-08T09:34:56.056692Z","iopub.status.idle":"2025-05-08T09:34:57.834312Z","shell.execute_reply.started":"2025-05-08T09:34:56.056676Z","shell.execute_reply":"2025-05-08T09:34:57.833246Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\nimport matplotlib.pyplot as plt\n\n# seismic_data.shape = (500, 5, 1000, 70)\n\n# 各レシーバーの平均波形（震源0）\nwaveforms = np.mean(seis[:, 0, :, :], axis=0)  # shape: (1000, 70)\n\nplt.figure(figsize=(12, 6))\nplt.imshow(waveforms.T, aspect='auto', cmap='seismic', extent=[0, 1000, 69, 0])\nplt.colorbar(label=\"Amplitude\")\nplt.xlabel(\"Time Step\")\nplt.ylabel(\"Receiver Index\")\nplt.title(\"Wave Propagation (Source 0)\")\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T09:35:01.461325Z","iopub.execute_input":"2025-05-08T09:35:01.461626Z","iopub.status.idle":"2025-05-08T09:35:01.815426Z","shell.execute_reply.started":"2025-05-08T09:35:01.461605Z","shell.execute_reply":"2025-05-08T09:35:01.814237Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"arrival_times = []\n\nfor r in range(70):\n    signal = np.mean(seis[:, 0, :, r], axis=0)  # shape: (1000,)\n    arrival_time = np.argmax(np.abs(signal))  # 最も強い振幅の時間を到達時間と仮定\n    arrival_times.append(arrival_time)\n\nplt.plot(range(70), arrival_times, marker='o')\nplt.xlabel(\"Receiver Index\")\nplt.ylabel(\"Estimated Arrival Time (Time Step)\")\nplt.title(\"Estimated Wave Arrival Times (Source 0)\")\nplt.grid(True)\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T09:35:05.375044Z","iopub.execute_input":"2025-05-08T09:35:05.375434Z","iopub.status.idle":"2025-05-08T09:35:06.077866Z","shell.execute_reply.started":"2025-05-08T09:35:05.375410Z","shell.execute_reply":"2025-05-08T09:35:06.076832Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"mean_arrival_times = []\nstd_arrival_times = []\n\nfor r in range(70):\n    arrival_times = []\n    for s in range(500):\n        signal = seis[s, 0, :, r]  # shape: (1000,)\n        t = np.argmax(np.abs(signal))     # 各サンプルの到達時刻\n        arrival_times.append(t)\n    mean_arrival_times.append(np.mean(arrival_times))\n    std_arrival_times.append(np.std(arrival_times))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T09:35:37.828684Z","iopub.execute_input":"2025-05-08T09:35:37.829454Z","iopub.status.idle":"2025-05-08T09:35:38.322191Z","shell.execute_reply.started":"2025-05-08T09:35:37.829430Z","shell.execute_reply":"2025-05-08T09:35:38.320967Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nplt.figure(figsize=(12, 5))\nplt.errorbar(\n    range(70),\n    mean_arrival_times,\n    yerr=std_arrival_times,\n    fmt='o',\n    capsize=3,\n    label='Arrival Time (mean ± std)'\n)\nplt.xlabel(\"Receiver Index\")\nplt.ylabel(\"Estimated Arrival Time (Time Step)\")\nplt.title(\"Wave Arrival Time per Receiver (Source 0)\")\nplt.grid(True)\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T09:35:39.151851Z","iopub.execute_input":"2025-05-08T09:35:39.152722Z","iopub.status.idle":"2025-05-08T09:35:39.390750Z","shell.execute_reply.started":"2025-05-08T09:35:39.152698Z","shell.execute_reply":"2025-05-08T09:35:39.389744Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## velデータ","metadata":{}},{"cell_type":"code","source":"# velは1次元にする\n# フラット化後のshape (500*70*70,)\nflat_vel = vel.reshape(-1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T09:35:44.179876Z","iopub.execute_input":"2025-05-08T09:35:44.180266Z","iopub.status.idle":"2025-05-08T09:35:44.185113Z","shell.execute_reply.started":"2025-05-08T09:35:44.180242Z","shell.execute_reply":"2025-05-08T09:35:44.184181Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"最大値：\", max(flat_vel))\nprint(\"最小値：\", min(flat_vel))\nprint(\"中央値：\", statistics.median(flat_vel))\nprint(\"最頻値：\", statistics.mode(flat_vel))\nprint(\"分散：\", statistics.pvariance(flat_vel))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T09:35:44.530044Z","iopub.execute_input":"2025-05-08T09:35:44.530522Z","iopub.status.idle":"2025-05-08T09:35:47.349633Z","shell.execute_reply.started":"2025-05-08T09:35:44.530498Z","shell.execute_reply":"2025-05-08T09:35:47.348876Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 箱ひげ図の描写 外れ値あり\nplt.boxplot(flat_vel, showfliers=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T09:35:47.350698Z","iopub.execute_input":"2025-05-08T09:35:47.350987Z","iopub.status.idle":"2025-05-08T09:35:47.527107Z","shell.execute_reply.started":"2025-05-08T09:35:47.350967Z","shell.execute_reply":"2025-05-08T09:35:47.526302Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(10, 6))\nplt.title(f\"Seismic Data - Batch 0, Source 0\")\nplt.imshow(seis[0, 0], aspect='auto', cmap='seismic')\nplt.colorbar(label=\"Amplitude\")\nplt.xlabel(\"Receivers\")\nplt.ylabel(\"Timesteps\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T09:35:47.527975Z","iopub.execute_input":"2025-05-08T09:35:47.528307Z","iopub.status.idle":"2025-05-08T09:35:47.861331Z","shell.execute_reply.started":"2025-05-08T09:35:47.528286Z","shell.execute_reply":"2025-05-08T09:35:47.860456Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ヒストグラムを描画（重ねる or 並べる）\nplt.figure(figsize=(12, 6))\n\n\nplt.hist(flat_vel, bins=100, alpha=0.5)\n\nplt.title(\"Velocity Histgram\")\nplt.xlabel(\"Velocity\")\nplt.ylabel(\"Frequency\")\nplt.legend()\nplt.grid(True)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T09:35:51.334341Z","iopub.execute_input":"2025-05-08T09:35:51.335240Z","iopub.status.idle":"2025-05-08T09:35:51.723341Z","shell.execute_reply.started":"2025-05-08T09:35:51.335216Z","shell.execute_reply":"2025-05-08T09:35:51.722292Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_id = 1\nplt.figure(figsize=(8, 6))\nplt.title(f\"Velocity Map (Ground Truth) - Sample {sample_id}\")\nsns.heatmap(vel[sample_id], cmap='viridis')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T09:35:52.870640Z","iopub.execute_input":"2025-05-08T09:35:52.871017Z","iopub.status.idle":"2025-05-08T09:35:53.312005Z","shell.execute_reply.started":"2025-05-08T09:35:52.870994Z","shell.execute_reply":"2025-05-08T09:35:53.311039Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_id = 2\nplt.figure(figsize=(8, 6))\nplt.title(f\"Velocity Map (Ground Truth) - Sample {sample_id}\")\nsns.heatmap(vel[sample_id], cmap='viridis')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-08T09:35:53.313256Z","iopub.execute_input":"2025-05-08T09:35:53.313554Z","iopub.status.idle":"2025-05-08T09:35:53.749295Z","shell.execute_reply.started":"2025-05-08T09:35:53.313534Z","shell.execute_reply":"2025-05-08T09:35:53.748519Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}