-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preliminary outline for reading/writing docs #536
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,73 @@ | ||||||
# # Writing rasters to Disk | ||||||
|
||||||
# Rasters.jl supports writing datasets to disk in several differnt formats. grd files are | ||||||
# currently the only supported file format that does not require loading an extension. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
# All other formats are supported with the ArchGDAL and NCDatasets extensions. | ||||||
# Datasets can (with some caveats) be written to different formats than they were loaded | ||||||
# in as, providing file-type conversion for spatial data. | ||||||
|
||||||
# Some metadata may be lost in formats that store little metadata, or where | ||||||
# metadata conversion has not been completely implemented. | ||||||
|
||||||
# # create a Raster dataset for saving | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
using Rasters | ||||||
|
||||||
# specify the coodinate reference system [crs]. | ||||||
proj = "+proj=longlat +datum=WGS84 +no_defs +type=crs" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be wrapped in |
||||||
|
||||||
# define coodinate dimensions | ||||||
lon, lat = X(25:1:30), Y(25:1:30) | ||||||
|
||||||
# create a Raster | ||||||
ras = Raster(rand(lon, lat); crs=proj) # this generates random numbers with the dimensions given | ||||||
|
||||||
# # write Raster to a grd file | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
# Note: that even though grd is a build in format that should not imply that it is the | ||||||
# most suitable format for saving your data. | ||||||
filename = tempname() * ".grd" | ||||||
write(filename, ras) | ||||||
|
||||||
# # write Raster using GDAL[requires adding ArchGDAL.jl] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
# write(filename::AbstractString, A::AbstractRaster; kw...) | ||||||
# Write an AbstractRaster to file, guessing the backend from the file extension. | ||||||
# Keyword arguments are passed to the write method for the backend. | ||||||
|
||||||
using Pkg; | ||||||
Pkg.add("ArchGDAL"); | ||||||
using ArchGDAL | ||||||
|
||||||
# write Raster as a GeoTIFF | ||||||
filename = tempname() * ".tif" | ||||||
write(filename, ras) | ||||||
|
||||||
# write Raster as a cog (cloud optimized geotiff) by specifing the COG `driver`` | ||||||
filename = tempname() * ".tif" | ||||||
write(filename, ras, driver="COG") | ||||||
|
||||||
# you can also pass options to GDAL by passing a dictionary of options. See GDAL | ||||||
# specific driver options. [See options specific to the GOG diver.](https://gdal.org/drivers/raster/cog.html) | ||||||
# `force=true` is required to overwirte an exisiting file | ||||||
write(filename, ras, driver="COG", options=Dict("BLOCKSIZE" => "512", "RESAMPLING" => "NEAREST"), force=true) | ||||||
|
||||||
# See the [full list of GDAL drivers](https://gdal.org/drivers/raster/index.html) | ||||||
# for other supported formats. | ||||||
|
||||||
# # write Raster to a NetCDF file [requires adding NCDatasets.jl] | ||||||
Pkg.add("NCDatasets"); | ||||||
using NCDatasets | ||||||
|
||||||
filename = tempname() * ".nc" | ||||||
write(filename, ras) | ||||||
|
||||||
# # write Raster to a JDL2 file. | ||||||
|
||||||
# JLD2 saves and loads Julia data structures in a format comprising a subset of HDF5, | ||||||
# without any dependency on the HDF5 C library. The save and load functions, provided | ||||||
# by FileIO, provide a mechanism to read and write data from a JLD2 file. | ||||||
Pkg.add("FileIO"); | ||||||
using FileIO | ||||||
|
||||||
filename = tempname() * ".jld2" | ||||||
save(filename, ras) | ||||||
Comment on lines
+63
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be a bit leery of serializing rasters using JLD2, since it's not robust if anything in the stack changes (DD, DiskArrays, etc). Maybe we should add a warning that this is only suitable for extremely short term storage? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks good enough, we should think about incorporating this into the new docs structure. (read and write section of methods or tutorials if is a little bit longer) |
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.