{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/ringsaturn/xue/blob/main/docs/schemas/store-array.schema.json",
  "title": "StoreArray",
  "description": "An array's zarr.json in a store of the Xue Zarr profile (docs/zarr-profile.md, \"Array metadata\", \"Array attributes\", \"Coordinates\", and the polar, network and column branches): a variable array of uint8 codes (uint16 on a series store's widened variable, docs/zarr-profile.md \"Series store\", and on a column store's surface array cut from one, \"Column store\"), carrying the xue, xue_polar, xue_network or xue_columns block that says what its codes mean, or a coordinate or side array, or the scalar crs array of a projected grid (shape []; zarr.json only, no chunk). The readers' own checks on a variable array: that it is uint8, or uint16 on a grid store's series array or a column store's surface array only; that it carries exactly one sharding_indexed codec whose inner chain is [bytes, zstd] or [xue.delta{axis: 0}, bytes, zstd] and whose index chain is [bytes little-endian, crc32c]; that the inner bytes codec is little-endian, which a uint8 array may leave unsaid; that fill_value is the variable's nodataCode and every code of its quantization fits the data_type; and that the outer chunk is whole inner chunks.",
  "type": "object",
  "required": ["zarr_format", "node_type", "shape", "data_type", "chunk_grid", "chunk_key_encoding", "fill_value", "codecs"],
  "properties": {
    "zarr_format": {"type": "integer", "const": 3},
    "node_type": {"type": "string", "const": "array"},
    "shape": {"description": "Empty on the scalar crs array, which reads as its fill value.", "type": "array", "items": {"type": "integer", "minimum": 0}},
    "data_type": {"type": "string", "enum": ["uint8", "uint16", "int32", "int64", "float32", "float64"]},
    "chunk_grid": {
      "type": "object",
      "required": ["name", "configuration"],
      "properties": {
        "name": {"type": "string", "const": "regular"},
        "configuration": {
          "type": "object",
          "required": ["chunk_shape"],
          "properties": {"chunk_shape": {"type": "array", "items": {"type": "integer", "minimum": 1}}}
        }
      }
    },
    "chunk_key_encoding": {
      "type": "object",
      "required": ["name"],
      "properties": {
        "name": {"type": "string", "const": "default"},
        "configuration": {"type": "object", "properties": {"separator": {"type": "string", "const": "/"}}}
      }
    },
    "fill_value": {
      "description": "A code (the nodataCode, or 0 on a polar array) on a variable array; a number or \"NaN\" on a coordinate.",
      "anyOf": [{"type": "number"}, {"type": "string", "const": "NaN"}]
    },
    "codecs": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/Codec"}},
    "attributes": {"$ref": "#/$defs/Attributes"},
    "dimension_names": {"type": "array", "items": {"type": "string", "minLength": 1}}
  },
  "$defs": {
    "Codec": {
      "type": "object",
      "required": ["name"],
      "properties": {
        "name": {"type": "string", "enum": ["sharding_indexed", "bytes", "zstd", "crc32c", "xue.delta"]},
        "configuration": {
          "type": "object",
          "properties": {"endian": {"description": "The bytes codec's order: little-endian throughout the profile, and absent from a uint8 array's inner chain.", "type": "string", "const": "little"}}
        }
      }
    },
    "Attributes": {
      "description": "A variable array of a grid store carries xue, of a polar store xue_polar, of a network store xue_network, of a column store xue_columns; a coordinate carries its CF attributes only. On a projected grid a variable array also names the crs array in grid_mapping, and the crs array carries the CF projection attributes.",
      "type": "object",
      "properties": {
        "xue": {"$ref": "#/$defs/GridArrayBlock"},
        "xue_polar": {"$ref": "#/$defs/PolarArrayBlock"},
        "xue_network": {"$ref": "#/$defs/NetworkArrayBlock"},
        "xue_columns": {"$ref": "#/$defs/ColumnArrayBlock"},
        "scale_factor": {"type": "number"},
        "add_offset": {"type": "number"},
        "_FillValue": {"description": "The nodataCode, as fill_value; above 255 on a uint16 array only: a series store's widened variable, or a column store's surface array cut from one.", "type": "integer", "minimum": 0, "maximum": 65535},
        "flag_values": {"type": "array", "items": {"type": "integer", "minimum": 0, "maximum": 255}},
        "flag_meanings": {"type": "string"},
        "units": {"type": "string"},
        "calendar": {"type": "string"},
        "standard_name": {"type": "string"},
        "positive": {"description": "A column store's level coordinate: pressure falls upwards.", "type": "string", "const": "down"},
        "long_name": {"type": "string"},
        "grid_mapping": {"type": "string", "const": "crs"},
        "grid_mapping_name": {"type": "string", "const": "lambert_conformal_conic"},
        "latitude_of_projection_origin": {"type": "number"},
        "longitude_of_central_meridian": {"type": "number"},
        "standard_parallel": {"type": "array", "minItems": 1, "maxItems": 2, "items": {"type": "number"}},
        "earth_radius": {"type": "number", "exclusiveMinimum": 0},
        "crs_wkt": {"type": "string", "minLength": 1}
      }
    },
    "GridArrayBlock": {
      "description": "A grid store's variable array: the bundle it belongs to (on a shared store only), that variable's entry of the bundle's variables, copied, and its predictor. Every writer writes variable and predictor; a reader takes the variable from the group and decodes by the codec chain, so it needs neither.",
      "type": "object",
      "properties": {
        "bundle": {"type": "string", "pattern": "^[a-z][a-z0-9]*$"},
        "variable": {"$ref": "bundle-metadata.schema.json#/$defs/Variable"},
        "predictor": {"description": "Informational: decoding follows the codec chain.", "type": "string", "enum": ["previous", "raw"]}
      }
    },
    "NetworkArrayBlock": {
      "description": "A network store's data array: the variable as the group's xue_network block lists it.",
      "type": "object",
      "required": ["variable"],
      "properties": {"variable": {"$ref": "#/$defs/NetworkVariable"}}
    },
    "ColumnArrayBlock": {
      "description": "A column store's data array: its id, which the group's xue_columns block describes it by.",
      "type": "object",
      "required": ["array"],
      "properties": {"array": {"type": "string", "pattern": "^[a-z][a-z0-9]*$"}}
    },
    "NetworkVariable": {
      "description": "A network store's variable: a bundle variable without a GRIB2 identity.",
      "type": "object",
      "required": ["numericId", "id", "label", "unit", "quantization"],
      "properties": {
        "numericId": {"type": "integer", "minimum": 1, "maximum": 255},
        "id": {"type": "string", "minLength": 1},
        "label": {"type": "string"},
        "unit": {"type": "string"},
        "quantization": {"$ref": "bundle-metadata.schema.json#/$defs/Quantization"}
      }
    },
    "PolarArrayBlock": {
      "description": "A polar store's data array: the variable with its source's codebook and reserved codes, and the beam and gate geometry.",
      "type": "object",
      "required": ["variable", "geometry"],
      "properties": {
        "variable": {"$ref": "#/$defs/PolarVariable"},
        "geometry": {"$ref": "#/$defs/PolarGeometry"}
      }
    },
    "PolarVariable": {
      "type": "object",
      "required": ["id", "label", "unit", "quantization", "reservedCodes"],
      "properties": {
        "id": {"type": "string", "pattern": "^[a-z][a-z0-9]*$"},
        "label": {"type": "string"},
        "unit": {"type": "string"},
        "quantization": {"$ref": "#/$defs/PolarQuantization"},
        "reservedCodes": {
          "description": "Code (as a decimal string) to the state it carries in place of a value.",
          "type": "object",
          "additionalProperties": {"type": "string", "pattern": "^[a-z][a-z_]*$"}
        },
        "signConvention": {"type": "string", "const": "positive_away"}
      }
    },
    "PolarQuantization": {
      "description": "value = code x scale + offset for minimumCode <= code <= maximumCode.",
      "type": "object",
      "required": ["type", "offset", "scale", "minimumCode", "maximumCode"],
      "properties": {
        "type": {"type": "string", "const": "linear"},
        "offset": {"type": "number"},
        "scale": {"type": "number", "exclusiveMinimum": 0},
        "minimumCode": {"type": "integer", "minimum": 0, "maximum": 255},
        "maximumCode": {"type": "integer", "minimum": 0, "maximum": 255}
      }
    },
    "PolarGeometry": {
      "description": "Beam j covers azimuths [azimuthStart + j azimuthStep, ...) degrees clockwise from true north; gate i covers slant ranges [rangeStart + i rangeStep, ...) km.",
      "type": "object",
      "required": ["azimuthStart", "azimuthStep", "rangeStart", "rangeStep"],
      "properties": {
        "azimuthStart": {"type": "number"},
        "azimuthStep": {"type": "number", "exclusiveMinimum": 0},
        "rangeStart": {"type": "number", "minimum": 0},
        "rangeStep": {"type": "number", "exclusiveMinimum": 0}
      }
    }
  }
}
