Skip to content

Commit 330bd40

Browse files
committed
Lint notebook
1 parent 0553f31 commit 330bd40

File tree

1 file changed

+77
-38
lines changed

1 file changed

+77
-38
lines changed

doc/examples/introduction.ipynb

Lines changed: 77 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"# Introduction to `cf_xarray`\n",
88
"\n",
9-
"This notebook is a brief introduction to `cf_xarray`'s current capabilities."
9+
"This notebook is a brief introduction to `cf_xarray`'s current capabilities.\n"
1010
]
1111
},
1212
{
@@ -29,7 +29,7 @@
2929
"cell_type": "markdown",
3030
"metadata": {},
3131
"source": [
32-
"Lets read two datasets."
32+
"Lets read two datasets.\n"
3333
]
3434
},
3535
{
@@ -52,7 +52,8 @@
5252
"cell_type": "markdown",
5353
"metadata": {},
5454
"source": [
55-
"This one is inspired by POP model output and illustrates how the coordinates attribute is interpreted"
55+
"This one is inspired by POP model output and illustrates how the coordinates\n",
56+
"attribute is interpreted\n"
5657
]
5758
},
5859
{
@@ -67,10 +68,26 @@
6768
"outputs": [],
6869
"source": [
6970
"pop = xr.Dataset()\n",
70-
"pop.coords[\"TLONG\"] = ((\"nlat\", \"nlon\"), np.ones((20, 30)), {\"units\": \"degrees_east\"})\n",
71-
"pop.coords[\"TLAT\"] = ((\"nlat\", \"nlon\"), 2 * np.ones((20, 30)), {\"units\": \"degrees_north\"})\n",
72-
"pop.coords[\"ULONG\"] = ((\"nlat\", \"nlon\"), 0.5 * np.ones((20, 30)), {\"units\": \"degrees_east\"})\n",
73-
"pop.coords[\"ULAT\"] = ((\"nlat\", \"nlon\"), 2.5 * np.ones((20, 30)), {\"units\": \"degrees_north\"})\n",
71+
"pop.coords[\"TLONG\"] = (\n",
72+
" (\"nlat\", \"nlon\"),\n",
73+
" np.ones((20, 30)),\n",
74+
" {\"units\": \"degrees_east\"},\n",
75+
")\n",
76+
"pop.coords[\"TLAT\"] = (\n",
77+
" (\"nlat\", \"nlon\"),\n",
78+
" 2 * np.ones((20, 30)),\n",
79+
" {\"units\": \"degrees_north\"},\n",
80+
")\n",
81+
"pop.coords[\"ULONG\"] = (\n",
82+
" (\"nlat\", \"nlon\"),\n",
83+
" 0.5 * np.ones((20, 30)),\n",
84+
" {\"units\": \"degrees_east\"},\n",
85+
")\n",
86+
"pop.coords[\"ULAT\"] = (\n",
87+
" (\"nlat\", \"nlon\"),\n",
88+
" 2.5 * np.ones((20, 30)),\n",
89+
" {\"units\": \"degrees_north\"},\n",
90+
")\n",
7491
"\n",
7592
"pop[\"UVEL\"] = (\n",
7693
" (\"nlat\", \"nlon\"),\n",
@@ -80,7 +97,10 @@
8097
"pop[\"TEMP\"] = (\n",
8198
" (\"nlat\", \"nlon\"),\n",
8299
" np.ones((20, 30)) * 15,\n",
83-
" {\"coordinates\": \"TLONG TLAT\", \"standard_name\": \"sea_water_potential_temperature\"},\n",
100+
" {\n",
101+
" \"coordinates\": \"TLONG TLAT\",\n",
102+
" \"standard_name\": \"sea_water_potential_temperature\",\n",
103+
" },\n",
84104
")\n",
85105
"pop"
86106
]
@@ -89,7 +109,8 @@
89109
"cell_type": "markdown",
90110
"metadata": {},
91111
"source": [
92-
"This synthetic dataset has multiple `X` and `Y` coords. An example would be model output on a staggered grid."
112+
"This synthetic dataset has multiple `X` and `Y` coords. An example would be\n",
113+
"model output on a staggered grid.\n"
93114
]
94115
},
95116
{
@@ -143,7 +164,10 @@
143164
" dict(standard_name=\"specific_humidity standard_error\", units=\"g/g\"),\n",
144165
")\n",
145166
"anc[\"q_detection_limit\"] = xr.DataArray(\n",
146-
" 1e-3, attrs=dict(standard_name=\"specific_humidity detection_minimum\", units=\"g/g\"),\n",
167+
" 1e-3,\n",
168+
" attrs=dict(\n",
169+
" standard_name=\"specific_humidity detection_minimum\", units=\"g/g\"\n",
170+
" ),\n",
147171
")\n",
148172
"anc"
149173
]
@@ -152,7 +176,7 @@
152176
"cell_type": "markdown",
153177
"metadata": {},
154178
"source": [
155-
"## What attributes have been discovered?"
179+
"## What attributes have been discovered?\n"
156180
]
157181
},
158182
{
@@ -173,9 +197,12 @@
173197
"cell_type": "markdown",
174198
"metadata": {},
175199
"source": [
176-
"`ds.lon` has attributes `axis: X`. This means that `cf_xarray` can identify the `'X'` axis as being represented by the `lon` variable.\n",
200+
"`ds.lon` has attributes `axis: X`. This means that `cf_xarray` can identify the\n",
201+
"`'X'` axis as being represented by the `lon` variable.\n",
177202
"\n",
178-
"It can also use the `standard_name` and `units` attributes to infer that `lon` is \"Longitude\". To see variable names that `cf_xarray` can infer, use `.cf.describe()`"
203+
"It can also use the `standard_name` and `units` attributes to infer that `lon`\n",
204+
"is \"Longitude\". To see variable names that `cf_xarray` can infer, use\n",
205+
"`.cf.describe()`\n"
179206
]
180207
},
181208
{
@@ -196,7 +223,9 @@
196223
"cell_type": "markdown",
197224
"metadata": {},
198225
"source": [
199-
"For `pop`, only `latitude` and `longitude` are detected, not `X` or `Y`. Please comment here: https://github.com/xarray-contrib/cf-xarray/issues/23 if you have opinions about this behaviour."
226+
"For `pop`, only `latitude` and `longitude` are detected, not `X` or `Y`. Please\n",
227+
"comment here: https://github.com/xarray-contrib/cf-xarray/issues/23 if you have\n",
228+
"opinions about this behaviour.\n"
200229
]
201230
},
202231
{
@@ -217,7 +246,7 @@
217246
"cell_type": "markdown",
218247
"metadata": {},
219248
"source": [
220-
"For `multiple`, multiple `X` and `Y` coordinates are detected"
249+
"For `multiple`, multiple `X` and `Y` coordinates are detected\n"
221250
]
222251
},
223252
{
@@ -240,7 +269,8 @@
240269
"source": [
241270
"## Feature: Accessing coordinate variables\n",
242271
"\n",
243-
"`.cf` implements `__getitem__` to allow easy access to coordinate and axis variables."
272+
"`.cf` implements `__getitem__` to allow easy access to coordinate and axis\n",
273+
"variables.\n"
244274
]
245275
},
246276
{
@@ -291,7 +321,7 @@
291321
"cell_type": "markdown",
292322
"metadata": {},
293323
"source": [
294-
"`Dataset.cf[...]` returns a `Dataset`, possibly with multiple variables"
324+
"`Dataset.cf[...]` returns a `Dataset`, possibly with multiple variables\n"
295325
]
296326
},
297327
{
@@ -313,7 +343,9 @@
313343
"cell_type": "markdown",
314344
"metadata": {},
315345
"source": [
316-
"`Dataset.cf[...]` returns a single `DataArray`, parsing the `coordinates` attribute if present, so we correctly get the `TLONG` variable and not the `ULONG` variable"
346+
"`Dataset.cf[...]` returns a single `DataArray`, parsing the `coordinates`\n",
347+
"attribute if present, so we correctly get the `TLONG` variable and not the\n",
348+
"`ULONG` variable\n"
317349
]
318350
},
319351
{
@@ -335,7 +367,8 @@
335367
"cell_type": "markdown",
336368
"metadata": {},
337369
"source": [
338-
"`Dataset.cf[...]` also interprets the `ancillary_variables` attribute. The ancillary variables are returned as coordinates of a DataArray"
370+
"`Dataset.cf[...]` also interprets the `ancillary_variables` attribute. The\n",
371+
"ancillary variables are returned as coordinates of a DataArray\n"
339372
]
340373
},
341374
{
@@ -356,7 +389,7 @@
356389
"cell_type": "markdown",
357390
"metadata": {},
358391
"source": [
359-
"## Feature: Accessing variables by standard names"
392+
"## Feature: Accessing variables by standard names\n"
360393
]
361394
},
362395
{
@@ -393,8 +426,7 @@
393426
"source": [
394427
"## Feature: Utility functions\n",
395428
"\n",
396-
"\n",
397-
"There are some utility functions to allow use by downstream libraries"
429+
"There are some utility functions to allow use by downstream libraries\n"
398430
]
399431
},
400432
{
@@ -417,7 +449,8 @@
417449
"source": [
418450
"## Feature: Rewriting property dictionaries\n",
419451
"\n",
420-
"`cf_xarray` will rewrite the `.sizes` and `.chunks` dictionaries so that one can index by a special CF axis or coordinate name"
452+
"`cf_xarray` will rewrite the `.sizes` and `.chunks` dictionaries so that one can\n",
453+
"index by a special CF axis or coordinate name\n"
421454
]
422455
},
423456
{
@@ -438,7 +471,7 @@
438471
"1. One for `X`, `Y`, `T`\n",
439472
"2. and one for `longitude`, `latitude` and `time`.\n",
440473
"\n",
441-
"An error is raised if there are multiple `'X'` variables (for example)"
474+
"An error is raised if there are multiple `'X'` variables (for example)\n"
442475
]
443476
},
444477
{
@@ -469,16 +502,19 @@
469502
"source": [
470503
"## Feature: Rewriting arguments\n",
471504
"\n",
472-
"`cf_xarray` can rewrite arguments for a large number of xarray functions. By this I mean that instead of specifing say `dim=\"lon\"`, you can pass `dim=\"X\"` or `dim=\"longitude\"` and `cf_xarray` will rewrite that to `dim=\"lon\"` based on the attributes present in the dataset. \n",
505+
"`cf_xarray` can rewrite arguments for a large number of xarray functions. By\n",
506+
"this I mean that instead of specifing say `dim=\"lon\"`, you can pass `dim=\"X\"` or\n",
507+
"`dim=\"longitude\"` and `cf_xarray` will rewrite that to `dim=\"lon\"` based on the\n",
508+
"attributes present in the dataset.\n",
473509
"\n",
474-
"Here are a few examples"
510+
"Here are a few examples\n"
475511
]
476512
},
477513
{
478514
"cell_type": "markdown",
479515
"metadata": {},
480516
"source": [
481-
"### Slicing"
517+
"### Slicing\n"
482518
]
483519
},
484520
{
@@ -499,7 +535,8 @@
499535
"cell_type": "markdown",
500536
"metadata": {},
501537
"source": [
502-
"Slicing works will expand a single key like `X` to multiple dimensions if those dimensions are tagged with `axis: X`"
538+
"Slicing works will expand a single key like `X` to multiple dimensions if those\n",
539+
"dimensions are tagged with `axis: X`\n"
503540
]
504541
},
505542
{
@@ -520,7 +557,7 @@
520557
"cell_type": "markdown",
521558
"metadata": {},
522559
"source": [
523-
"### Reductions"
560+
"### Reductions\n"
524561
]
525562
},
526563
{
@@ -541,7 +578,7 @@
541578
"cell_type": "markdown",
542579
"metadata": {},
543580
"source": [
544-
"Expanding to multiple dimensions is also supported"
581+
"Expanding to multiple dimensions is also supported\n"
545582
]
546583
},
547584
{
@@ -563,7 +600,7 @@
563600
"cell_type": "markdown",
564601
"metadata": {},
565602
"source": [
566-
"### Plotting"
603+
"### Plotting\n"
567604
]
568605
},
569606
{
@@ -598,7 +635,7 @@
598635
"cell_type": "markdown",
599636
"metadata": {},
600637
"source": [
601-
"`cf_xarray` can facet"
638+
"`cf_xarray` can facet\n"
602639
]
603640
},
604641
{
@@ -619,7 +656,7 @@
619656
"cell_type": "markdown",
620657
"metadata": {},
621658
"source": [
622-
"### Resample & groupby"
659+
"### Resample & groupby\n"
623660
]
624661
},
625662
{
@@ -654,7 +691,7 @@
654691
"cell_type": "markdown",
655692
"metadata": {},
656693
"source": [
657-
"### Rolling & coarsen "
694+
"### Rolling & coarsen\n"
658695
]
659696
},
660697
{
@@ -680,16 +717,17 @@
680717
}
681718
},
682719
"source": [
683-
"``coarsen`` works but everything later will break because of xarray bug https://github.com/pydata/xarray/issues/4120\n",
720+
"`coarsen` works but everything later will break because of xarray bug\n",
721+
"https://github.com/pydata/xarray/issues/4120\n",
684722
"\n",
685-
"``ds.isel(lon=slice(50)).cf.coarsen(Y=5, X=10).mean()``"
723+
"`ds.isel(lon=slice(50)).cf.coarsen(Y=5, X=10).mean()`\n"
686724
]
687725
},
688726
{
689727
"cell_type": "markdown",
690728
"metadata": {},
691729
"source": [
692-
"## Feature: mix \"special names\" and variable names"
730+
"## Feature: mix \"special names\" and variable names\n"
693731
]
694732
},
695733
{
@@ -712,7 +750,8 @@
712750
"source": [
713751
"## Feature: Weight by Cell Measures\n",
714752
"\n",
715-
"`cf_xarray` can weight by cell measure variables `\"area\"` and `\"volume\"` if the appropriate attribute is set"
753+
"`cf_xarray` can weight by cell measure variables `\"area\"` and `\"volume\"` if the\n",
754+
"appropriate attribute is set\n"
716755
]
717756
},
718757
{

0 commit comments

Comments
 (0)