Skip to content

Commit 4ca6eb0

Browse files
author
Valentina Ortiz Guzman
committed
minor edit to notebook
1 parent 780f448 commit 4ca6eb0

File tree

1 file changed

+45
-117
lines changed

1 file changed

+45
-117
lines changed

zw3_impact.ipynb

+45-117
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,11 @@
2525
{
2626
"cell_type": "code",
2727
"execution_count": 2,
28-
"id": "9d83f101-2549-4fb9-991d-bf011853dc34",
29-
"metadata": {},
30-
"outputs": [],
31-
"source": [
32-
"# load functions.py (like `import`)\n",
33-
"%run '/home/561/vo7653/.jupyter-root/functions.ipynb'"
34-
]
35-
},
36-
{
37-
"cell_type": "code",
38-
"execution_count": 3,
3928
"id": "b2a3b6a9-ad5b-4642-9088-0cce8fa64b10",
4029
"metadata": {},
4130
"outputs": [],
4231
"source": [
43-
"sns.set_context(\"talk\")\n",
44-
"#sns.set_context(\"notebook\")\n",
45-
"\n",
46-
"# Global variables (for plotting mainly)\n",
47-
"\n",
48-
"# symbol for phase\n",
49-
"phi = r'$\\varphi$'"
32+
"sns.set_context(\"talk\")"
5033
]
5134
},
5235
{
@@ -63,7 +46,6 @@
6346
"cell_type": "markdown",
6447
"id": "017ae224-572b-4981-b757-8fac10b2a5da",
6548
"metadata": {
66-
"jp-MarkdownHeadingCollapsed": true,
6749
"tags": []
6850
},
6951
"source": [
@@ -72,37 +54,34 @@
7254
},
7355
{
7456
"cell_type": "code",
75-
"execution_count": 4,
57+
"execution_count": 3,
7658
"id": "32757b76-1621-4c0e-9c21-51a3c18e5751",
7759
"metadata": {
7860
"tags": []
7961
},
8062
"outputs": [],
8163
"source": [
82-
"## CODE FROM MARTIN'S REPOSITORY!\n",
64+
"## CODE FROM MARTIN'S AOSTOOLS REPOSITORY!\n",
8365
"# Just copied here to modify the return of StatTes() function.\n",
84-
"# Maybe worth add this changes as a flag in aostools.climate.py\n",
85-
"# Talk to Martin!!\n",
8666
"\n",
8767
"def StackArray(x,dim):\n",
88-
"\t'''return stacked array with only one dimension left\n",
89-
"\n",
90-
"\tINPUTS:\n",
91-
"\t x : xarray.DataArray or Dataset to be stacked\n",
92-
"\t dim: sole dimension to remain after stacking, None if all dimensions to be stacked\n",
93-
"\tOUTPUTS:\n",
94-
"\t stacked: same as x, but stacked\n",
95-
"\t'''\n",
96-
"\tif len(x.dims) == 0:\n",
97-
"\t\treturn x\n",
98-
"\tif dim not in x.dims or dim is None:\n",
99-
"\t\tdims = list(x.dims)\n",
100-
"\telse:\n",
101-
"\t\tdims = []\n",
102-
"\t\tfor d in x.dims:\n",
103-
"\t\t\tif d != dim:\n",
104-
"\t\t\t\tdims.append(d)\n",
105-
"\treturn x.stack(stacked=dims)\n",
68+
" '''return stacked array with only one dimension left\n",
69+
" INPUTS:\n",
70+
" x : xarray.DataArray or Dataset to be stacked\n",
71+
" dim: sole dimension to remain after stacking, None if all dimensions to be stacked\n",
72+
" OUTPUTS:\n",
73+
" stacked: same as x, but stacked\n",
74+
" '''\n",
75+
" if len(x.dims) == 0:\n",
76+
" return x\n",
77+
" if dim not in x.dims or dim is None:\n",
78+
" dims = list(x.dims)\n",
79+
" else:\n",
80+
" dims = []\n",
81+
" for d in x.dims:\n",
82+
" if d != dim:\n",
83+
" dims.append(d)\n",
84+
" return x.stack(stacked=dims)\n",
10685
"\n",
10786
"def ComputeStat(i,sx,y,sy,test, tstat_r=False):\n",
10887
" '''This is part of StatTest, but for parmap.map to work, it has to be an\n",
@@ -204,7 +183,7 @@
204183
},
205184
{
206185
"cell_type": "code",
207-
"execution_count": 6,
186+
"execution_count": 4,
208187
"id": "8d6ae13c-31fb-433b-904d-d7d8cf6a7b09",
209188
"metadata": {
210189
"tags": []
@@ -494,7 +473,7 @@
494473
},
495474
{
496475
"cell_type": "code",
497-
"execution_count": null,
476+
"execution_count": 5,
498477
"id": "11d45ea5-5539-47a4-9572-f0f51858f9cc",
499478
"metadata": {
500479
"tags": []
@@ -615,7 +594,7 @@
615594
},
616595
{
617596
"cell_type": "code",
618-
"execution_count": null,
597+
"execution_count": 6,
619598
"id": "ee02374b-4751-4ddb-9599-f0cab5493d32",
620599
"metadata": {
621600
"tags": []
@@ -1126,6 +1105,7 @@
11261105
"cell_type": "markdown",
11271106
"id": "a98e7e9e-fd80-4e07-acce-1166602c3f08",
11281107
"metadata": {
1108+
"jp-MarkdownHeadingCollapsed": true,
11291109
"tags": []
11301110
},
11311111
"source": [
@@ -1135,14 +1115,15 @@
11351115
},
11361116
{
11371117
"cell_type": "code",
1138-
"execution_count": 8,
1118+
"execution_count": 7,
11391119
"id": "3432156b-c171-4cdc-ac4b-43930acab88f",
11401120
"metadata": {
11411121
"tags": []
11421122
},
11431123
"outputs": [],
11441124
"source": [
11451125
"# ERA5 data dir\n",
1126+
"# (replace here with the path where your ERA5 data is stored)\n",
11461127
"era5_dir = '/g/data/w40/vo7653/downsized_data/ERA5/daily_data/'\n",
11471128
"\n",
11481129
"# daily meridional wind\n",
@@ -1176,7 +1157,7 @@
11761157
},
11771158
{
11781159
"cell_type": "code",
1179-
"execution_count": 10,
1160+
"execution_count": 8,
11801161
"id": "081f8a87-91d7-456e-ba67-bb665adf66d3",
11811162
"metadata": {
11821163
"tags": []
@@ -1223,6 +1204,7 @@
12231204
"cell_type": "markdown",
12241205
"id": "05ebaf5f-eb50-484c-9c26-df1b14384449",
12251206
"metadata": {
1207+
"jp-MarkdownHeadingCollapsed": true,
12261208
"tags": []
12271209
},
12281210
"source": [
@@ -1232,7 +1214,7 @@
12321214
},
12331215
{
12341216
"cell_type": "code",
1235-
"execution_count": 14,
1217+
"execution_count": 9,
12361218
"id": "e68ef92a-f1fd-4e99-a588-a03e5f90ceec",
12371219
"metadata": {
12381220
"tags": []
@@ -1311,6 +1293,7 @@
13111293
"cell_type": "markdown",
13121294
"id": "8aac5c14-5fcc-4184-a032-98024691fc42",
13131295
"metadata": {
1296+
"jp-MarkdownHeadingCollapsed": true,
13141297
"tags": []
13151298
},
13161299
"source": [
@@ -1345,6 +1328,7 @@
13451328
"cell_type": "markdown",
13461329
"id": "20873277-cb2e-4ec4-ba71-0ce6e5a734ce",
13471330
"metadata": {
1331+
"jp-MarkdownHeadingCollapsed": true,
13481332
"tags": []
13491333
},
13501334
"source": [
@@ -1407,7 +1391,7 @@
14071391
"\n",
14081392
"# gp\n",
14091393
"gp_comp_ = []\n",
1410-
"for s in ['DJF', 'MAM', 'JJA', 'SON']:\n",
1394+
"for s in ['DJF']:#, 'MAM', 'JJA', 'SON']:\n",
14111395
" gp_comp_s = lag_compose_on_w3(gp_roll_anom, phase, amp, bins, lags, V=Vtp_79, season=s)\n",
14121396
" gp_comp_s['stdd'] = gp_comp_s['z']\n",
14131397
" gp_comp_s['season'] = s \n",
@@ -1478,7 +1462,10 @@
14781462
{
14791463
"cell_type": "markdown",
14801464
"id": "1ac4f1d6-7e39-42b9-8423-5acf60bdc3da",
1481-
"metadata": {},
1465+
"metadata": {
1466+
"jp-MarkdownHeadingCollapsed": true,
1467+
"tags": []
1468+
},
14821469
"source": [
14831470
"#### Figure 1, Figure 2"
14841471
]
@@ -1522,6 +1509,7 @@
15221509
"cell_type": "markdown",
15231510
"id": "4abb3cea-727d-4d39-9bb0-0586028c575f",
15241511
"metadata": {
1512+
"jp-MarkdownHeadingCollapsed": true,
15251513
"tags": []
15261514
},
15271515
"source": [
@@ -1566,6 +1554,7 @@
15661554
"cell_type": "markdown",
15671555
"id": "4e1acf9f-4bee-4475-abc7-2c4a94122d4f",
15681556
"metadata": {
1557+
"jp-MarkdownHeadingCollapsed": true,
15691558
"tags": []
15701559
},
15711560
"source": [
@@ -1605,6 +1594,7 @@
16051594
"cell_type": "markdown",
16061595
"id": "cd46fa21-e910-4a04-985d-142fa3e9bca6",
16071596
"metadata": {
1597+
"jp-MarkdownHeadingCollapsed": true,
16081598
"tags": []
16091599
},
16101600
"source": [
@@ -1886,14 +1876,6 @@
18861876
"prob_H_ZW3phase = xr.concat(prob_H_ZW3phase, dim='sam_thresh')"
18871877
]
18881878
},
1889-
{
1890-
"cell_type": "markdown",
1891-
"id": "e317d462-aa4e-4bf1-af2d-5ccc1c34a193",
1892-
"metadata": {},
1893-
"source": [
1894-
"#### Figure 6"
1895-
]
1896-
},
18971879
{
18981880
"cell_type": "code",
18991881
"execution_count": 28,
@@ -1984,6 +1966,7 @@
19841966
"cell_type": "markdown",
19851967
"id": "5ffdd456-86f5-4991-86c2-bd0f6dab4561",
19861968
"metadata": {
1969+
"jp-MarkdownHeadingCollapsed": true,
19871970
"tags": []
19881971
},
19891972
"source": [
@@ -2055,13 +2038,6 @@
20552038
"prob_H_PSA1 = p_H_idx(psa1, n=nbins, box=regs[reg], extrm=ph, pct=pct, min_ssize=nstar, wdw=wdw, season=s)\n",
20562039
"prob_H_PSA2 = p_H_idx(psa2, n=nbins, box=regs[reg], extrm=ph, pct=pct, min_ssize=nstar, wdw=wdw, season=s)\n",
20572040
"\n",
2058-
"# # Probability of (ZW3, Index)\n",
2059-
"# prob_ZW3phase_SAM = p_zw3phase_and_idx(phase, bins, sam, n=nbins, amp=amp_std, amp_thresh=Athresh, season=s)\n",
2060-
"# prob_ZW3phase_Nino = p_zw3phase_and_idx(phase_nino, bins, nino, n=nbins, amp=amp_nino_std, amp_thresh=Athresh, season=s)\n",
2061-
"# prob_ZW3phase_IOD = p_zw3phase_and_idx(phase_nino, bins, iod, n=nbins, amp=amp_nino_std, amp_thresh=Athresh, season=s)\n",
2062-
"# prob_ZW3phase_PSA1 = p_zw3phase_and_idx(phase, bins, psa1, n=nbins, amp=amp_std, amp_thresh=Athresh, season=s)\n",
2063-
"# prob_ZW3phase_PSA2 = p_zw3phase_and_idx(phase, bins, psa2, n=nbins, amp=amp_std, amp_thresh=Athresh, season=s)\n",
2064-
"\n",
20652041
"# Probability of H given ZW3 and Index\n",
20662042
"nstar2 = 30 if timescale=='30dRM' else 5\n",
20672043
"\n",
@@ -2292,7 +2268,9 @@
22922268
{
22932269
"cell_type": "markdown",
22942270
"id": "6a3647dc-bb98-4478-b7b3-dd940520cf42",
2295-
"metadata": {},
2271+
"metadata": {
2272+
"tags": []
2273+
},
22962274
"source": [
22972275
"#### Figure 9 \n",
22982276
"SST composites comparison"
@@ -2513,68 +2491,18 @@
25132491
},
25142492
{
25152493
"cell_type": "code",
2516-
"execution_count": 1,
2517-
"id": "fa066966-1cd6-49cc-9246-b7cabac3977f",
2518-
"metadata": {},
2519-
"outputs": [
2520-
{
2521-
"data": {
2522-
"text/plain": [
2523-
"'/home/561/vo7653'"
2524-
]
2525-
},
2526-
"execution_count": 1,
2527-
"metadata": {},
2528-
"output_type": "execute_result"
2529-
}
2530-
],
2531-
"source": [
2532-
"pwd"
2533-
]
2534-
},
2535-
{
2536-
"cell_type": "code",
2537-
"execution_count": 42,
2494+
"execution_count": 2,
25382495
"id": "38d3a7a3-ade1-4396-88a0-12f1b109ee0b",
25392496
"metadata": {
25402497
"tags": []
25412498
},
2542-
"outputs": [
2543-
{
2544-
"ename": "NameError",
2545-
"evalue": "name 'skt_comp_' is not defined",
2546-
"output_type": "error",
2547-
"traceback": [
2548-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
2549-
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
2550-
"\u001b[0;32m/jobfs/116478024.gadi-pbs/ipykernel_975632/72449981.py\u001b[0m in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mlevels\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlinspace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m0.72\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0.72\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m19\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mskt_all\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mplot_SSTs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpval\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevels\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlevels\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;31m# save fig\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;31m#skt_all.savefig(f'{path_figs}skt_comps.pdf', bbox_inches='tight', facecolor='white', transparent=False)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
2551-
"\u001b[0;32m/jobfs/116478024.gadi-pbs/ipykernel_975632/1986014422.py\u001b[0m in \u001b[0;36mplot_SSTs\u001b[0;34m(pval, levels, cmap, regions, var2)\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mvar1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msig_mask1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 14\u001b[0;31m \u001b[0mdalist\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mskt_comp_\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mskt_comp_g\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mskt_comp_w1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 15\u001b[0m \u001b[0mdanames\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m'Fourier ZW3'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'Goyal ZW3'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'Fourier ZW1'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
2552-
"\u001b[0;31mNameError\u001b[0m: name 'skt_comp_' is not defined"
2553-
]
2554-
}
2555-
],
2499+
"outputs": [],
25562500
"source": [
25572501
"levels = np.linspace(-0.72, 0.72, 19)\n",
25582502
"skt_all = plot_SSTs(pval=0.1, levels=levels)\n",
25592503
"# save fig\n",
25602504
"#skt_all.savefig(f'{path_figs}skt_comps.pdf', bbox_inches='tight', facecolor='white', transparent=False)"
25612505
]
2562-
},
2563-
{
2564-
"cell_type": "code",
2565-
"execution_count": 87,
2566-
"id": "ec15ef0c-ba52-47f4-8f1f-853c7b5b9bbe",
2567-
"metadata": {},
2568-
"outputs": [],
2569-
"source": []
2570-
},
2571-
{
2572-
"cell_type": "code",
2573-
"execution_count": null,
2574-
"id": "214b8339-59aa-4f7f-a88d-a9a05a7c1a31",
2575-
"metadata": {},
2576-
"outputs": [],
2577-
"source": []
25782506
}
25792507
],
25802508
"metadata": {

0 commit comments

Comments
 (0)