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:

  1. the directory named by the environment variable GRIDFORGE_FEEDER_DIR, if it is set;

  2. else gridforge/data/pandapower of 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, when pyproject.toml is next to its directory: an installed package (site-packages/gridforge) never is, and files put in its data/pandapower for gridforge 0.3.0 are no longer used, which where says;

  3. else the user’s data directory, $XDG_DATA_HOME/gridforge/pandapower (~/.local/share/gridforge/pandapower by default; %LOCALAPPDATA% on Windows), where fetch_feeders writes 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: FeederDataError

A file is not the published one: its checksum differs from the pinned one.

exception gridforge.data.FeederDataError[source]#

Bases: Exception

The feeder data could not be fetched.

exception gridforge.data.FeederDownloadError[source]#

Bases: FeederDataError

The archive of the feeders could not be downloaded.

exception gridforge.data.FeederWriteError[source]#

Bases: FeederDataError

The 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: object

What a directory holds of the published feeders of the version gridforge pins.

current are the files of that version (FEEDERS_VERSION); former those of a version published before, with that version, which a fetch replaces; differing those that are neither; missing the published feeders the directory lacks; and unknown the 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.

message() → str | None[source]#

What is wrong, and the command that puts it right; None if nothing is.

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, as python -m gridforge.data where does.

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 as unknown.

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_DIR at 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 return dest.

The archive is downloaded from url (the permanent link of data.gouv.fr; a mirror or a file:// URL of a copy also does), checked against the pinned SHA-256, and only its networks/*.json files are extracted, each checked against the pinned SHA256SUMS. When all the files are in dest with the right checksum, nothing is downloaded; when any is missing, the whole archive is downloaded, and only the missing files are written. A file of dest that is the one of a version published before (v1, of gridforge 0.3.0) is replaced, as a missing one is written. A file of dest with any other content is replaced only with replace; otherwise it is an error, before any download.

Each file is written in a temporary directory inside dest and 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 dest that 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 dest holds a file that differs from it (without replace).

  • FeederWriteError – dest could not be created, read or written, or holds a directory under the name of a feeder; the OSError is its cause.

gridforge.data.missing_feeders_message(directory: str | PathLike | None = None, names: Sequence[str] = ()) → str[source]#

The message of a case study that finds no feeder, or not those of names, in directory (default: feeder_dir()).

gridforge.data.user_feeder_dir() → Path[source]#

The directory of the feeders in the user’s data directory, existing or not.