Feeder Data#
The feeder data of the MV/LV case study: where gridforge looks for it, and how to fetch it.
The 150 feeders are published on data.gouv.fr (DATASET_URL) under the Licence Ouverte /
Open Licence 2.0, as one archive whose checksum, and those of the files it holds, are
pinned here. Only two of them are in the git repository, for the tests; the wheel holds
none. fetch_feeders (or python -m gridforge.data fetch) downloads the archive,
checks it and extracts the feeders, and feeder_dir tells where gridforge looks for
them:
the directory named by the environment variable
GRIDFORGE_FEEDER_DIR, if it is set;else
gridforge/data/pandapowerof a source checkout, if it holds feeder files other than the two of the repository (the files were put there by hand, or fetched there). The package is taken to sit in a source checkout, or in an editable install of one, whenpyproject.tomlis next to its directory: an installed package (site-packages/gridforge) never is, and files put in itsdata/pandapowerfor gridforge 0.3.0 are no longer used, whichwheresays;else the user’s data directory,
$XDG_DATA_HOME/gridforge/pandapower(~/.local/share/gridforge/pandapowerby default;%LOCALAPPDATA%on Windows), wherefetch_feederswrites by default, whether or not it exists yet.
The files are those of version 2 of the data (FEEDERS_VERSION, #14), made from
version 1, which gridforge 0.3.0 used, by scripts/repair_feeders.py of the
repository. A fetch replaces the files of version 1 that it finds without being told
to (replace), since they are the published ones of a former version.
feeder_dir reads the environment variable at each call, and resolves a relative value
against the working directory of the call.
gridforge.data_path is resolved by it once, when gridforge is imported: set the
variable before importing gridforge.
- gridforge.data.ARCHIVE_NAME = 'departs-hta-representatifs-pandapower-gridforge-v2.tar.xz'#
The file name of the archive of the feeders
- gridforge.data.ARCHIVE_SHA256 = 'e55ac84ab2c16b15ac8315cc1024b3a19b2e8d21a9377ecb4d1089b12f4c7c36'#
The SHA-256 of the archive, against which a fetch checks it
- gridforge.data.DATASET_URL = 'https://www.data.gouv.fr/datasets/departs-hta-representatifs-pour-lanalyse-des-reseaux-de-distribution-francais'#
The page of the dataset of the feeders on data.gouv.fr
- gridforge.data.FEEDERS_URL = 'https://www.data.gouv.fr/fr/datasets/r/5b0f15fa-2bdb-4033-8d47-abc3c43b7a6f'#
The permanent link of the archive on data.gouv.fr, which redirects to the file
- gridforge.data.FEEDERS_VERSION = 'v2'#
The version of the published feeders that gridforge pins and fetches
- gridforge.data.FEEDER_DIR_ENV = 'GRIDFORGE_FEEDER_DIR'#
The environment variable that names the directory of the feeders
- gridforge.data.FETCH_COMMAND = 'python -m gridforge.data fetch'#
The command that fetches the feeders, as the messages give it
- exception gridforge.data.FeederChecksumError[source]#
Bases:
FeederDataErrorA file is not the published one: its checksum differs from the pinned one.
- exception gridforge.data.FeederDataError[source]#
Bases:
ExceptionThe feeder data could not be fetched.
- exception gridforge.data.FeederDownloadError[source]#
Bases:
FeederDataErrorThe archive of the feeders could not be downloaded.
- exception gridforge.data.FeederWriteError[source]#
Bases:
FeederDataErrorThe directory of the feeders could not be read or written.
- class gridforge.data.FeederCheck(directory: Path, current: tuple[str, ...]=(), former: dict[str, str]=<factory>, differing: tuple[str, ...]=(), missing: tuple[str, ...]=(), unknown: tuple[str, ...]=())[source]#
Bases:
objectWhat a directory holds of the published feeders of the version gridforge pins.
currentare the files of that version (FEEDERS_VERSION);formerthose of a version published before, with that version, which a fetch replaces;differingthose that are neither;missingthe published feeders the directory lacks; andunknownthe files asked for that are not published feeders. All are file names.- directory: Path#
- current: tuple[str, ...] = ()#
- former: dict[str, str]#
- differing: tuple[str, ...] = ()#
- missing: tuple[str, ...] = ()#
- unknown: tuple[str, ...] = ()#
- property ok: bool#
Whether every feeder checked is there, of the version gridforge pins.
- gridforge.data.check_feeders(directory: str | PathLike | None = None, names: Sequence[str] | None = None) FeederCheck[source]#
Check the feeders of
directory(default:feeder_dir()) against the checksums that gridforge pins, aspython -m gridforge.data wheredoes.- Parameters:
directory – The directory of the feeders.
names – The file names to check (
<feeder>.json); default: all the published feeders. A name that is not one of them is reported asunknown.
- gridforge.data.feeder_file_message(path: str | PathLike) str | None[source]#
What is wrong with the feeder file
path, if its name is that of a published feeder and it is not the file of the version gridforge pins; None otherwise, and for a file of another name (a feeder of one’s own).
- gridforge.data.manifest_sha256() str[source]#
The SHA-256 of the checksums of the feeders that gridforge pins (
pandapower-feeders.sha256): it names the version of the data a study runs on.
- gridforge.data.expected_feeders() dict[str, str][source]#
The published feeder files, by file name, with their SHA-256.
- gridforge.data.feeder_dir() Path[source]#
The directory where gridforge looks for the feeders, by the rule of the module.
It reads
GRIDFORGE_FEEDER_DIRat each call, and resolves a relative value against the working directory of the call: the path it returns keeps its meaning after a change of the working directory.
- gridforge.data.fetch_feeders(dest: str | PathLike | None = None, *, url: str = 'https://www.data.gouv.fr/fr/datasets/r/5b0f15fa-2bdb-4033-8d47-abc3c43b7a6f', replace: bool = False, timeout: float = 60.0) Path[source]#
Download the 150 feeders of the MV/LV case study into
dest, and returndest.The archive is downloaded from
url(the permanent link of data.gouv.fr; a mirror or afile://URL of a copy also does), checked against the pinned SHA-256, and only itsnetworks/*.jsonfiles are extracted, each checked against the pinnedSHA256SUMS. When all the files are indestwith the right checksum, nothing is downloaded; when any is missing, the whole archive is downloaded, and only the missing files are written. A file ofdestthat is the one of a version published before (v1, of gridforge 0.3.0) is replaced, as a missing one is written. A file ofdestwith any other content is replaced only withreplace; otherwise it is an error, before any download.Each file is written in a temporary directory inside
destand moved into place once checked, so that an error leaves no partial file. A temporary directory that a killed fetch left, older than a day, is removed.- Parameters:
dest – The directory of the feeders (default:
feeder_dir()).url – Where to download the archive from.
replace – Replace the files of
destthat differ from the published ones.timeout – Seconds to wait for the server, per read.
- Raises:
FeederDownloadError – The archive could not be downloaded, or its permanent link is not known yet, as in a development version of gridforge that pins an archive not yet published.
FeederChecksumError – The archive, or a file of it, is not the published one, or
destholds a file that differs from it (withoutreplace).FeederWriteError –
destcould not be created, read or written, or holds a directory under the name of a feeder; theOSErroris its cause.