@@ -49,6 +49,11 @@ We can save a Dataset to disk using the
49
49
50
50
.. ipython :: python
51
51
52
+ ds = xr.Dataset({' foo' : ((' x' , ' y' ), np.random.rand(4 , 5 ))},
53
+ coords = {' x' : [10 , 20 , 30 , 40 ],
54
+ ' y' : pd.date_range(' 2000-01-01' , periods = 5 ),
55
+ ' z' : (' x' , list (' abcd' ))})
56
+
52
57
ds.to_netcdf(' saved_on_disk.nc' )
53
58
54
59
By default, the file is saved as netCDF4 (assuming netCDF4-Python is
@@ -59,7 +64,7 @@ the ``format`` and ``engine`` arguments.
59
64
60
65
Using the `h5netcdf <https://github.com/shoyer/h5netcdf >`_ package
61
66
by passing ``engine='h5netcdf' `` to :py:meth: `~xarray.open_dataset ` can
62
- be quicker than the default ``engine='netcdf4' `` that uses the
67
+ sometimes be quicker than the default ``engine='netcdf4' `` that uses the
63
68
`netCDF4 <https://github.com/Unidata/netcdf4-python >`_ package.
64
69
65
70
@@ -171,8 +176,6 @@ will remove encoding information.
171
176
:suppress:
172
177
173
178
ds_disk.close()
174
- import os
175
- os.remove(' saved_on_disk.nc' )
176
179
177
180
.. _io.netcdf.writing_encoded :
178
181
@@ -459,11 +462,6 @@ module:
459
462
460
463
import pickle
461
464
462
- ds = xr.Dataset({' foo' : ((' x' , ' y' ), np.random.rand(4 , 5 ))},
463
- coords = {' x' : [10 , 20 , 30 , 40 ],
464
- ' y' : pd.date_range(' 2000-01-01' , periods = 5 ),
465
- ' z' : (' x' , list (' abcd' ))})
466
-
467
465
# use the highest protocol (-1) because it is way faster than the default
468
466
# text based pickle format
469
467
pkl = pickle.dumps(ds, protocol = - 1 )
@@ -523,6 +521,12 @@ To export just the dataset schema, without the data itself, use the
523
521
This can be useful for generating indices of dataset contents to expose to
524
522
search indices or other automated data discovery tools.
525
523
524
+ .. ipython :: python
525
+ :suppress:
526
+
527
+ import os
528
+ os.remove(' saved_on_disk.nc' )
529
+
526
530
.. _io.rasterio :
527
531
528
532
Rasterio
0 commit comments