Skip to content

Instantly share code, notes, and snippets.

@knu2xs
knu2xs / get_logger.py
Created Sep 29, 2021
concisely get an easy to use logger
View get_logger.py
import logging
from pathlib import Path
from typing import Union
def get_logger(log_path: Union[str, Path] = 'logfile.log', log_name: str = 'logger', log_level: int = logging.ERROR):
"""
Standardized way to create a console and file logger in one.
Args:
View get_sys_info.py
import psutil
import platform
from datetime import datetime
def get_size(bytes, suffix="B"):
"""
Scale bytes to its proper format
e.g:
1253656 => '1.20MB'
1253656678 => '1.17GB'
@knu2xs
knu2xs / polsby_popper.py
Last active Sep 29, 2021
Calculate Polsby-Popper as measure of compactness
View polsby_popper.py
import math
from arcgis.geometry import Polygon
def get_simplified_polygon(geometry: Polygon, simplification_factor: float = 0.1) -> Polygon:
# ensure working with a polygon
assert isinstance(geometry, Polygon)
@knu2xs
knu2xs / environment.yml
Created Sep 28, 2021
Example conda environment file with PyDOBC
View environment.yml
name: arcgis
channels:
- esri
- conda-forge
dependencies:
- arcgis
- arcpy
- jupyterlab
View test_pro_version.py
def pro_at_least_version(version: str) -> bool:
"""
Test the current ArcGIS Pro version to be equal or greater than.
Args:
version: Version number eg ('2', '2.1', '2.8.1')
Returns:
Boolean indicating if version is at least or greater than specified version.
"""
# late import since may or may not already be loaded
View od-nax.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@knu2xs
knu2xs / enrichment-introspection.ipynb
Created May 28, 2021
Enrichment introspection examples
View enrichment-introspection.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@knu2xs
knu2xs / arcade_commute.arcade
Last active May 17, 2021
Arcade expression to calculate average drive time.
View arcade_commute.arcade
(
$feature.commute_ACSTWORKU5 * 2.5
+ $feature.commute_ACSTWORK5 * 7.0
+ $feature.commute_ACSTWORK10 * 12.0
+ $feature.commute_ACSTWORK15 * 17.0
+ $feature.commute_ACSTWORK20 * 22.0
+ $feature.commute_ACSTWORK25 * 27.0
+ $feature.commute_ACSTWORK30 * 32.0
+ $feature.commute_ACSTWORK35 * 37.0
+ $feature.commute_ACSTWORK40 * 42.0
@knu2xs
knu2xs / pyarrow-errors.ipynb
Created May 3, 2021
Errors encountered with PyArrow
View pyarrow-errors.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@knu2xs
knu2xs / enrich-direct-all.ipynb
Created Apr 27, 2021
Enrich block groups using all variables directly.
View enrich-direct-all.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.