3) Tutorial - Understanding the database structure¶
Introduction¶
Datatoolbox does provide a csv-based database like interface that does use git to mangage and version control data sets (called “sources” with datatoolbox). Ideally, datatoolbox does manage all files and folders on the hard disk and manual changes are not required and even unsupported. Dataoolbox does monitor the internal folder and raises error when detecting manual changes. The underlying philophosy is to avoide manual changes that are not tracked by the git tracking and thus ensure reproducabilty of changes in the dataset. Overall, this should overall allow to reproduce analytical results based on given datasets and their fixed version.
The following figure shows the three layers within the data workflow starting from the raw data, to the aligned datatable struture, via the local database to the final shared database online.

1) Data integration¶
As done in the first two tutorials, always the firsts step is the conversion of the data
into the required data fromat and aligning to the naming convention. The data is separated
into homogeneous datatables that only consist on variable and with that a set of meta information
for all data values for variable regional and temporal extend.
Please not, that the consisstency in meta data might require to split data in different datatables, e.g. if the same data is switching between historic values to for example a projection, which should be indicated in the meta data as different scenarios (historic vs projection), however, the user itself is adviced to maintain the useful level of consistency.
2) Main repository of the datashelf¶
The main reposity of the datashelf follows roughtly the following data structure:
.
├── database
│ └── [.. indicidual sources ..]
│ └── [.. indicidual sources ..]
├── inventory.csv
├── mappings
│ ├── continent.csv
│ ├── country_codes.csv
│ └── regions.csv
├── rawdata
├── remote_sources
│ └── source_states.csv
└── sources.csv
The subfolder “database” does contain folder with indiviual data sources (see next section), that are combined to one locally available database. For this, the file “sources.csv” does contain all information about the locally added sources, which includes the meta data of the individual sources, the version of the source and its expected git hash. The “inventory.csv” does contain all tables from all sourcess combined and is used when searching for specific tables. Each time a source is added, changed or removed, the inventory.csv is updated to represent the new current database state. Each state is tracked via git commits and.
3) Organising data in individual sources (data sets)¶
Data sets (including all data from on souce and release) are organized as sources in datatoolbox. Each data set can contrain an arbitrary number of datatables reflecting different variables and scenario combinations. In the background, datatoolbox does create a git repository for each new source, that has its own meta data, inventory of datatables and is versioned using git.
import datatoolbox as dt
dt.admin.switch_database_to_testing()
print(dt.core.DB._get_source_path('Numbers_2022'))
Each source directory does follow the same file structure including a csv for the meta data, a source_inventory csv file and a folder containing the individual datatable csv.
.
├── meta.csv
├── raw_data
├── source_inventory.csv
└── tables
├── Numbers-Fives__Historic__Numbers_2020.csv
└── Numbers-Ones__Historic__Numbers_2020.csv````
5) Fixing errors in the database¶
When using data from the datashelf, datatoolbox verifies that the individual database git states do match the once listed in the overall repository. Thus, some incidence, local changes or bug might break the consistency of the databases . The following issues might arries that will make datatoolbox stop working or prevent access to individual data sources:
Uncommited changes in the main repository or individual source repositories
Different git hash of a local data source than in the main sources.csv
Errorenous table meta in “inventory.csv”
For some errors, dt.admin does offer some limited solution strategies:
dt.admin.fix_brocken_DB(sourceID, how):
how = "commmit_source_changes" # commits all changes in source and integrates new hash in main
# Only reverts all local changes in source repo using "git reset --hard"
how = "reset_source_revision":
# Resets source to version in main repository.
how == "fix_sources_inventory":
# Restores the data respository based on the last working git hash in the inventory file.
# After a successfulr restorations, datatoolbox need to be imported from scratch. For notebooks
# the restart of the python kernel might be required.