{ "cells": [ { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "train files: [['1987.h5', '1988.h5', '1989.h5', '1990.h5', '1991.h5', '1992.h5', '1993.h5', '1994.h5', '1995.h5', '1996.h5', '1997.h5', '1998.h5', '1999.h5', '2000.h5', '2001.h5', '2002.h5', '2003.h5', '2004.h5', '2005.h5', '2006.h5', '2007.h5', '2008.h5', '2009.h5', '2010.h5', '2011.h5', '2012.h5', '2013.h5', '2014.h5', '2015.h5', '2016.h5', '2017.h5', '2018.h5', '2019.h5', '2020.h5', '2021.h5', '2022.h5'], ['1999.h5', '2000.h5', '2001.h5', '2002.h5', '2003.h5', '2004.h5', '2005.h5', '2006.h5', '2007.h5', '2008.h5', '2009.h5', '2010.h5', '2011.h5', '2012.h5', '2013.h5', '2014.h5', '2015.h5', '2016.h5', '2017.h5', '2018.h5', '2019.h5', '2020.h5', '2021.h5', '2022.h5']]\n", "test files: [['2023.h5'], ['2023.h5']]\n" ] } ], "source": [ "# %%\n", "import os\n", "\n", "import h5py\n", "import matplotlib.pyplot as plt\n", "from tqdm import tqdm\n", "\n", "# %%\n", "h5_dirs = [\"NC/waveform_h5\", \"SC/waveform_h5\"]\n", "h5_out = \"waveform.h5\"\n", "h5_train = \"waveform_train.h5\"\n", "h5_test = \"waveform_test.h5\"\n", "\n", "# # %%\n", "# h5_dir = \"waveform_h5\"\n", "# h5_out = \"waveform.h5\"\n", "# h5_train = \"waveform_train.h5\"\n", "# h5_test = \"waveform_test.h5\"\n", "\n", "h5_file_lists = [sorted(os.listdir(h5_dir)) for h5_dir in h5_dirs]\n", "train_file_lists = [x[:-1] for x in h5_file_lists]\n", "test_file_lists = [x[-1:] for x in h5_file_lists]\n", "# train_files = h5_files\n", "# train_files = [x for x in train_files if (x != \"2014.h5\") and (x not in [])]\n", "# test_files = []\n", "print(f\"train files: {train_file_lists}\")\n", "print(f\"test files: {test_file_lists}\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "1987.h5: 100%|██████████| 21/21 [00:00<00:00, 13205.45it/s]\n", "1988.h5: 100%|██████████| 122/122 [00:00<00:00, 44093.50it/s]\n", "1989.h5: 100%|██████████| 145/145 [00:00<00:00, 48487.13it/s]\n", "1990.h5: 100%|██████████| 149/149 [00:00<00:00, 47098.60it/s]\n", "1991.h5: 100%|██████████| 161/161 [00:00<00:00, 42155.12it/s]\n", "1992.h5: 100%|██████████| 158/158 [00:00<00:00, 47980.02it/s]\n", "1993.h5: 100%|██████████| 1647/1647 [00:00<00:00, 49726.60it/s]\n", "1994.h5: 100%|██████████| 1625/1625 [00:00<00:00, 49557.51it/s]\n", "1995.h5: 100%|██████████| 4595/4595 [00:00<00:00, 48027.90it/s]\n", "1996.h5: 100%|██████████| 4287/4287 [00:00<00:00, 49844.30it/s]\n", "1997.h5: 100%|██████████| 6260/6260 [00:00<00:00, 57234.54it/s]\n", "1998.h5: 100%|██████████| 4568/4568 [00:00<00:00, 57102.95it/s]\n", "1999.h5: 100%|██████████| 6024/6024 [00:00<00:00, 57112.18it/s]\n", "2000.h5: 100%|██████████| 1105/1105 [00:00<00:00, 53676.60it/s]\n", "2001.h5: 100%|██████████| 2679/2679 [00:00<00:00, 63035.62it/s]\n", "2002.h5: 100%|██████████| 7506/7506 [00:00<00:00, 60202.90it/s]\n", "2003.h5: 100%|██████████| 8420/8420 [00:00<00:00, 47666.41it/s]\n", "2004.h5: 100%|██████████| 15232/15232 [00:00<00:00, 47821.13it/s]\n", "2005.h5: 100%|██████████| 8465/8465 [00:00<00:00, 52576.08it/s]\n", "2006.h5: 100%|██████████| 7269/7269 [00:00<00:00, 47932.45it/s]\n", "2007.h5: 100%|██████████| 12722/12722 [00:00<00:00, 52216.50it/s]\n", "2008.h5: 100%|██████████| 11822/11822 [00:00<00:00, 43993.57it/s]\n", "2009.h5: 100%|██████████| 11412/11412 [00:00<00:00, 42015.39it/s]\n", "2010.h5: 100%|██████████| 11973/11973 [00:00<00:00, 45174.53it/s]\n", "2011.h5: 100%|██████████| 13848/13848 [00:00<00:00, 47253.07it/s]\n", "2012.h5: 100%|██████████| 15738/15738 [00:00<00:00, 40880.02it/s]\n", "2013.h5: 100%|██████████| 16020/16020 [00:00<00:00, 38879.41it/s]\n", "2014.h5: 100%|██████████| 21804/21804 [00:00<00:00, 44580.12it/s]\n", "2015.h5: 100%|██████████| 14230/14230 [00:00<00:00, 41559.02it/s]\n", "2016.h5: 100%|██████████| 13977/13977 [00:00<00:00, 39143.14it/s]\n", "2017.h5: 100%|██████████| 18099/18099 [00:00<00:00, 38739.83it/s]\n", "2018.h5: 100%|██████████| 14036/14036 [00:00<00:00, 41671.15it/s]\n", "2019.h5: 100%|██████████| 15064/15064 [00:00<00:00, 43094.97it/s]\n", "2020.h5: 100%|██████████| 16155/16155 [00:00<00:00, 36563.74it/s]\n", "2021.h5: 100%|██████████| 15581/15581 [00:00<00:00, 38802.18it/s]\n", "2022.h5: 100%|██████████| 10898/10898 [00:00<00:00, 40756.44it/s]\n", "2023.h5: 100%|██████████| 11085/11085 [00:00<00:00, 39294.58it/s]\n", "1999.h5: 100%|██████████| 24/24 [00:00<00:00, 30849.92it/s]\n", "2000.h5: 100%|██████████| 27/27 [00:00<00:00, 26226.54it/s]\n", "2001.h5: 100%|██████████| 29/29 [00:00<00:00, 30715.86it/s]\n", "2002.h5: 100%|██████████| 34/34 [00:00<00:00, 34091.88it/s]\n", "2003.h5: 100%|██████████| 73/73 [00:00<00:00, 28934.44it/s]\n", "2004.h5: 100%|██████████| 740/740 [00:00<00:00, 33500.47it/s]\n", "2005.h5: 100%|██████████| 1249/1249 [00:00<00:00, 35171.48it/s]\n", "2006.h5: 100%|██████████| 657/657 [00:00<00:00, 34450.03it/s]\n", "2007.h5: 100%|██████████| 1743/1743 [00:00<00:00, 35092.29it/s]\n", "2008.h5: 100%|██████████| 12570/12570 [00:00<00:00, 35370.94it/s]\n", "2009.h5: 100%|██████████| 14282/14282 [00:00<00:00, 40763.96it/s]\n", "2010.h5: 100%|██████████| 34818/34818 [00:00<00:00, 40016.59it/s]\n", "2011.h5: 100%|██████████| 13427/13427 [00:00<00:00, 36651.35it/s]\n", "2012.h5: 100%|██████████| 15416/15416 [00:00<00:00, 38639.99it/s]\n", "2013.h5: 100%|██████████| 17056/17056 [00:00<00:00, 40840.94it/s]\n", "2014.h5: 100%|██████████| 13937/13937 [00:00<00:00, 39126.77it/s]\n", "2015.h5: 100%|██████████| 15311/15311 [00:00<00:00, 37447.81it/s]\n", "2016.h5: 100%|██████████| 15470/15470 [00:00<00:00, 36607.05it/s]\n", "2017.h5: 100%|██████████| 15771/15771 [00:00<00:00, 36313.59it/s]\n", "2018.h5: 100%|██████████| 20344/20344 [00:00<00:00, 35744.70it/s]\n", "2019.h5: 100%|██████████| 60424/60424 [00:01<00:00, 36248.55it/s]\n", "2020.h5: 100%|██████████| 33621/33621 [00:00<00:00, 36729.94it/s]\n", "2021.h5: 100%|██████████| 15206/15206 [00:00<00:00, 35751.59it/s]\n", "2022.h5: 100%|██████████| 12532/12532 [00:00<00:00, 34850.17it/s]\n", "2023.h5: 100%|██████████| 13410/13410 [00:00<00:00, 34365.93it/s]\n", "1987.h5: 100%|██████████| 21/21 [00:00<00:00, 42184.09it/s]\n", "1988.h5: 100%|██████████| 122/122 [00:00<00:00, 54774.68it/s]\n", "1989.h5: 100%|██████████| 145/145 [00:00<00:00, 53522.32it/s]\n", "1990.h5: 100%|██████████| 149/149 [00:00<00:00, 55506.82it/s]\n", "1991.h5: 100%|██████████| 161/161 [00:00<00:00, 51115.20it/s]\n", "1992.h5: 100%|██████████| 158/158 [00:00<00:00, 51384.05it/s]\n", "1993.h5: 100%|██████████| 1647/1647 [00:00<00:00, 54106.28it/s]\n", "1994.h5: 100%|██████████| 1625/1625 [00:00<00:00, 55482.02it/s]\n", "1995.h5: 100%|██████████| 4595/4595 [00:00<00:00, 58728.18it/s]\n", "1996.h5: 100%|██████████| 4287/4287 [00:00<00:00, 55312.14it/s]\n", "1997.h5: 100%|██████████| 6260/6260 [00:00<00:00, 52698.71it/s]\n", "1998.h5: 100%|██████████| 4568/4568 [00:00<00:00, 53222.39it/s]\n", "1999.h5: 100%|██████████| 6024/6024 [00:00<00:00, 52687.69it/s]\n", "2000.h5: 100%|██████████| 1105/1105 [00:00<00:00, 58423.12it/s]\n", "2001.h5: 100%|██████████| 2679/2679 [00:00<00:00, 57428.62it/s]\n", "2002.h5: 100%|██████████| 7506/7506 [00:00<00:00, 58583.76it/s]\n", "2003.h5: 100%|██████████| 8420/8420 [00:00<00:00, 54412.15it/s]\n", "2004.h5: 100%|██████████| 15232/15232 [00:00<00:00, 57007.87it/s]\n", "2005.h5: 100%|██████████| 8465/8465 [00:00<00:00, 54145.10it/s]\n", "2006.h5: 100%|██████████| 7269/7269 [00:00<00:00, 51191.79it/s]\n", "2007.h5: 100%|██████████| 12722/12722 [00:00<00:00, 47122.06it/s]\n", "2008.h5: 100%|██████████| 11822/11822 [00:00<00:00, 44205.48it/s]\n", "2009.h5: 100%|██████████| 11412/11412 [00:00<00:00, 43242.28it/s]\n", "2010.h5: 100%|██████████| 11973/11973 [00:00<00:00, 42805.26it/s]\n", "2011.h5: 100%|██████████| 13848/13848 [00:00<00:00, 42280.57it/s]\n", "2012.h5: 100%|██████████| 15738/15738 [00:00<00:00, 41685.79it/s]\n", "2013.h5: 100%|██████████| 16020/16020 [00:00<00:00, 43329.98it/s]\n", "2014.h5: 100%|██████████| 21804/21804 [00:00<00:00, 44983.11it/s]\n", "2015.h5: 100%|██████████| 14230/14230 [00:00<00:00, 44135.09it/s]\n", "2016.h5: 100%|██████████| 13977/13977 [00:00<00:00, 44137.57it/s]\n", "2017.h5: 100%|██████████| 18099/18099 [00:00<00:00, 42492.87it/s]\n", "2018.h5: 100%|██████████| 14036/14036 [00:00<00:00, 39025.89it/s]\n", "2019.h5: 100%|██████████| 15064/15064 [00:00<00:00, 38635.81it/s]\n", "2020.h5: 100%|██████████| 16155/16155 [00:00<00:00, 38816.08it/s]\n", "2021.h5: 100%|██████████| 15581/15581 [00:00<00:00, 39043.39it/s]\n", "2022.h5: 100%|██████████| 10898/10898 [00:00<00:00, 39888.76it/s]\n", "1999.h5: 100%|██████████| 24/24 [00:00<00:00, 34532.86it/s]\n", "2000.h5: 100%|██████████| 27/27 [00:00<00:00, 26690.13it/s]\n", "2001.h5: 100%|██████████| 29/29 [00:00<00:00, 30700.36it/s]\n", "2002.h5: 100%|██████████| 34/34 [00:00<00:00, 35029.80it/s]\n", "2003.h5: 100%|██████████| 73/73 [00:00<00:00, 35970.89it/s]\n", "2004.h5: 100%|██████████| 740/740 [00:00<00:00, 36212.21it/s]\n", "2005.h5: 100%|██████████| 1249/1249 [00:00<00:00, 40190.00it/s]\n", "2006.h5: 100%|██████████| 657/657 [00:00<00:00, 38375.36it/s]\n", "2007.h5: 100%|██████████| 1743/1743 [00:00<00:00, 37327.53it/s]\n", "2008.h5: 100%|██████████| 12570/12570 [00:00<00:00, 41988.87it/s]\n", "2009.h5: 100%|██████████| 14282/14282 [00:00<00:00, 42669.64it/s]\n", "2010.h5: 100%|██████████| 34818/34818 [00:00<00:00, 42444.23it/s]\n", "2011.h5: 100%|██████████| 13427/13427 [00:00<00:00, 37659.90it/s]\n", "2012.h5: 100%|██████████| 15416/15416 [00:00<00:00, 37632.25it/s]\n", "2013.h5: 100%|██████████| 17056/17056 [00:00<00:00, 37530.78it/s]\n", "2014.h5: 100%|██████████| 13937/13937 [00:00<00:00, 37437.27it/s]\n", "2015.h5: 100%|██████████| 15311/15311 [00:00<00:00, 39536.43it/s]\n", "2016.h5: 100%|██████████| 15470/15470 [00:00<00:00, 38313.60it/s]\n", "2017.h5: 100%|██████████| 15771/15771 [00:00<00:00, 40890.63it/s]\n", "2018.h5: 100%|██████████| 20344/20344 [00:00<00:00, 38624.25it/s]\n", "2019.h5: 100%|██████████| 60424/60424 [00:01<00:00, 35660.70it/s]\n", "2020.h5: 100%|██████████| 33621/33621 [00:00<00:00, 36877.49it/s]\n", "2021.h5: 100%|██████████| 15206/15206 [00:00<00:00, 36150.85it/s]\n", "2022.h5: 100%|██████████| 12532/12532 [00:00<00:00, 37151.34it/s]\n", "2023.h5: 100%|██████████| 11085/11085 [00:00<00:00, 55073.48it/s]\n", "2023.h5: 100%|██████████| 13410/13410 [00:00<00:00, 55802.88it/s]\n" ] } ], "source": [ "# %%\n", "with h5py.File(h5_out, \"w\") as fp:\n", " # external linked file\n", " for h5_dir, h5_files in zip(h5_dirs, h5_file_lists):\n", " for h5_file in h5_files:\n", " with h5py.File(os.path.join(h5_dir, h5_file), \"r\") as f:\n", " for event in tqdm(f.keys(), desc=h5_file, total=len(f.keys())):\n", " if event not in fp:\n", " fp[event] = h5py.ExternalLink(os.path.join(h5_dir, h5_file), event)\n", " else:\n", " print(f\"{event} already exists\")\n", " continue\n", "\n", "# %%\n", "with h5py.File(h5_train, \"w\") as fp:\n", " # external linked file\n", " for h5_dir, h5_files in zip(h5_dirs, train_file_lists):\n", " for h5_file in h5_files:\n", " with h5py.File(os.path.join(h5_dir, h5_file), \"r\") as f:\n", " for event in tqdm(f.keys(), desc=h5_file, total=len(f.keys())):\n", " if event not in fp:\n", " fp[event] = h5py.ExternalLink(os.path.join(h5_dir, h5_file), event)\n", " else:\n", " print(f\"{event} already exists\")\n", " continue\n", "\n", "# %%\n", "with h5py.File(h5_test, \"w\") as fp:\n", " # external linked file\n", " for h5_dir, h5_files in zip(h5_dirs, test_file_lists):\n", " for h5_file in h5_files:\n", " with h5py.File(os.path.join(h5_dir, h5_file), \"r\") as f:\n", " for event in tqdm(f.keys(), desc=h5_file, total=len(f.keys())):\n", " if event not in fp:\n", " fp[event] = h5py.ExternalLink(os.path.join(h5_dir, h5_file), event)\n", " else:\n", " print(f\"{event} already exists\")\n", " continue\n", "\n", "# %%\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "import h5py" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "653073" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "h5_fp = h5py.File(\"waveform.h5\", \"r\")\n", "len(list(h5_fp.keys()))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_3422288/108058564.py:9: DtypeWarning: Columns (11) have mixed types. Specify dtype option on import or set low_memory=False.\n", " df = pd.read_csv(f\"{dir}/{csv_file}\")\n", "/tmp/ipykernel_3422288/108058564.py:9: DtypeWarning: Columns (11) have mixed types. Specify dtype option on import or set low_memory=False.\n", " df = pd.read_csv(f\"{dir}/{csv_file}\")\n", "/tmp/ipykernel_3422288/108058564.py:9: DtypeWarning: Columns (11) have mixed types. Specify dtype option on import or set low_memory=False.\n", " df = pd.read_csv(f\"{dir}/{csv_file}\")\n" ] } ], "source": [ "import pandas as pd\n", "\n", "dirs = [\"NC\", \"SC\"]\n", "csv_files = ['events.csv', 'events_test.csv', 'events_train.csv', 'picks.csv', 'picks_test.csv', 'picks_train.csv']\n", "\n", "for csv_file in csv_files:\n", " dfs = []\n", " for dir in dirs:\n", " df = pd.read_csv(f\"{dir}/{csv_file}\")\n", " dfs.append(df)\n", " df = pd.concat(dfs)\n", " df.to_csv(csv_file, index=False, na_rep='')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "scp wanghy@ai4earth.geo.berkeley.edu:/data/wanghy/events_test.csv ./\n", "scp wanghy@ai4earth.geo.berkeley.edu:/data/wanghy/picks.csv ./\n", "scp wanghy@ai4earth.geo.berkeley.edu:/data/wanghy/picks_train.csv ./\n", "scp wanghy@ai4earth.geo.berkeley.edu:/data/wanghy/picks_test.csv ./\n", "scp wanghy@ai4earth.geo.berkeley.edu:/data/wanghy/waveform.h5 ./\n", "scp wanghy@ai4earth.geo.berkeley.edu:/data/wanghy/waveform_test.h5 ./\n", "scp wanghy@ai4earth.geo.berkeley.edu:/data/wanghy/waveform_train.h5 ./" ] } ], "metadata": { "kernelspec": { "display_name": "obspy", "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.11.10" } }, "nbformat": 4, "nbformat_minor": 2 }