Query and fetching datasets
Query datasets
candidates = VCDataSets.query(category=nothing, source=nothing,
name=nothing, filename=nothing)
candidates = VCDataSets.query(filename="bunny.off")
candidates = VCDataSets.query(name="bunny")
candidates = VCDataSets.query(name=:bunny)
for d in VCDataSets.query(category="geometry")
@show(d)
end
for d in VCDataSets.query(category="flow/netcdf")
@show(d)
end
VCDataSets.query
returns a potentially empty Vector
of datasets, which math the search criteria.
Fetch a dataset
path = VCDataSets.withdir("./data") do
path1 = VCDataSets.file(name=:bunny)
candidates = VCDataSets.query(name="bunny")
path2 = VCDataSets.file(candidates)
@assert path1 == path2
@assert isfile(path1)
@assert VCDataSets.indirs("./data")
path1
end
# open file in path
VCDataSets.file
returns the path to a data file that is fetched from an external source if it is not present inVCDataSets.dirs
.VCDataSets.withdir!
callsVCDataSets.pushdir!
and reverts the change todirs()
. Use this method to changedirs()
temporarily.VCDataSets.dirs
stores the search path for files on local storage. A file is fetched only if it is not present indirs()
. In this case, the downloaded file is stored indirs()[end]
, i.e., the last path provided toVCDataSets.pushdir!
.- Use
VCDataSets.indirs
to check if a path is contained indirs()
.
VCDataSets.file
provides the option force=true
to enforce a download.
Fetch into a specific file
thisfile("mydir/bunny.off") == "mydir/bunny.off"
thisfile("mydir/data.off", "bunny.off") == "mydir/data.off"
thisfile("mydir/data.off", query(...)) == "mydir/data.off"
thisfile("mydir/bunny.off"[, ...; force=true, copy=false) == "mydir/bunny.off"
VCDataSet.thisfile
is like VCDataSets.file
but stores the dataset in path
: dirs
is only relevant for copying an already downloaded file from local storage (unless copy=false
).
VCDataSets.DataSet
— TypeInternal specification of a dataset
VCDataSets.add
— MethodAdd dataset to database.
See also query
VCDataSets.dirs
— Methodlist = dirs()
Get list of directories where datasets are stored. Data that is not present in any of dirs()
and needs to be fetched from a source is stored in dirs()[end]
.
VCDataSets.ensuredir
— Methoddir = ensuredir(dir)
Helper that creates dir
if it doesn't exist.
VCDataSets.indirs
— MethodVCDataSets.pushdir!
— Methodpushdir!(path[; absolute=false])
Push path
onto dirs
and make it the current path for stroring data that needs to be fetched.
Make sure path
is an abosulte path ifabsolute=true
, otherwise relative paths can be pushed!
pushdir!
always pushes and does not check if a path already exists in dirs
.
VCDataSets.query
— Methodlist = query(category=nothing, source=nothing,
name=nothing, filename=nothing)
Example
content = read(open(file(first(query(name=:bunny)))), String)
Query database for a dataset and return a potentially empty list of candidates.
See also file
VCDataSets.thisfile
— Functiondataset = query(...)
path = thisfile(path; dataset=dataset[; force=false, copy=true)
path = thisfile(path[; force=false, copy=true,
filename=basename(path), name=nothing,
category=nothing, source=nothing])
Similar to file
but store file in path
. The dataset is specified either by dataset = query(...)
or by name
, category
, source
, and filename
as for query
.
The default filename
is the basename(path)
if path
is not a directory. If a different filename
is used to specify the dataset, the data is still saved to the file given as path
!.
If path
refers to a directory, the filename is determined from the dataset.
The returned path
is either identical to the input path
, or the filename is joined if isdir(path)
. I.e., the returned path is can be a relative path (other than for file
.
As for [file
(@ref), force=true
enforces a download from the external source.
If copy=true
, the file is not downloaded by copied from local dirs
if available.
dirs
is relevant only for copy
ing a file, not for storing a downloaded file!
VCDataSets.withdir
— Methodwithdir(path) do
@path == dirs()[end]
end
Apply pushdir!
with path
temporarily while evaluating the given function.
The method returns the value returned by f
, i.e., f
may just return the path.