Skip to content

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 keeps all and requires SNR (:func:canvod.readers.validate_dataset).

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 obs_ds is, recorded as provenance (e.g. a store group).

required

Returns:

Type Description
Path

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 tool_ds is, recorded as provenance (e.g. a file name).

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 vod_ds is, recorded as provenance (e.g. a store group).

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. "gnssvod").

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:NOT_INSTALLED.

adapter_version str

Version of canvod-adapters.

direction {'import', 'export'}

"import": from the tool into canvodpy; "export": the reverse.

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. site.vod_store).

required
analysis_name str

Analysis the VOD belongs to (e.g. "canopy_01_vs_reference_01").

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

True if written, False if skipped as a duplicate.

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. site.vod_store).

required
group_name str

VOD group, {model}/{analysis_name} (e.g. "tau_omega_zeroth_order/canopy_01_vs_reference_01").

required
path Path or str

File to write.

required
branch str

Icechunk branch to read from.

"main"

Returns:

Type Description
Path

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 "GPS" is accepted; see :class:~canvod.adapters.gnssvod.reader.GnssvodObsReader.

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 bands argument: band variable to the signal-strength observation codes calc_vod merges into it, e.g. {"VOD_L1": ["S1C", "S1W"], "VOD_L2": ["S2W"]}. Importing gives each band's VOD the sids of its code if the band has one code ("S2W" -> "G01|L2|W"), and of its RINEX 2 form if it merges several ("S1" -> "G01|L1|u", canvodpy's marker for a band whose tracking code is not known). Exporting merges canvodpy's VOD the same way as calc_vod, a merged band also taking the sids an import gives it, so imported VOD exports unchanged.

time_system str

Time scale of the epochs, as in the RINEX files gnssvod read (their TIME OF FIRST OBS record). canvodpy stores every epoch in GPS time, so only "GPS" is accepted; files in another time scale are refused when imported. Recorded on the epoch coordinate, like the readers do.

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 Epoch, SV).

time_system str

Time scale of the file's epochs, which gnssvod keeps as in the RINEX file (its TIME OF FIRST OBS record). canvodpy stores every epoch in GPS time, so only "GPS" is accepted; files in another time scale are refused when read. Recorded on the epoch coordinate, like the other readers do.

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. ["SNR"]); None keeps all.

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 (epoch, sid), an sv coordinate, any of SNR/Pseudorange/Phase/Doppler, optionally theta/phi.

required

Returns:

Type Description
Dataset

dims (Epoch, SV): one variable per observation code with data, e.g. S1C, for the satellites with data; Azimuth/ Elevation in degrees. All-NaN sids (canvodpy pads to a global sid set) are left out.

Raises:

Type Description
ValueError

If two sids of a satellite map to the same observation code (RINEX 2 P2 and C2 are both C2 in RINEX 3 terms).

from_gnssvod_observations(gnssvod_ds)

gnssvod observations as canvodpy observations.

Parameters:

Name Type Description Default
gnssvod_ds Dataset

gnssvod observations, dims (Epoch, SV) (e.g. Observation.observation.to_xarray()).

required

Returns:

Type Description
Dataset

dims (epoch, sid) with the sid coordinates; SNR, Pseudorange, Phase, Doppler as present; theta/phi if Elevation/Azimuth are present. Only satellite/code columns with data become sids.

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 (epoch, sid), an sv coordinate, VOD, optionally theta/phi.

required
bands dict[str, list[str]]

gnssvod's bands argument: band name to the signal-strength observation codes it merges, e.g. {"VOD_L1": ["S1C", "S1W"]}.

required

Returns:

Type Description
Dataset

dims (Epoch, SV): one variable per band; Azimuth/ Elevation in degrees. canvodpy's angles are the canopy receiver's; calc_vod reports the reference receiver's.

from_gnssvod_vod(gnssvod_ds, bands)

gnssvod VOD as canvodpy VOD.

Parameters:

Name Type Description Default
gnssvod_ds Dataset

gnssvod VOD, dims (Epoch, SV) (e.g. the calc_vod result converted with DataFrame.to_xarray()).

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. {"VOD_L1": "S1"}: the sid is "G01|L1|u", canvodpy's marker for a band whose tracking code is not known.

required

Returns:

Type Description
Dataset

dims (epoch, sid) with the sid coordinates; VOD; theta/phi if Elevation/Azimuth are present. Only satellite/band columns with data become sids.

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.