Skip to content
Merged
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
2 changes: 2 additions & 0 deletions crates/assistant/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ fn search_commands(s: &Session, a: &Value) -> Result<Value, String> {
.iter()
// Internal plumbing the model has no use for.
.filter(|c| !matches!(c.id, "gp.finish" | "info.commands"))
// Commands of an extension the user turned off (#1752).
.filter(|c| s.extensions().blocks(c.id).is_none())
.filter_map(|c| {
let (id, label, loc, params) =
(c.id.to_lowercase(), c.label.to_lowercase(), c.location.to_lowercase(), c.params.to_lowercase());
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/src/cmd/cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ use super::ps;
use crate::{CmdResult, CommandSpec as C, Session};

pub fn commands() -> Vec<C> {
vec![C::new("cube.trend", "Trend Analysis", "Analyze › Image Analysis", trend_cmd).inputs(cube_inputs).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Network).with(crate::policy::Effect::Files)).params(
vec![C::new("cube.trend", "Trend Analysis", "Analyze › Workflows", trend_cmd).inputs(cube_inputs).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Network).with(crate::policy::Effect::Files)).params(
r#"{"cube"?: an entry of cube.catalog (its STAC API, collection, band, cell size and cloud cap, or its Zarr store and variable) | "layers"?: [raster layers, a date each; one on another grid is resampled (nearest) onto the first's] | "layer"?: a Zarr layer (or "path" | "url", "variable", "index", "crs" as for zarr.reduce) or a raster of several bands, a date each (default: the active layer) | "collection": a STAC collection (desktop; read in place over an area, in pieces when large; with url, asset, bbox, maxCloud, cellSize and resampling below, and "start", "end"), "url"?: the collection's STAC API (as for stac.addCube), "asset"?: the collection's band, such as NDVI, "bbox"?: [w, s, e, n] | "view" (the collection's area), "maxCloud"?: a collection's cloud cover cap, "cellSize"?: a collection's cell size in the files' units (the overview level nearest it is read), "resampling"?: "nearest" (default: that overview's pixels as stored) | "average" (each cell the mean of the full images' pixels in it, which reads them), "band"?: 1-based (a stack's band), "dates"?: [dates] (a stack's or the bands' dates, in their order; default: read from the layers' names or files, or the bands' names), "start"?, "end"?: dates (a whole number from 1000 to 9999 is a year; an end given as a year or a month takes all of it), "months"?: [1–12] (one season across years), "test"?: "hamedRao" (default) | "yueWang" | "seasonal" | "original", "seasons"?: parts of a year for the seasonal test (default 12), "alpha"?: 0.05 (above 0, below 0.5), "minValid"?: dates a cell needs (default: half of them, at least 4; the seasonal test also needs 4 in seasons of two or more), "per"?: "year" (default) | "decade", "name"?: text, "ran"?: (internal: a trend the app has worked out)} → four raster layers: Sen's slope, the test's Z and p-value, and the slope where p < alpha"#,
),
C::new("cube.reduce", "Summarise a Data Cube over Time", "Analyze › Image Analysis", reduce_cmd).inputs(cube_inputs).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Network).with(crate::policy::Effect::Files)).params(
C::new("cube.reduce", "Summarise a Data Cube over Time", "Analyze › Workflows", reduce_cmd).inputs(cube_inputs).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Network).with(crate::policy::Effect::Files)).params(
r#"{"cube"?: an entry of cube.catalog (as for cube.trend) | "layers"?: [raster layers, a date each; one on another grid is resampled (nearest) onto the first's] | "layer"?: a Zarr layer or a raster of several bands, a date each (default: the active layer) | "path"?: a Zarr store's folder | "url"?: a Zarr store's address, or a STAC collection's API (as for stac.addCube) | "collection": a STAC collection (desktop; read in place over an area, in pieces when large; with url, asset, bbox, maxCloud, cellSize and resampling below, and "start", "end"), "variable"?, "index"?, "crs"?: a Zarr variable's (as for zarr.reduce), "asset"?: the collection's band, such as NDVI, "bbox"?: [w, s, e, n] | "view" (the collection's area), "maxCloud"?: a collection's cloud cover cap, "cellSize"?: a collection's cell size in the files' units (the overview level nearest it is read), "resampling"?: "nearest" (default) | "average" (as for cube.trend), "band"?: 1-based (a stack's band), "dates"?: [dates] (a stack's or the bands' dates, in their order; default: read from the layers' names or files, or the bands' names), "stat": "mean"|"min"|"max"|"sum"|"std" (the population standard deviation, n)|"count"|"countAbove"|"mode" or "majority" (a categorical cube's most frequent class; the least of those tied)|"modeCount" (how many dates had the mode)|"variety" (how many classes)|"changes" (how many times the class changed from one valued date to the next)|"longestRun" (the class of the longest run of dates in one class; the least of those tied)|"longestRunLength" (how many dates that run lasted)|"frequency" (a layer for each class met: its count of dates)|"countIn" (how many dates in the classes given), "above"?: number (countAbove's threshold), "classes"?: [whole numbers 0–255, at most 256] (countIn's classes), "by"?: "all" (default: one layer) | "year" (a layer for each calendar year) | "month" (a layer for each month of the year, across years), "start"?, "end"?: dates (as for cube.trend), "months"?: [1–12] (a season across years), "minValid"?: 0–1 (a cell with a smaller share of its group's dates is left empty; default 0), "name"?: text} → raster layers of the statistic, one for each group (frequency: one for each class of each group)"#,
)]
}
Expand Down
14 changes: 7 additions & 7 deletions crates/engine/src/cmd/deeplearning.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Analyze › Image Classification (Deep Learning Tools), Publish › Package (Deep Learning) and
//! Analyze › Imagery Sharing (Create Hosted Imagery): neural-network pixel classification with models kept
//! Imagery › Image Classification (Deep Learning Tools), Publish › Package (Deep Learning) and
//! Imagery › Imagery Sharing (Create Hosted Imagery): neural-network pixel classification with models kept
//! in the project and shared as packages, and rasters cut into web map tiles.

use std::collections::HashMap;
Expand Down Expand Up @@ -62,7 +62,7 @@ fn need_model(s: &Session) -> Option<&'static str> {

pub fn commands() -> Vec<C> {
vec![
C::new("dl.train", "Train Deep Learning Model", "Analyze › Image Classification", |s, p| {
C::new("dl.train", "Train Deep Learning Model", "Imagery › Image Classification", |s, p| {
let (m, unread) = train(s, p)?;
unread.say(s);
let mut r = json!({"model": m.name, "accuracy": m.accuracy, "classes": m.model.classes, "epochs": m.epochs});
Expand All @@ -72,7 +72,7 @@ pub fn commands() -> Vec<C> {
}).inputs(training_inputs).roles(&[]).effects(crate::policy::Effects::NONE)
.when(need_raster)
.params(r#"{"layer": raster, "training": polygon layer, "classField": field naming each polygon's class, "bands"?: [1-based], "hidden"?: [units per hidden layer] (default [32, 16]), "epochs"?: 1..500 (default 60), "model"?: name}"#),
C::new("dl.classify", "Deep Learning Tools", "Analyze › Image Classification", classify).inputs(classify_inputs).roles(&[]).effects(crate::policy::Effects::NONE).when(need_raster).params(
C::new("dl.classify", "Deep Learning Tools", "Imagery › Image Classification", classify).inputs(classify_inputs).roles(&[]).effects(crate::policy::Effects::NONE).when(need_raster).params(
r#"{"layer": raster, "model"?: a trained model's name, "training"?: polygon layer, "classField"?: field, "bands"?: [1-based], "hidden"?: [units], "epochs"?: 1..500 (without a model: train one first, as dl.train), "name"?: output, "ran"?: (internal: classes the app has worked out)}"#,
),
C::new("dl.package", "Deep Learning Package", "Publish › Package", |s, p| {
Expand All @@ -84,7 +84,7 @@ pub fn commands() -> Vec<C> {
.view()
.when(need_model)
.params(r#"{"model"?: name (default: the last trained), "path": "*.rgisdlpk"}"#),
C::new("dl.import", "Import Deep Learning Package", "Analyze › Image Classification", |s, p| {
C::new("dl.import", "Import Deep Learning Package", "Imagery › Image Classification", |s, p| {
let bytes = read_bytes(p)?;
// Only the model is inflated, whatever else the package holds.
let entries = rustgis_data::zip::read_matching(&bytes, |n| n == "model.json")?;
Expand All @@ -110,14 +110,14 @@ pub fn commands() -> Vec<C> {
Ok(json!({"model": name}))
}).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files))
.params(r#"{"path"?: "*.rgisdlpk", "data"?: base64}"#),
C::new("dl.remove", "Delete Model", "Analyze › Image Classification", |s, p| {
C::new("dl.remove", "Delete Model", "Imagery › Image Classification", |s, p| {
let i = model_index(s, p)?;
s.project.dl_models.remove(i);
Ok(Value::Null)
}).roles(&[]).effects(crate::policy::Effects::NONE)
.when(need_model)
.params(r#"{"model": name}"#),
C::new("imagery.hostedImagery", "Create Hosted Imagery", "Analyze › Imagery Sharing", hosted).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)).view().when(need_raster).params(
C::new("imagery.hostedImagery", "Create Hosted Imagery", "Imagery › Imagery Sharing", hosted).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)).view().when(need_raster).params(
r#"{"layer": raster, "path": "*.zip" (z/x/y.png tiles, tiles.json and a viewer page), "minZoom"?: 0..22, "maxZoom"?: 0..22 (default: the raster's resolution)}"#,
),
]
Expand Down
49 changes: 49 additions & 0 deletions crates/engine/src/cmd/extensions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! Extensions (#1752): list them, and turn them on or off. See [`crate::extensions`].

use serde_json::{Value, json};

use super::{bool_value, ps};
use crate::{CmdResult, CommandSpec as C, Session};

pub fn commands() -> Vec<C> {
use crate::policy::{Effect, Effects};
vec![
// Listing reads nothing of the user's and changes nothing; turning one on or off is
// Reserved, as `plugin.enable` is.
C::new("extension.list", "Extensions", "Plugins › Extensions", list).roles(&[]).effects(Effects::NONE).view(),
C::new("extension.enable", "Enable Extension", "Plugins › Extensions", enable)
.roles(&[])
.effects(Effects::NONE.with(Effect::Reserved))
.view()
.params(r#"{"id": extension id (see extension.list), "enabled"?: bool (default true)}"#),
C::new("extension.disable", "Disable Extension", "Plugins › Extensions", disable)
.roles(&[])
.effects(Effects::NONE.with(Effect::Reserved))
.view()
.params(r#"{"id": extension id (see extension.list)}"#),
]
}

fn list(s: &mut Session, _: &Value) -> CmdResult {
Ok(s.extensions().list())
}

fn enable(s: &mut Session, p: &Value) -> CmdResult {
// Text that isn't clearly true or false is refused, not read as false: it would turn a whole
// part of RustGIS off.
let on = match p.get("enabled") {
None | Some(Value::Null) => true,
Some(v) => bool_value(v).ok_or("enabled must be true or false")?,
};
set(s, p, on)
}

fn disable(s: &mut Session, p: &Value) -> CmdResult {
set(s, p, false)
}

fn set(s: &mut Session, p: &Value, on: bool) -> CmdResult {
let id = ps(p, "id").map(str::trim).filter(|id| !id.is_empty()).ok_or("id is required (see extension.list)")?;
let e = s.set_extension(id, on)?;
Ok(json!({"id": e.id, "name": e.name, "enabled": on, "tab": e.tab}))
}
Loading
Loading