|
589 | 589 | "outputs": [], |
590 | 590 | "source": [ |
591 | 591 | "# make an output folder first\n", |
592 | | - "output_folder = Path('11-0output')\n", |
| 592 | + "output_folder = Path('11-output')\n", |
593 | 593 | "output_folder.mkdir(exist_ok=True)\n", |
594 | 594 | "\n", |
595 | 595 | "encoding={'prcp': {'zlib': True, # compression algorithm\n", |
|
966 | 966 | "source": [ |
967 | 967 | "### Write an xarray dataset to a raster\n", |
968 | 968 | "\n", |
969 | | - "Write part of the dataset out to a GeoTIFF. Note that rioxarray requires us to remove the `'grid_mapping'` attribute first (at least in version 0.15, you will get an error otherwise). `grid_mapping` is a variable from the original NetCDF dataset that specifies that coordinate reference information is contained in a variable called `'lambert_conformal_conic'` (we used it above to specify the coordinate reference information for **rioxarray**).\n", |
| 969 | + "Write part of the dataset out to a GeoTIFF. \n", |
| 970 | + "\n", |
| 971 | + "Earlier versions of rioxarray require us to remove the `'grid_mapping'` attribute first (at least in version 0.15, you will get an error otherwise). `grid_mapping` is a variable from the original NetCDF dataset that specifies that coordinate reference information is contained in a variable called `'lambert_conformal_conic'` (we used it above to specify the coordinate reference information for **rioxarray**).\n", |
970 | 972 | "\n", |
971 | 973 | "#### Write a single 2D timeslice to a raster" |
972 | 974 | ] |
|
978 | 980 | "outputs": [], |
979 | 981 | "source": [ |
980 | 982 | "precip_slice = ds.sel(time='2018-12-30')['prcp']\n", |
981 | | - "del precip_slice.attrs['grid_mapping']" |
| 983 | + "\n", |
| 984 | + "# remove grid_mapping if needed\n", |
| 985 | + "#del precip_slice.attrs['grid_mapping']" |
982 | 986 | ] |
983 | 987 | }, |
984 | 988 | { |
|
1005 | 1009 | "outputs": [], |
1006 | 1010 | "source": [ |
1007 | 1011 | "precip_slice = ds.sel(time=slice('2018-12-25', '2018-12-30'))['prcp']\n", |
1008 | | - "del precip_slice.attrs['grid_mapping']\n", |
| 1012 | + "\n", |
1009 | 1013 | "precip_slice.rio.to_raster(output_folder / 'pcrp_20181225-30.tif')" |
1010 | 1014 | ] |
1011 | 1015 | }, |
|
1097 | 1101 | "name": "python", |
1098 | 1102 | "nbconvert_exporter": "python", |
1099 | 1103 | "pygments_lexer": "ipython3", |
1100 | | - "version": "3.11.7" |
| 1104 | + "version": "3.11.9" |
1101 | 1105 | } |
1102 | 1106 | }, |
1103 | 1107 | "nbformat": 4, |
|
0 commit comments