brokenspoke_analyzer.core.utils module¶
Define utility functions.
- class brokenspoke_analyzer.core.utils.PolygonFormat(*values)¶
Bases:
Enum
Represent the available polygon formats from polygons.openstreetmap.fr.
- GEOJSON = 'get_geojson.py'¶
- POLY = 'get_poly.py'¶
- WKT = 'get_wkt.py'¶
- brokenspoke_analyzer.core.utils.compare_bna_results(brokenspoke_scores, original_scores, output_csv)¶
Compare the Brokenaspoke and the original BNA results.
- Return type:
DataFrame
- brokenspoke_analyzer.core.utils.file_checksum_ok(osm_file, osm_file_md5)¶
Validate a file checksum.
- Return type:
bool
- brokenspoke_analyzer.core.utils.get_srid(shapefile)¶
Get the SRID of a shapefile.
- Return type:
int
- brokenspoke_analyzer.core.utils.gunzip(gzip_file, target, delete_after=True)¶
Gunzip a file into a specific target.
- Return type:
None
- brokenspoke_analyzer.core.utils.is_usa(country)¶
Return True if the country name is an alias of the USA.
- Return type:
bool
- Examples:
>>> is_usa('US') True
>>> is_usa('USA') True
>>> is_usa('United States') True
>>> is_usa('France') False
- brokenspoke_analyzer.core.utils.normalize_country_name(country)¶
Normalize the country name.
The main goal of this function is to normalize the name of the United States of America. Since the country can have 3 names, it can be confusing. As per the BNA guidelines, the name of this country must be “united states”.
- Return type:
str
- Examples:
>>> normalize_country_name("US") united states
>>> normalize_country_name("USA") united states
>>> normalize_country_name("France") France
- brokenspoke_analyzer.core.utils.normalize_unicode_name(value)¶
Normalize unicode names.
- Return type:
str
- Examples:
>>> normalize_unicode_name("Québec") quebec
>>> normalize_unicode_name("Cañon City") canon city
- brokenspoke_analyzer.core.utils.prepare_census_blocks(tabblk_file, output_dir)¶
Prepare the census block files to match our naming convention.
- Return type:
None
- brokenspoke_analyzer.core.utils.prepare_city_inputs(country, city, state, root=None)¶
Prepare the directories and files that will be used to perform the analysis.
- Return type:
tuple
[Path
,Path
,Path
]- Returns:
a tuple containing the input directory created for the city, the boundary file and the OSM file.
- brokenspoke_analyzer.core.utils.prepare_environment(city, state, country, city_fips, state_fips, state_abbrev, run_import_jobs)¶
Prepare the environment variables required by the modular BNA.
- Return type:
Mapping
[str
,str
]
- Example:
>>> d = prepare_environment( >>> "washington", "district of columbia", "usa", "1150000", "11", "DC", "1" >>> ) >>> assert d == { >>> "BNA_CITY_FIPS": "1150000", >>> "BNA_CITY": "washington", >>> "BNA_COUNTRY": "usa", >>> "BNA_FULL_STATE": "district of columbia", >>> "BNA_SHORT_STATE": "dc", >>> "BNA_STATE_FIPS": "11", >>> "CENSUS_YEAR": "2019", >>> "NB_COUNTRY": "usa", >>> "NB_INPUT_SRID": "4326", >>> "PFB_CITY_FIPS": "1150000", >>> "PFB_STATE_FIPS": "11", >>> "PFB_STATE": "dc", >>> "RUN_IMPORT_JOBS": "1", >>> }
- brokenspoke_analyzer.core.utils.unzip(zip_file, output_dir, delete_after=True)¶
Unzip an archive into a specific directory.
- Return type:
None