Skip to content

Commit

Permalink
update w-avg notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
cehbrecht committed Oct 27, 2023
1 parent 5cf8f6b commit 23c85a1
Showing 1 changed file with 102 additions and 6 deletions.
108 changes: 102 additions & 6 deletions notebooks/weighted_average.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,98 @@
"import numpy as np"
]
},
{
"cell_type": "markdown",
"id": "8a17aae4-9928-4b01-addf-ebbc9a54d7f6",
"metadata": {},
"source": [
"## search intake catalog"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6fe8241b-6edb-45fa-8706-f1ba374a4d4e",
"metadata": {},
"outputs": [],
"source": [
"import intake"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "69afa185-ecf5-420f-8942-f24e738555d3",
"metadata": {},
"outputs": [],
"source": [
"cat_url = \"https://raw.githubusercontent.com/cp4cds/c3s_34g_manifests/master/intake/catalogs/c3s.yaml\"\n",
"\n",
"cat = intake.open_catalog(cat_url)\n",
"list(cat)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "551b1877-c39e-47c6-a358-31a193cbff93",
"metadata": {},
"outputs": [],
"source": [
"df_cmip6 = cat['c3s-cmip6'].read()\n",
"df_cmip6.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3191572-09af-4607-841f-d3a288edc904",
"metadata": {},
"outputs": [],
"source": [
"df = df_cmip6.loc[\n",
" (df_cmip6.experiment_id==\"ssp245\")\n",
" & (df_cmip6.activity_id==\"ScenarioMIP\")\n",
" & (df_cmip6.institution_id==\"MPI-M\")\n",
" & (df_cmip6.member_id==\"r1i1p1f1\")\n",
" & (df_cmip6.table_id==\"Amon\")\n",
" & (df_cmip6.source_id==\"MPI-ESM1-2-LR\")\n",
" & (df_cmip6.variable_id==\"tasmax\")\n",
"]\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e938263-a1ec-441a-a375-35c863f8a611",
"metadata": {},
"outputs": [],
"source": [
"ds_path = list(set(df.path))[0]\n",
"ds_path"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1596cd41-7f6a-43f0-aa9a-64629a06cf3d",
"metadata": {},
"outputs": [],
"source": [
"# ds_url = f\"https://data.mips.copernicus-climate.eu/thredds/fileServer/esg_c3s-cmip6/{ds_path}\"\n",
"ds_url = f\"http://esgf3.dkrz.de/thredds/fileServer/cmip6/{ds_path}\"\n",
"ds_url"
]
},
{
"cell_type": "markdown",
"id": "48daa7a3-b2bc-4662-af52-1616d4ef6db7",
"metadata": {},
"source": [
"## download test data"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -46,11 +138,7 @@
"metadata": {},
"outputs": [],
"source": [
"cmip6_url = \"http://esgf3.dkrz.de/thredds/fileServer/cmip6/ScenarioMIP/DKRZ/MPI-ESM1-2-HR/ssp245/r1i1p1f1/Amon/tasmax/gn/v20190710/tasmax_Amon_MPI-ESM1-2-HR_ssp245_r1i1p1f1_gn_202001-202412.nc\"\n",
"\n",
"cmip5_url = \"http://esgf1.dkrz.de/thredds/fileServer/cmip5/cmip5/output1/MPI-M/MPI-ESM-LR/historical/mon/atmos/Amon/r1i1p1/v20120315/cct/cct_Amon_MPI-ESM-LR_historical_r1i1p1_185001-200512.nc\"\n",
"\n",
"!wget $cmip5_url -O /tmp/test.nc"
"!wget $ds_url -O /tmp/test.nc"
]
},
{
Expand All @@ -60,10 +148,18 @@
"metadata": {},
"outputs": [],
"source": [
"nc_files = sorted(data_dir.glob('**/*.nc'))\n",
"nc_files = sorted(data_dir.glob('**/test.nc'))\n",
"nc_files"
]
},
{
"cell_type": "markdown",
"id": "ec0ae6ce-d503-4fc6-82c6-8f08d8bc4f04",
"metadata": {},
"source": [
"## calculate weighted average"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit 23c85a1

Please sign in to comment.