canvod.adapters API reference¶
Interfaces¶
Interfaces of the adapters, one per kind of data canvodpy exchanges.
A tool implements the interfaces of the data it exchanges with canvodpy, and only those. Everything entering canvodpy is checked against canvodpy's own contract for that kind of data:
- observations: :func:
canvod.readers.validate_dataset, the contract of every canvodpy reader. Observations are imported with a reader of the tool's files, a :class:canvod.readers.GNSSDataReader. - VOD: :func:
canvod.readers.validate_vod_dataset, the contract of VOD calculator output and of the VOD store.
A subclass converts; checking the result and recording provenance is done here, the same for every tool.
ObservationsAdapter
¶
Bases: _Adapter, ABC
Observations: the tool's observation files <-> canvodpy observations.
reader(path)
abstractmethod
¶
A canvodpy reader of one of the tool's observation files.
convert_from_canvodpy(obs_ds)
abstractmethod
¶
canvodpy observations in the tool's data structure.
save(tool_ds, path)
abstractmethod
¶
Write a dataset in the tool's data structure to its file format.
import_file(path, keep_data_vars=None)
¶
Read one of the tool's observation files as canvodpy observations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path or str
|
The tool's observation file. |
required |
keep_data_vars
|
list of str
|
Data variables to keep and require; |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
canvodpy observations with provenance attributes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the result does not meet the observations contract. |
export_file(obs_ds, path, source)
¶
Write canvodpy observations as one of the tool's files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obs_ds
|
Dataset
|
canvodpy observations. |
required |
path
|
Path or str
|
File to write. |
required |
source
|
str
|
What |
required |
Returns:
| Type | Description |
|---|---|
Path
|
|
VodAdapter
¶
Bases: _Adapter, ABC
VOD: the tool's VOD files <-> canvodpy VOD.
open(path)
abstractmethod
¶
Read one of the tool's VOD files in its own data structure.
save(tool_ds, path)
abstractmethod
¶
Write a dataset in the tool's data structure to its file format.
convert_to_canvodpy(tool_ds)
abstractmethod
¶
VOD in the tool's data structure as canvodpy VOD.
convert_from_canvodpy(vod_ds)
abstractmethod
¶
canvodpy VOD in the tool's data structure.
import_dataset(tool_ds, source)
¶
The tool's VOD as canvodpy VOD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_ds
|
Dataset
|
VOD in the tool's data structure. |
required |
source
|
str
|
What |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
canvodpy VOD with provenance attributes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the result does not meet the VOD dataset contract. |
import_file(path)
¶
Read one of the tool's VOD files as canvodpy VOD.
See :meth:import_dataset.
export_dataset(vod_ds, source)
¶
canvodpy VOD in the tool's data structure, with provenance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vod_ds
|
Dataset
|
canvodpy VOD. |
required |
source
|
str
|
What |
required |
export_file(vod_ds, path, source)
¶
Write canvodpy VOD as one of the tool's VOD files.
See :meth:export_dataset. Returns path.
Provenance¶
Provenance of a conversion between canvodpy and another tool.
Tool
¶
Bases: BaseModel
A program canvodpy exchanges data with.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Short name, also the model layer of imported VOD in the VOD store
(e.g. |
distribution |
str
|
Name of its installed Python distribution, to record its version. |
url |
str
|
Where to find it. |
Provenance
¶
Bases: BaseModel
Which tool data was converted from or to, by what, when.
Attributes:
| Name | Type | Description |
|---|---|---|
tool |
str
|
Name of the other tool. |
tool_url |
str
|
Where to find it. |
tool_version |
str
|
Its installed version at conversion time, or :data: |
adapter_version |
str
|
Version of canvod-adapters. |
direction |
{'import', 'export'}
|
|
source |
str
|
What was converted, e.g. a file name or a VOD store group. |
created |
datetime
|
When (UTC). |
now(tool, direction, source)
classmethod
¶
Provenance of a conversion running now, with installed versions.
to_attrs()
¶
Dataset attributes, each name prefixed with :data:ATTR_PREFIX.
from_attrs(attrs)
classmethod
¶
Read provenance back from dataset attributes.
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the attributes hold no complete provenance. |
package_version(distribution)
¶
Installed version of distribution, or :data:NOT_INSTALLED.
A conversion need not have the other tool installed (e.g. importing a gnssvod NetCDF file), so a missing package is recorded, not an error.
Reading and writing VOD stores¶
VOD store I/O through any :class:~canvod.adapters.base.VodAdapter.
Uses canvod-store, a dependency of this package.
import_vod(adapter, path, store, analysis_name, *, branch='main', dedup=True)
¶
Import one of a tool's VOD files into a canvodpy VOD store.
The data goes to the group {tool}/{analysis_name}: the tool takes
the place of the VOD model, so imported VOD stays apart from VOD that
canvodpy computed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
VodAdapter
|
Adapter of the tool that wrote the file. |
required |
path
|
Path or str
|
The tool's VOD file. |
required |
store
|
MyIcechunkStore
|
Destination VOD store (e.g. |
required |
analysis_name
|
str
|
Analysis the VOD belongs to (e.g. |
required |
branch
|
str
|
Icechunk branch to write to. |
"main"
|
dedup
|
bool
|
Skip the write if this file was already imported, or if its epochs overlap data already in the group. |
True
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the converted data does not meet the VOD dataset contract. |
export_vod(adapter, store, group_name, path, *, branch='main')
¶
Export a VOD store group as one of a tool's VOD files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
VodAdapter
|
Adapter of the tool to write for. |
required |
store
|
MyIcechunkStore
|
Source VOD store (e.g. |
required |
group_name
|
str
|
VOD group, |
required |
path
|
Path or str
|
File to write. |
required |
branch
|
str
|
Icechunk branch to read from. |
"main"
|
Returns:
| Type | Description |
|---|---|
Path
|
|
gnssvod¶
Adapters between canvodpy and gnssvod (Humphrey et al.).
GnssvodObservations
¶
Bases: ObservationsAdapter
gnssvod observation files <-> canvodpy observations.
Attributes:
| Name | Type | Description |
|---|---|---|
time_system |
str
|
Time scale of the epochs of the gnssvod files to import, as in the
RINEX files they came from; only |
Examples:
>>> adapter = GnssvodObservations(time_system="GPS")
>>> obs = adapter.import_file("ROSA_obs.nc")
>>> adapter.export_file(obs, "back_obs.nc", source="ROSA_obs.nc")
GnssvodVod
¶
Bases: VodAdapter
gnssvod VOD files <-> canvodpy VOD.
A gnssvod VOD file is the result of gnssvod.calc_vod for one
station pair (DataFrame.to_xarray()) written as NetCDF: dims
Epoch, SV, one variable per band, Azimuth/Elevation.
Attributes:
| Name | Type | Description |
|---|---|---|
bands |
dict[str, list[str]]
|
gnssvod's |
time_system |
str
|
Time scale of the epochs, as in the RINEX files gnssvod read (their
|
Notes
calc_vod reports the reference receiver's Azimuth/
Elevation; canvodpy reports the canopy receiver's. Imported VOD
keeps gnssvod's angles.
Examples:
>>> adapter = GnssvodVod(bands={"VOD_L1": ["S1C", "S1W"]}, time_system="GPS")
>>> vod = adapter.import_file("vod_canopy_vs_reference.nc")
canvodpy reader of gnssvod observation files.
GnssvodObsReader
¶
Bases: GNSSDataReader
Reads the observation NetCDF files gnssvod.preprocess writes.
A canvodpy reader like the RINEX and SBF readers: its datasets meet
the reader contract (:func:canvod.readers.validate_dataset), carry
the file hash for deduplication and the global attributes of every
canvodpy reader.
Attributes:
| Name | Type | Description |
|---|---|---|
fpath |
Path
|
gnssvod observation file (dims |
time_system |
str
|
Time scale of the file's epochs, which gnssvod keeps as in the
RINEX file (its |
to_ds(keep_data_vars=None, **kwargs)
¶
The file's observations as a canvodpy dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keep_data_vars
|
list of str
|
Data variables to keep (e.g. |
None
|
**kwargs
|
object
|
Not used; accepted for the reader interface. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the result does not meet the reader contract. |
iter_epochs()
¶
The file's observations, one epoch at a time.
Conversion between canvodpy and gnssvod (Humphrey et al.) data.
gnssvod
Observations: dims (Epoch, SV), one variable per RINEX observation
code (S1C, C1C, L1C, D1C; RINEX 2: S1, P2, ...),
plus Azimuth and Elevation in degrees (Observation objects,
gnssvod.preprocess). VOD: dims (Epoch, SV), one variable per
band named in the bands argument of gnssvod.calc_vod, which
merges the band's observation codes present in the data in sorted
order (numpy.intersect1d), each filling the gaps of the previous.
canvodpy
dims (epoch, sid), sid "SV|BAND|CODE" with the coordinates
sv, system, band, code and the band frequencies;
SNR, Pseudorange, Phase, Doppler, VOD; theta
(polar angle from zenith) and phi (azimuth from North, clockwise)
in radians.
Signal IDs and observation codes are mapped with
:func:canvod.readers.gnss_specs.obs_codes.sid_for_obs_code and
:func:~canvod.readers.gnss_specs.obs_codes.obs_code_for_sid, the rules of
canvodpy's RINEX readers. Angles: Elevation = 90 - degrees(theta),
Azimuth = degrees(phi) mod 360.
to_gnssvod_observations(ds)
¶
canvodpy observations as gnssvod observations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
canvodpy receiver dataset: dims |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
dims |
Raises:
| Type | Description |
|---|---|
ValueError
|
If two sids of a satellite map to the same observation code
(RINEX 2 |
from_gnssvod_observations(gnssvod_ds)
¶
gnssvod observations as canvodpy observations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gnssvod_ds
|
Dataset
|
gnssvod observations, dims |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
dims |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a satellite has data for a code its system has no band for. |
to_gnssvod_vod(vod_ds, bands)
¶
canvodpy VOD as gnssvod VOD, merged per band like gnssvod.calc_vod.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vod_ds
|
Dataset
|
canvodpy VOD dataset: dims |
required |
bands
|
dict[str, list[str]]
|
gnssvod's |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
dims |
from_gnssvod_vod(gnssvod_ds, bands)
¶
gnssvod VOD as canvodpy VOD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gnssvod_ds
|
Dataset
|
gnssvod VOD, dims |
required |
bands
|
dict[str, str]
|
Band variable to the observation code its sids get. gnssvod merges
the codes of a band, so give the RINEX 2 form for a merged band,
e.g. |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
dims |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a band variable is missing, or a satellite has VOD for a band its system does not have. |
See the Overview for usage.