{ "cells": [ { "cell_type": "markdown", "id": "6e8c5c25-687b-4e45-8455-a759f27a2b1d", "metadata": {}, "source": [ "in the merged folder I copied all data from v3 into v2. This leads to the \"valid\" csv to only reflect v3. Need to merge this." ] }, { "cell_type": "code", "execution_count": 3, "id": "f776df0e-2529-46ec-be15-6c661d91b70c", "metadata": {}, "outputs": [], "source": [ "import glob\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 4, "id": "20a3ec31-2dec-4314-a682-5ecfe26a01a2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "v2/output_agg_upscaled/RGI01/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI02/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI03/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI04/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI05/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI06/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI07/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI08/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI09/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI10/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI11/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI12/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI13/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI14/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI15/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI16/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI17/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI18/hypercube_valid.csv\n", "v2/output_agg_upscaled/RGI19/hypercube_valid.csv\n" ] } ], "source": [ "# Pattern to match files, e.g., \"*.txt\" for all text files\n", "pattern = \"v2/output_agg_upscaled/**/hypercube_valid.csv\"\n", "\n", "# Find all files recursively\n", "files = sorted(glob.glob(pattern, recursive=True))\n", "\n", "# Print the matched files\n", "for file in files:\n", " print(file)" ] }, { "cell_type": "code", "execution_count": 27, "id": "3db480a0-b08d-464b-96e1-846b3fb79ad5", "metadata": {}, "outputs": [], "source": [ "for file in files:\n", " dfv2 = pd.read_csv(file, index_col=0)\n", " dfv3 = pd.read_csv(file.replace('v2', 'v3'), index_col=0)\n", " \n", " dfo = pd.concat([dfv2, dfv3[dfv3.columns[5:]]], axis=1)\n", " sorted_cols = list(dfo.columns[:5]) + sorted(dfo.columns[5:])\n", " dfo = dfo[sorted_cols]\n", " \n", " of = file.replace('v2', 'merged_v2v3')\n", " dfo.to_csv(of)" ] }, { "cell_type": "code", "execution_count": 10, "id": "0e7f0a0a-d65d-4a97-ad7d-74b58618db44", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['valid_IPSL-CM6A-LR_ssp534-over', 'valid_MRI-ESM2-0_ssp534-over',\n", " 'valid_CESM2-WACCM_ssp126', 'valid_CESM2-WACCM_ssp585',\n", " 'valid_CESM2-WACCM_ssp534-over'],\n", " dtype='object')" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "code", "execution_count": 8, "id": "174a94e9-8300-4727-a2a8-ea1d3306226c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
melt_ftemp_biasprcp_factemp_meltglen_avalid_IPSL-CM6A-LR_ssp126valid_IPSL-CM6A-LR_ssp585valid_MRI-ESM2-0_ssp126valid_MRI-ESM2-0_ssp585
exp
0NaNNaNNaNNaNNaN0.9778880.9780980.9779770.978098
10.422340-1.0065301.6920462.0010252.1290140.4717240.9438780.5327110.952051
2-0.2225162.3528210.844443-1.4131660.2767350.9780980.9780980.9780980.978098
30.445820-1.1651831.7273522.7093900.7748720.3776740.9411060.4160180.942735
40.690500-0.5575301.372393-1.7658971.3993880.9779480.9780610.9779850.978098
..............................
2961.3661631.0861761.229347-2.2997810.5469460.9780980.9780980.9780980.978098
297-0.520724-1.5249651.235378-1.4978551.4307200.9649770.9776890.9761240.977699
298-1.580318-1.2054720.962362-0.9007690.2140410.9714590.9764500.9750320.976492
2991.505797-2.1927230.9398242.0787790.6032720.9331730.9757830.9392360.976252
300-0.0885271.5494390.699100-1.0644184.9687030.9780980.9780980.9780980.978098
\n", "

301 rows × 9 columns

\n", "
" ], "text/plain": [ " melt_f temp_bias prcp_fac temp_melt glen_a \\\n", "exp \n", "0 NaN NaN NaN NaN NaN \n", "1 0.422340 -1.006530 1.692046 2.001025 2.129014 \n", "2 -0.222516 2.352821 0.844443 -1.413166 0.276735 \n", "3 0.445820 -1.165183 1.727352 2.709390 0.774872 \n", "4 0.690500 -0.557530 1.372393 -1.765897 1.399388 \n", ".. ... ... ... ... ... \n", "296 1.366163 1.086176 1.229347 -2.299781 0.546946 \n", "297 -0.520724 -1.524965 1.235378 -1.497855 1.430720 \n", "298 -1.580318 -1.205472 0.962362 -0.900769 0.214041 \n", "299 1.505797 -2.192723 0.939824 2.078779 0.603272 \n", "300 -0.088527 1.549439 0.699100 -1.064418 4.968703 \n", "\n", " valid_IPSL-CM6A-LR_ssp126 valid_IPSL-CM6A-LR_ssp585 \\\n", "exp \n", "0 0.977888 0.978098 \n", "1 0.471724 0.943878 \n", "2 0.978098 0.978098 \n", "3 0.377674 0.941106 \n", "4 0.977948 0.978061 \n", ".. ... ... \n", "296 0.978098 0.978098 \n", "297 0.964977 0.977689 \n", "298 0.971459 0.976450 \n", "299 0.933173 0.975783 \n", "300 0.978098 0.978098 \n", "\n", " valid_MRI-ESM2-0_ssp126 valid_MRI-ESM2-0_ssp585 \n", "exp \n", "0 0.977977 0.978098 \n", "1 0.532711 0.952051 \n", "2 0.978098 0.978098 \n", "3 0.416018 0.942735 \n", "4 0.977985 0.978098 \n", ".. ... ... \n", "296 0.978098 0.978098 \n", "297 0.976124 0.977699 \n", "298 0.975032 0.976492 \n", "299 0.939236 0.976252 \n", "300 0.978098 0.978098 \n", "\n", "[301 rows x 9 columns]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dfv2" ] }, { "cell_type": "code", "execution_count": 25, "id": "4c626c66-883f-416d-80d0-41d795d83c5c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
melt_ftemp_biasprcp_factemp_meltglen_avalid_CESM2-WACCM_ssp126valid_CESM2-WACCM_ssp534-overvalid_CESM2-WACCM_ssp585valid_IPSL-CM6A-LR_ssp126valid_IPSL-CM6A-LR_ssp534-overvalid_IPSL-CM6A-LR_ssp585valid_MRI-ESM2-0_ssp126valid_MRI-ESM2-0_ssp534-overvalid_MRI-ESM2-0_ssp585
exp
0NaNNaNNaNNaNNaN0.9780610.9780610.9780980.9778880.9778980.9780980.9779770.9780160.978098
10.422340-1.0065301.6920462.0010252.1290140.6723730.6730060.9613280.4717240.4720190.9438780.5327110.6152090.952051
2-0.2225162.3528210.844443-1.4131660.2767350.9780980.9780980.9780980.9780980.9780980.9780980.9780980.9780980.978098
30.445820-1.1651831.7273522.7093900.7748720.5024600.4590060.9575200.3776740.3839900.9411060.4160180.4483020.942735
40.690500-0.5575301.372393-1.7658971.3993880.9780610.9780610.9780980.9779480.9779480.9780610.9779850.9780160.978098
.............................................
2961.3661631.0861761.229347-2.2997810.5469460.9780980.9780980.9780980.9780980.9780980.9780980.9780980.9780980.978098
297-0.520724-1.5249651.235378-1.4978551.4307200.9772210.9772120.9777540.9649770.9733090.9776890.9761240.9768480.977699
298-1.580318-1.2054720.962362-0.9007690.2140410.9761370.9761730.9764710.9714590.9726440.9764500.9750320.9756610.976492
2991.505797-2.1927230.9398242.0787790.6032720.9496890.9491550.9763770.9331730.9349140.9757830.9392360.9434510.976252
300-0.0885271.5494390.699100-1.0644184.9687030.9780980.9780980.9780980.9780980.9780980.9780980.9780980.9780980.978098
\n", "

301 rows × 14 columns

\n", "
" ], "text/plain": [ " melt_f temp_bias prcp_fac temp_melt glen_a \\\n", "exp \n", "0 NaN NaN NaN NaN NaN \n", "1 0.422340 -1.006530 1.692046 2.001025 2.129014 \n", "2 -0.222516 2.352821 0.844443 -1.413166 0.276735 \n", "3 0.445820 -1.165183 1.727352 2.709390 0.774872 \n", "4 0.690500 -0.557530 1.372393 -1.765897 1.399388 \n", ".. ... ... ... ... ... \n", "296 1.366163 1.086176 1.229347 -2.299781 0.546946 \n", "297 -0.520724 -1.524965 1.235378 -1.497855 1.430720 \n", "298 -1.580318 -1.205472 0.962362 -0.900769 0.214041 \n", "299 1.505797 -2.192723 0.939824 2.078779 0.603272 \n", "300 -0.088527 1.549439 0.699100 -1.064418 4.968703 \n", "\n", " valid_CESM2-WACCM_ssp126 valid_CESM2-WACCM_ssp534-over \\\n", "exp \n", "0 0.978061 0.978061 \n", "1 0.672373 0.673006 \n", "2 0.978098 0.978098 \n", "3 0.502460 0.459006 \n", "4 0.978061 0.978061 \n", ".. ... ... \n", "296 0.978098 0.978098 \n", "297 0.977221 0.977212 \n", "298 0.976137 0.976173 \n", "299 0.949689 0.949155 \n", "300 0.978098 0.978098 \n", "\n", " valid_CESM2-WACCM_ssp585 valid_IPSL-CM6A-LR_ssp126 \\\n", "exp \n", "0 0.978098 0.977888 \n", "1 0.961328 0.471724 \n", "2 0.978098 0.978098 \n", "3 0.957520 0.377674 \n", "4 0.978098 0.977948 \n", ".. ... ... \n", "296 0.978098 0.978098 \n", "297 0.977754 0.964977 \n", "298 0.976471 0.971459 \n", "299 0.976377 0.933173 \n", "300 0.978098 0.978098 \n", "\n", " valid_IPSL-CM6A-LR_ssp534-over valid_IPSL-CM6A-LR_ssp585 \\\n", "exp \n", "0 0.977898 0.978098 \n", "1 0.472019 0.943878 \n", "2 0.978098 0.978098 \n", "3 0.383990 0.941106 \n", "4 0.977948 0.978061 \n", ".. ... ... \n", "296 0.978098 0.978098 \n", "297 0.973309 0.977689 \n", "298 0.972644 0.976450 \n", "299 0.934914 0.975783 \n", "300 0.978098 0.978098 \n", "\n", " valid_MRI-ESM2-0_ssp126 valid_MRI-ESM2-0_ssp534-over \\\n", "exp \n", "0 0.977977 0.978016 \n", "1 0.532711 0.615209 \n", "2 0.978098 0.978098 \n", "3 0.416018 0.448302 \n", "4 0.977985 0.978016 \n", ".. ... ... \n", "296 0.978098 0.978098 \n", "297 0.976124 0.976848 \n", "298 0.975032 0.975661 \n", "299 0.939236 0.943451 \n", "300 0.978098 0.978098 \n", "\n", " valid_MRI-ESM2-0_ssp585 \n", "exp \n", "0 0.978098 \n", "1 0.952051 \n", "2 0.978098 \n", "3 0.942735 \n", "4 0.978098 \n", ".. ... \n", "296 0.978098 \n", "297 0.977699 \n", "298 0.976492 \n", "299 0.976252 \n", "300 0.978098 \n", "\n", "[301 rows x 14 columns]" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dfo = pd.concat([dfv2, dfv3[dfv3.columns[5:]]], axis=1)\n", "sorted_cols = list(dfo.columns[:5]) + sorted(dfo.columns[5:])\n", "dfo = dfo[sorted_cols]\n", "dfo" ] }, { "cell_type": "code", "execution_count": 20, "id": "aa6cf49a-6d72-4d6c-9ba5-0913029089dc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['melt_f', 'temp_bias', 'prcp_fac', 'temp_melt', 'glen_a'], dtype='object')" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "code", "execution_count": 23, "id": "d3302c10-7c11-4684-89d4-dbda60be90e9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['valid_IPSL-CM6A-LR_ssp126', 'valid_IPSL-CM6A-LR_ssp585',\n", " 'valid_MRI-ESM2-0_ssp126', 'valid_MRI-ESM2-0_ssp585',\n", " 'valid_IPSL-CM6A-LR_ssp534-over', 'valid_MRI-ESM2-0_ssp534-over',\n", " 'valid_CESM2-WACCM_ssp126', 'valid_CESM2-WACCM_ssp585',\n", " 'valid_CESM2-WACCM_ssp534-over'],\n", " dtype='object')" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "6406d48e-0078-46a9-9d85-3011364ca393", "metadata": {}, "outputs": [], "source": [] } ], "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.10.8" } }, "nbformat": 4, "nbformat_minor": 5 }