Utils

Load config file

scripts.utils.load_config()[source]

Read config.json

Clean directory

scripts.utils.clean_dir(dirpath)[source]

This function can be used to fully clear a directory.

Arguments:
dirpath (string) – path to directory to be cleared from files

Remove files from directory

scripts.utils.remove_files(dirpath, startname)[source]

This function can be used to delete specific files from a directory. In general this function is used to clean country files from the ‘calc’ directory.

Arguments:

dirpath (string) – path to directory in which the files should be removed

startname (string) – the substring to be searched for in the files

Create folder structure

scripts.utils.create_folder_structure(data_path, country)[source]

Create the directory structure for the output.

Arguments:

*base_path (string) – path to directory where folder structure should be created.

regionalized (bool) – specify whether also the folders for a regionalized analyse should be created (default: True)

Integer to date

scripts.utils.int2date(argdate: int)[source]

If you have date as an integer, use this method to obtain a datetime.date object.

Arguments:
argdate (int) – Date as a regular integer value (example: 20160618)
Returns:
dateandtime.date – A date object which corresponds to the given value argdate.

Get integer from string

scripts.utils.get_num(x)[source]

Grab all integers from string.

Arguments:
x (string) – string containing integers
Returns:
integer – created from string

Create dictionary with country names in GeoFabrik

scripts.utils.country_dict_geofabrik()[source]

Create a dictionary to convert ISO2 codes to Geofabrik country names.

Returns:
dictionary – lookup between ISO2 codes and Geofabrik country names.

Download OSM file from GeoFabrik

scripts.utils.download_osm_file(country)[source]

Download OSM file from Geofabrik.

Arguments:
country (string) – ISO2 string code of country
Returns:
downloaded OSM file