{ "cells": [ { "cell_type": "markdown", "id": "eca44042", "metadata": { "papermill": { "duration": 0.023375, "end_time": "2021-06-07T20:43:04.877986", "exception": false, "start_time": "2021-06-07T20:43:04.854611", "status": "completed" }, "tags": [] }, "source": [ "# Analysis of the Gravity wave drag" ] }, { "cell_type": "code", "execution_count": 1, "id": "d21abe05", "metadata": { "execution": { "iopub.execute_input": "2021-06-07T20:43:04.957934Z", "iopub.status.busy": "2021-06-07T20:43:04.957239Z", "iopub.status.idle": "2021-06-07T20:43:05.847823Z", "shell.execute_reply": "2021-06-07T20:43:05.846720Z" }, "papermill": { "duration": 0.931382, "end_time": "2021-06-07T20:43:05.848135", "exception": false, "start_time": "2021-06-07T20:43:04.916753", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "from netCDF4 import Dataset, num2date\n", "import xarray as xr\n", "import xarray.ufuncs as xrf\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import glob" ] }, { "cell_type": "markdown", "id": "bc349ecf", "metadata": { "papermill": { "duration": 0.006214, "end_time": "2021-06-07T20:43:05.866740", "exception": false, "start_time": "2021-06-07T20:43:05.860526", "status": "completed" }, "tags": [] }, "source": [ "## Definitions" ] }, { "cell_type": "code", "execution_count": 2, "id": "cb9688c1", "metadata": { "execution": { "iopub.execute_input": "2021-06-07T20:43:05.886105Z", "iopub.status.busy": "2021-06-07T20:43:05.885689Z", "iopub.status.idle": "2021-06-07T20:43:05.888634Z", "shell.execute_reply": "2021-06-07T20:43:05.888952Z" }, "papermill": { "duration": 0.015196, "end_time": "2021-06-07T20:43:05.889087", "exception": false, "start_time": "2021-06-07T20:43:05.873891", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "def anomalie(step,var):\n", " string = \"time.\"+step \n", " climatology = var.groupby(string).mean(\"time\")\n", " anomalies = var.groupby(string) - climatology\n", " \n", " return anomalies" ] }, { "cell_type": "code", "execution_count": 3, "id": "374d5895", "metadata": { "execution": { "iopub.execute_input": "2021-06-07T20:43:05.913535Z", "iopub.status.busy": "2021-06-07T20:43:05.913116Z", "iopub.status.idle": "2021-06-07T20:43:05.915996Z", "shell.execute_reply": "2021-06-07T20:43:05.915668Z" }, "papermill": { "duration": 0.01975, "end_time": "2021-06-07T20:43:05.916075", "exception": false, "start_time": "2021-06-07T20:43:05.896325", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "def sea(days_period,station,var):\n", " df_dates = pd.read_csv('/home/hochatmstud/bene/dates/without_final_warmings/ssw_dates_without_final_warmings_'+station+'.csv') # you can load SSWs from a csv file like attached\n", " dates = df_dates.set_index('BeginDate')\n", "\n", " xa_ls = []\n", " max_lag = days_period\n", " for il, days in enumerate(range(-max_lag,max_lag+1)): \n", " sel_dates = pd.to_datetime(dates.index) + pd.Timedelta(str(days)+' days')\n", " mask = np.in1d(var.time.dt.floor('1D'),sel_dates)\n", " comp_m = var.sel(time = mask).mean('time')\n", " xa_ls.append(comp_m)\n", " \n", " xa_comp = xr.concat(xa_ls, dim = 'days')\n", " xa_comp['days'] = range(-max_lag, max_lag+1)\n", "\n", " # print(xa_comp)\n", " return xa_comp" ] }, { "cell_type": "markdown", "id": "9afbcb68", "metadata": { "papermill": { "duration": 0.007335, "end_time": "2021-06-07T20:43:05.933613", "exception": false, "start_time": "2021-06-07T20:43:05.926278", "status": "completed" }, "tags": [] }, "source": [ "## Analysis" ] }, { "cell_type": "code", "execution_count": 4, "id": "7d8ad0fe", "metadata": { "execution": { "iopub.execute_input": "2021-06-07T20:43:05.950674Z", "iopub.status.busy": "2021-06-07T20:43:05.950250Z", "iopub.status.idle": "2021-06-07T20:43:05.953297Z", "shell.execute_reply": "2021-06-07T20:43:05.952938Z" }, "papermill": { "duration": 0.013748, "end_time": "2021-06-07T20:43:05.953394", "exception": false, "start_time": "2021-06-07T20:43:05.939646", "status": "completed" }, "tags": [ "parameters" ] }, "outputs": [], "source": [ "station = 'Leipzig'" ] }, { "cell_type": "code", "execution_count": 5, "id": "facb7378", "metadata": { "execution": { "iopub.execute_input": "2021-06-07T20:43:05.971127Z", "iopub.status.busy": "2021-06-07T20:43:05.970711Z", "iopub.status.idle": "2021-06-07T20:43:05.973449Z", "shell.execute_reply": "2021-06-07T20:43:05.973776Z" }, "papermill": { "duration": 0.013757, "end_time": "2021-06-07T20:43:05.973875", "exception": false, "start_time": "2021-06-07T20:43:05.960118", "status": "completed" }, "tags": [ "injected-parameters" ] }, "outputs": [], "source": [ "# Parameters\n", "station = \"Andenes\"\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "2a72c17a", "metadata": { "execution": { "iopub.execute_input": "2021-06-07T20:43:05.995091Z", "iopub.status.busy": "2021-06-07T20:43:05.994662Z", "iopub.status.idle": "2021-06-07T20:43:05.997256Z", "shell.execute_reply": "2021-06-07T20:43:05.996911Z" }, "papermill": { "duration": 0.016401, "end_time": "2021-06-07T20:43:05.997350", "exception": false, "start_time": "2021-06-07T20:43:05.980949", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "if station == 'Leipzig':\n", " dir = '/home/gemeinsam_tmp/UA_students/data/PW_GW_analysis/GWD_2004-08-01_2020-12-01_Col.nc'\n", "elif station == 'CMOR':\n", " dir = '/home/gemeinsam_tmp/UA_students/data/PW_GW_analysis/GWD_2002-01-01_2020-11-01_CMA.nc'\n", "elif station == 'Esrange':\n", " dir = '/home/gemeinsam_tmp/UA_students/data/PW_GW_analysis/GWD_1999-08-01_2021-03-01_Kir.nc'\n", "elif station == 'Sodankyla':\n", " dir = '/home/gemeinsam_tmp/UA_students/data/PW_GW_analysis/GWD_2008-10-01_2021-03-01_Sod.nc'\n", "elif station == 'Davis':\n", " dir = '/home/gemeinsam_tmp/UA_students/data/PW_GW_analysis/GWD_2005-01-01_2020-12-01_Dav.nc'\n", "elif station == 'RioGrande':\n", " dir = '/home/gemeinsam_tmp/UA_students/data/PW_GW_analysis/GWD_2008-02-01_2021-01-01_Rio.nc'\n", "elif station == 'Andenes':\n", " dir = '/home/gemeinsam_tmp/UA_students/data/PW_GW_analysis/GWD_1999-08-01_2019-12-01_SES.nc'" ] }, { "cell_type": "code", "execution_count": 7, "id": "42caf289", "metadata": { "execution": { "iopub.execute_input": "2021-06-07T20:43:06.021675Z", "iopub.status.busy": "2021-06-07T20:43:06.021275Z", "iopub.status.idle": "2021-06-07T20:43:06.040922Z", "shell.execute_reply": "2021-06-07T20:43:06.040139Z" }, "papermill": { "duration": 0.036342, "end_time": "2021-06-07T20:43:06.041131", "exception": false, "start_time": "2021-06-07T20:43:06.004789", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "ds=xr.open_dataset(dir)" ] }, { "cell_type": "code", "execution_count": 8, "id": "7b3a0cbe", "metadata": { "execution": { "iopub.execute_input": "2021-06-07T20:43:06.073647Z", "iopub.status.busy": "2021-06-07T20:43:06.070562Z", "iopub.status.idle": "2021-06-07T20:43:06.076989Z", "shell.execute_reply": "2021-06-07T20:43:06.076448Z" }, "papermill": { "duration": 0.024815, "end_time": "2021-06-07T20:43:06.077133", "exception": false, "start_time": "2021-06-07T20:43:06.052318", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
[178992 values with dtype=int64]
array([ 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96,\n",
" 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120])array(['1999-08-01T00:00:00.000000000', '1999-08-01T01:00:00.000000000',\n",
" '1999-08-01T02:00:00.000000000', ..., '2019-12-31T21:00:00.000000000',\n",
" '2019-12-31T22:00:00.000000000', '2019-12-31T23:00:00.000000000'],\n",
" dtype='datetime64[ns]')[4653792 values with dtype=float64]