canvod.filemap API reference¶
Package¶
canvod-filemap: naming recipes for non-canonical GNSS filenames.
VirtualFile
dataclass
¶
NamingRecipe
¶
Bases: BaseModel
A user-defined mapping from arbitrary filenames to canVOD names.
Serialize to YAML for sharing, to JSON for API transport. Fields it
does not know are ignored; :meth:unrecognized_fields names them.
expected_length
property
¶
Total number of characters consumed by the field spec.
parse_filename(filename)
¶
Extract fields from a physical filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Bare filename (no directory components). |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Extracted field values. Integer fields (year, doy, etc.) are
returned as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the filename is too short for the field spec. |
to_virtual_file(file_path)
¶
Map a physical file to a VirtualFile using this recipe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to the physical file. |
required |
Returns:
| Type | Description |
|---|---|
VirtualFile
|
The mapped virtual file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the filename cannot be parsed. |
matches(filename)
¶
Check if a filename can be parsed by this recipe.
to_yaml()
¶
Serialize to YAML string.
save(path)
¶
Write recipe to a YAML file.
from_yaml(text)
classmethod
¶
Load from a YAML string.
Raises:
| Type | Description |
|---|---|
YAMLError
|
If |
ValidationError
|
If the YAML is not a valid recipe. |
load(path)
classmethod
¶
Load from a YAML file.
unrecognized_fields(path)
classmethod
¶
Top-level fields of a recipe file that the recipe does not know.
They are ignored when the recipe is loaded, for example a misspelled field or one a later version of canvod-filemap reads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
A recipe file. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The unknown field names, in file order; empty if there are none. |
Raises:
| Type | Description |
|---|---|
YAMLError
|
If the file is not YAML, or is nested too deeply to read. |
RecipeNotFoundError
¶
Bases: FileNotFoundError
No recipe file exists for a site and recipe name.
RecipeFetchError
¶
Bases: RemoteRecipeError
A recipe that could not be fetched, or whose file is not a valid recipe.
RecipeURLError
¶
Bases: RemoteRecipeError, ValueError
A recipe URL that is not a raw file link.
RemoteRecipeError
¶
Bases: Exception
A recipe URL that cannot be used.
recipe_sha256(path)
¶
The sha256 of a recipe file, as recorded in a store's metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
A recipe file, local or fetched by this run. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The hexadecimal sha256 of the file's bytes. |
create_recipe(config_dir, site, name, *, overwrite=False)
¶
Create the recipe name of site from the template.
The new file has name filled in. The receiver identity and the
fields list must be edited before the recipe can be loaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir
|
Path
|
The configuration directory (the one holding the settings file). |
required |
site
|
str
|
Site name in the settings file. |
required |
name
|
str
|
Recipe name, the receiver's |
required |
overwrite
|
bool
|
Replace an existing recipe file. |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
The created file, |
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If the recipe file exists and |
find_recipe(config_dir, site, name)
¶
Path of the existing recipe file name of site.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir
|
Path
|
The configuration directory (the one holding the settings file). |
required |
site
|
str
|
Site name in the settings file. |
required |
name
|
str
|
Recipe name, the receiver's |
required |
Returns:
| Type | Description |
|---|---|
Path
|
|
Raises:
| Type | Description |
|---|---|
RecipeNotFoundError
|
If that file does not exist. If the recipe is found directly in
|
RemoteRecipeError
|
If |
recipe_path(config_dir, site, name)
¶
Path of the recipe name of site, whether it exists or not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir
|
Path
|
The configuration directory (the one holding the settings file). |
required |
site
|
str
|
Site name in the settings file. |
required |
name
|
str
|
Recipe name, the receiver's |
required |
Returns:
| Type | Description |
|---|---|
Path
|
|
check_recipe_url(url)
¶
Check that url is a raw file link in a GitHub repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The recipe URL. |
required |
Raises:
| Type | Description |
|---|---|
RecipeURLError
|
If the URL is not |
fetch_recipe(url, *, timeout=30.0)
¶
The local file of the recipe at url, fetched by this run.
The URL is checked with :func:check_recipe_url. The file is fetched,
read like a local recipe file, and its name must match the file
name at the end of the URL. A run fetches a URL once, into a folder
of the run that is removed when the process that made it ends
(:func:canvod.utils.remote_file.fetch_remote).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The recipe URL. |
required |
timeout
|
float
|
Seconds to wait for the server. |
30.0
|
Returns:
| Type | Description |
|---|---|
Path
|
The fetched recipe file. |
Raises:
| Type | Description |
|---|---|
RecipeURLError
|
If the URL is not a raw file link. |
RecipeFetchError
|
If the file cannot be fetched (not found, no access, a token that is not a token, no network, timeout), is not a valid recipe, or its name does not match the URL. |
is_recipe_url(value)
¶
Whether a recipe: setting is a URL rather than a recipe name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The receiver's |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True for |
Recipe¶
Naming recipe: user-defined mapping from arbitrary filenames to canVOD names.
A recipe is a small YAML file that describes: 1. The canonical identity of a receiver (site, agency, sampling, etc.) 2. How to extract date/time fields from the user's physical filenames.
The field extraction is a sequential left-to-right walk over the filename.
Each entry in the fields list consumes characters and either extracts
a named value or skips literal characters.
Recognized field names
year4-digit year (e.g. 2025)yy2-digit year (80-99 → 19xx, 00-79 → 20xx)doyday of year (1-366)monthmonth (01-12)dayday of month (01-31)hourhour (00-23)minuteminute (00-59)hour_letterRINEX 2 session letter (a-x = hours 0-23; 0 = daily file)skipignore these characters
Example recipe (YAML)
::
name: fangorn_reference
description: Orthanc, reference receiver
site: FAN
agency: INK
receiver_number: 1
receiver_type: reference
sampling: "05S"
period: "15M"
content: "AA"
file_type: rnx
glob: "*.??o"
# Example: rref001a15.25o
fields:
- skip: 4
- doy: 3
- hour_letter: 1
- minute: 2
- skip: 1
- yy: 2
- skip: 1
Example recipe for exotic filenames
::
# Example: STATION_2025_042_00_15.rinex
fields:
- skip: 8
- year: 4
- skip: 1
- doy: 3
- skip: 1
- hour: 2
- skip: 1
- minute: 2
- skip: 6
NamingRecipe
¶
Bases: BaseModel
A user-defined mapping from arbitrary filenames to canVOD names.
Serialize to YAML for sharing, to JSON for API transport. Fields it
does not know are ignored; :meth:unrecognized_fields names them.
expected_length
property
¶
Total number of characters consumed by the field spec.
parse_filename(filename)
¶
Extract fields from a physical filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Bare filename (no directory components). |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Extracted field values. Integer fields (year, doy, etc.) are
returned as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the filename is too short for the field spec. |
to_virtual_file(file_path)
¶
Map a physical file to a VirtualFile using this recipe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to the physical file. |
required |
Returns:
| Type | Description |
|---|---|
VirtualFile
|
The mapped virtual file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the filename cannot be parsed. |
matches(filename)
¶
Check if a filename can be parsed by this recipe.
to_yaml()
¶
Serialize to YAML string.
save(path)
¶
Write recipe to a YAML file.
from_yaml(text)
classmethod
¶
Load from a YAML string.
Raises:
| Type | Description |
|---|---|
YAMLError
|
If |
ValidationError
|
If the YAML is not a valid recipe. |
load(path)
classmethod
¶
Load from a YAML file.
unrecognized_fields(path)
classmethod
¶
Top-level fields of a recipe file that the recipe does not know.
They are ignored when the recipe is loaded, for example a misspelled field or one a later version of canvod-filemap reads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
A recipe file. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The unknown field names, in file order; empty if there are none. |
Raises:
| Type | Description |
|---|---|
YAMLError
|
If the file is not YAML, or is nested too deeply to read. |
recipe_sha256(path)
¶
The sha256 of a recipe file, as recorded in a store's metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
A recipe file, local or fetched by this run. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The hexadecimal sha256 of the file's bytes. |
Recipe files¶
Where naming recipe files live, and creating them from the template.
Recipes are kept per site in the configuration directory::
<config dir>/recipes/<site>/<name>.yaml
<site> is the site name in the settings file and <name> the
receiver's recipe: setting. Recipe files are user data: they are not part
of any repository and are only read from this location.
RecipeNotFoundError
¶
Bases: FileNotFoundError
No recipe file exists for a site and recipe name.
recipe_path(config_dir, site, name)
¶
Path of the recipe name of site, whether it exists or not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir
|
Path
|
The configuration directory (the one holding the settings file). |
required |
site
|
str
|
Site name in the settings file. |
required |
name
|
str
|
Recipe name, the receiver's |
required |
Returns:
| Type | Description |
|---|---|
Path
|
|
find_recipe(config_dir, site, name)
¶
Path of the existing recipe file name of site.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir
|
Path
|
The configuration directory (the one holding the settings file). |
required |
site
|
str
|
Site name in the settings file. |
required |
name
|
str
|
Recipe name, the receiver's |
required |
Returns:
| Type | Description |
|---|---|
Path
|
|
Raises:
| Type | Description |
|---|---|
RecipeNotFoundError
|
If that file does not exist. If the recipe is found directly in
|
RemoteRecipeError
|
If |
create_recipe(config_dir, site, name, *, overwrite=False)
¶
Create the recipe name of site from the template.
The new file has name filled in. The receiver identity and the
fields list must be edited before the recipe can be loaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir
|
Path
|
The configuration directory (the one holding the settings file). |
required |
site
|
str
|
Site name in the settings file. |
required |
name
|
str
|
Recipe name, the receiver's |
required |
overwrite
|
bool
|
Replace an existing recipe file. |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
The created file, |
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If the recipe file exists and |
Mapping¶
VirtualFile: a physical file paired with its canVOD conventional name.
NamingRecipe.to_virtual_file returns it; the file on disk keeps its name.