provider
Stable type · Providers
Tier: stable · Kind: type · Topic: Providers
| Python | Julia | Rust |
|---|---|---|
Provider | Provider | Provider |
Python
class Provider
Provider(loader: DataSource, cache: Cache, window: Optional[Window] = None, *, formats: Optional[Registry] = None)
Provider.is_const: bool # property
Provider.coords: Dict[str, NativeField] # property
Provider.materialize(select: Optional[Any] = None) -> NativeDataset
Provider.refresh(t: _dt.datetime, select: Optional[Any] = None) -> NativeDataset
Provider.supports_selection: bool # property
Provider.store_backed: bool # property
Provider.array_shape(var: str) -> Optional[Tuple[int, ...]]
Provider.refresh_times() -> List[_dt.datetime]
Provider.prefetch(window: Optional[Window] = None) -> List[CacheEntry]
A loader-bound provider of native-grid arrays, refreshed at the loader’s cadence. See the module docstring for the CONST/DISCRETE contract.
Parameters
loader(DataSource) — TheDataSourcethis provider serves.cache(Cache) — The content-addressedCache(component (a)).window(Optional[Window]) — Optional run window(start, end)boundingrefresh_times/prefetchand primingmaterializefor a DISCRETE loader.formats(Optional[Registry]) — The format registry to resolve the reader from (defaults to the globalformat_registry) — the seam that lets a new format plug in with no Provider change.Raises,registered
Members
is_const— True if the bound loader is time-invariant (CONST).coords— Native coordinates of the current buffer (lat/lon/…); empty until the firstmaterialize/refresh.materialize— Materialize the loader’s native arrays into the buffer and return them.refresh— Refresh the buffer to the cadence anchor for timetand return it.supports_selection— True when the bound reader can honour an orthogonalselectwithout materialising the whole array. A caller uses this to decide whether to push a projection down (materialize(..., select=…)) or to read whole and slice on its own side.store_backed— True when the bound reader reads a directory-like STORE (a Zarr v2 store, each object its own fetch) rather than one blob. Read withsupports_selectionit tells a caller whether a pushed-downselectshrinks the DOWNLOAD or only the decode.array_shape— The full native (dims-order) shape of on-disk arrayvar, for a honour/refuse pushdown decision, orNone.refresh_times— The cadence anchors at which the data changes and the solver mustrefresh— the solver tstops.prefetch— Warm the cache for every file the provider will need, WITHOUT decoding.
Example (provider)
source = DataSource(
"stations",
"csv", # the format-registry key that selects the reader
(FIXTURES / "stations.csv").as_uri(),
variables=["value", "location_id"],
reader_kwargs={"numeric_columns": ["latitude", "longitude", "value"]},
)
data = Provider(source, cache).materialize()
assert isinstance(data, NativeDataset)
assert data.variable_names() == ["location_id", "value"]
assert data["value"].data.dtype == np.float64
assert list(data["value"].data) == [152.3, 168.7, 98.1, 110.4]
# Digit-only text columns stay strings: nothing is inferred.
assert data["location_id"].data == ["1", "1", "2", "2"]
Julia
struct Provider
Provider(cache::Cache, format::String, cadence::Cadence, times::Vector{Float64}, url_for::Function, time_dim::Union{Nothing, String}, variables::Union{Nothing, Vector{String}}, reader_kwargs::Dict{Symbol, Any}, source_loader::Union{Nothing, String}, auth_realm::Union{Nothing, String}, records_per_sample::Union{Nothing, Int64})
Provider(cache, format, cadence, times, url_for, time_dim, variables, reader_kwargs, source_loader, auth_realm, records_per_sample)
Provider(cache::Cache, url; format, cadence, times, time_dim, variables, reader_kwargs, source_loader, auth_realm, records_per_sample)
Provider(cache, url; format, cadence=CONST, times=Float64[], time_dim=nothing,
variables=nothing, reader_kwargs=NamedTuple(),
source_loader=nothing, auth_realm=nothing)
A data provider over the shared cache.
url— a resolved-URLString(constant source) OR a functiont -> url(a time-varying source whose file/key changes per tick).format— reader name in [FORMAT_REGISTRY] ("netcdf","csv", …).cadence— [CONST] or [DISCRETE].DISCRETErequires non-emptytimes;CONSTrequires emptytimes.times— the discrete cadence grid (sorted on construction); what [refresh_times] returns. It may span MANY files: pair it with at -> urlresolver and the cadence walks from one file to the next (seetime_dim).time_dim— when set on aDISCRETEprovider whose files hold the cadence on an internal axis (e.g. a daily file of hourly steps), [materialize](p, t)slices that dimension to the tick’s record.The record is located WITHIN its file, not within the whole cadence: tick
iis recordmod1(i, L)of the file the resolver returns for it, whereLis that file’s length alongtime_dim. So a cadence of 56 three-hourly ticks over seven 8-record daily files reads record 1 of day 2 at tick 9, not record 9 of day 1 (which does not exist). A single file holding the whole cadence is theL >= length(times)case, wheremod1is the identity — the behaviour is unchanged. This assumes files are UNIFORM in length and that their records are consecutive on the cadence; a short/trimmed file mid-run shifts every later tick (the Python track avoids that by matching the file’s own decoded time axis, which the Julia track cannot do becausetimesis a caller-defined grid rather than the file’s raw axis).records_per_sample—nothingor1(default) returns the SINGLE at-or-before record withtime_dimDROPPED (held piecewise-constant);2returns the TWO bracketing records (floor + successor) withtime_dimRETAINED at length 2 and a canonical 2-elementtime_dimcoordinate of Unix epoch seconds, so a downstream model interpolates in time.2requires atime_dim; the successor is read across a file boundary when needed, and at the last cadence tick the bracket degenerates to[last, last](equal timestamps) so the downstream weight clamps. The provider does pure I/O (returns N records) and performs no interpolation itself.variables— restrict the returned data variables (coords always kept);nothingreturns all.reader_kwargs— extra keywords forwarded to [read_native] (e.g. the CSV reader’snumeric_columns).source_loader/auth_realm— recorded in the cache manifest on fetch.
Example (provider)
url = "file://" * abspath(joinpath(FIXTURES, "stations.csv"))
p = const_provider(cache, url; format = "csv", source_loader = "stations",
variables = ["value", "location_id"],
reader_kwargs = (numeric_columns = ["latitude", "longitude", "value"],))
@assert is_const(p) && refresh_times(p) == Float64[] # a CONST provider never refreshes
data = materialize(p)
@assert data isa NativeDataset
@assert Set(variable_names(data)) == Set(["location_id", "value"])
@assert data["value"].data == [152.3, 168.7, 98.1, 110.4]
# Digit-only text columns stay strings: nothing is inferred.
@assert data["location_id"].data == ["1", "1", "2", "2"]
Rust
pub struct Provider {
/* private fields */
}
impl Provider { pub fn new(loader: DataSource, cache: Arc<Cache>, window: Option<Window>) -> Result<Self> }
impl Provider { pub fn with_formats(loader: DataSource, cache: Arc<Cache>, window: Option<Window>, formats: &FormatRegistry) -> Result<Self> }
impl Provider { pub fn coords(&self) -> &HashMap<String, Coord> }
impl Provider { pub fn supports_selection(&self) -> bool }
impl Provider { pub fn store_backed(&self) -> bool }
impl Provider { pub fn array_shape(&self, var: &str) -> Result<Option<Vec<usize>>> }
impl Provider { pub fn store_access(&self) -> StoreAccess }
impl Provider { pub fn materialize(&mut self) -> Result<HashMap<String, NativeField>> }
impl Provider { pub fn materialize_with_select(&mut self, sel: Option<&Selection>) -> Result<HashMap<String, NativeField>> }
impl Provider { pub fn refresh(&mut self, t: OffsetDateTime) -> Result<Option<HashMap<String, NativeField>>> }
impl Provider { pub fn refresh_with_select(&mut self, t: OffsetDateTime, sel: Option<&Selection>) -> Result<Option<HashMap<String, NativeField>>> }
impl Provider { pub fn refresh_times(&self) -> Vec<f64> }
impl Provider { pub fn prefetch(&mut self, window: Window) -> Result<()> }
A loader-bound provider of native-grid arrays, refreshed at the loader’s cadence. See the module-level documentation for the CONST/DISCRETE contract.