Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ nav:
- "Home": "index.md"
- "Quick start" : "scripts/generated/basics/first_raster.md"
- "User Guide":
- "Data Sources" : "scripts/generated/basics/data_sources.md"
- "Reading" : "scripts/generated/basics/reading.md"
- "Writing" : "scripts/generated/basics/writing.md"
- "Methods" : "scripts/generated/basics/methods.md"
- "Arrays operations" : "scripts/generated/basics/array_operations.md"
- "Examples and Plotting" : "scripts/generated/basics/plotting.md"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# # Data sources
# # Reading data into Rasters

# Rasters.jl uses a number of backends to load raster data. `Raster`, `RasterStack`
# and `RasterSeries` will detect which backend to use for you, automatically.
Expand Down Expand Up @@ -46,16 +46,6 @@
#md # smapseries
#md # ```

# ## Writing file formats to disk

# Files can be written to disk in all formats other than SMAP HDF5 using
# `write("filename.ext", A)`. See the docs for [`write`](@ref). They 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.

# ## RasterDataSources.jl integration

# [RasterDataSources.jl](https://github.com/EcoJulia/RasterDataSources.jl)
Expand Down
73 changes: 73 additions & 0 deletions docs/scripts/basics/writing.jl
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Rasters.jl supports writing datasets to disk in several differnt formats. grd files are
# Rasters.jl supports writing datasets to disk in several different formats. `.grd` files are

# currently the only supported file format that does not require loading an extension.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# currently the only supported file format that does not require loading an extension.
# supported with no extra steps, but all others require loading an extension.

# 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# # create a Raster dataset for saving
# # Create a Raster to save

using Rasters

# specify the coodinate reference system [crs].
proj = "+proj=longlat +datum=WGS84 +no_defs +type=crs"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be wrapped in GFT.ProjString


# 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# # write Raster to a grd file
# # Write Raster to a `.grd` file

# 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]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# # write Raster using GDAL[requires adding ArchGDAL.jl]
# # Write Raster using GDAL (requires ArchGDAL.jl)


# 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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)


Loading