Skip to content

Commit 0f8a826

Browse files
committed
Add first example
0 parents  commit 0f8a826

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed

EasierWayToGetVariableNames.ipynb

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Getting all Variable names from xarray\n",
8+
"\n",
9+
"Question: Is there a short way to get number of unique coordinates in a DataSet object?"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 7,
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"data": {
19+
"text/plain": [
20+
"'0.11.3'"
21+
]
22+
},
23+
"execution_count": 7,
24+
"metadata": {},
25+
"output_type": "execute_result"
26+
}
27+
],
28+
"source": [
29+
"import arviz as az\n",
30+
"import xarray as xr\n",
31+
"xr.__version__"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": 4,
37+
"metadata": {},
38+
"outputs": [
39+
{
40+
"data": {
41+
"text/plain": [
42+
"arviz.data.inference_data.InferenceData"
43+
]
44+
},
45+
"execution_count": 4,
46+
"metadata": {},
47+
"output_type": "execute_result"
48+
}
49+
],
50+
"source": [
51+
"# Load NetCDF File from fileshare\n",
52+
"radon_data = az.load_arviz_data(dataset=\"radon\")\n",
53+
"\n",
54+
"type(radon_data)"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": 8,
60+
"metadata": {},
61+
"outputs": [
62+
{
63+
"data": {
64+
"text/plain": [
65+
"xarray.core.dataset.Dataset"
66+
]
67+
},
68+
"execution_count": 8,
69+
"metadata": {},
70+
"output_type": "execute_result"
71+
}
72+
],
73+
"source": [
74+
"observed_dataset = radon_data.observed_data\n",
75+
"type(observed_dataset)"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": 9,
81+
"metadata": {},
82+
"outputs": [
83+
{
84+
"data": {
85+
"text/plain": [
86+
"<xarray.Dataset>\n",
87+
"Dimensions: (observed_county: 919)\n",
88+
"Coordinates:\n",
89+
" * observed_county (observed_county) object 'AITKIN' ... 'YELLOW MEDICINE'\n",
90+
"Data variables:\n",
91+
" y_like (observed_county) float64 ...\n",
92+
"Attributes:\n",
93+
" created_at: 2018-10-05T15:29:14.882229\n",
94+
" inference_library: pymc3\n",
95+
" inference_library_version: 3.5"
96+
]
97+
},
98+
"execution_count": 9,
99+
"metadata": {},
100+
"output_type": "execute_result"
101+
}
102+
],
103+
"source": [
104+
"observed_dataset"
105+
]
106+
},
107+
{
108+
"cell_type": "code",
109+
"execution_count": 10,
110+
"metadata": {},
111+
"outputs": [
112+
{
113+
"data": {
114+
"text/plain": [
115+
"(85,)"
116+
]
117+
},
118+
"execution_count": 10,
119+
"metadata": {},
120+
"output_type": "execute_result"
121+
}
122+
],
123+
"source": [
124+
"# Can this be made shorter?\n",
125+
"radon_data.observed_data.to_dataframe().index.unique().shape"
126+
]
127+
}
128+
],
129+
"metadata": {
130+
"kernelspec": {
131+
"display_name": "Python 3",
132+
"language": "python",
133+
"name": "python3"
134+
},
135+
"language_info": {
136+
"codemirror_mode": {
137+
"name": "ipython",
138+
"version": 3
139+
},
140+
"file_extension": ".py",
141+
"mimetype": "text/x-python",
142+
"name": "python",
143+
"nbconvert_exporter": "python",
144+
"pygments_lexer": "ipython3",
145+
"version": "3.6.7"
146+
}
147+
},
148+
"nbformat": 4,
149+
"nbformat_minor": 2
150+
}

0 commit comments

Comments
 (0)