Skip to content

Instantly share code, notes, and snippets.

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 September 29, 2021 03:48
Calculate Polsby-Popper as measure of compactness
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 September 28, 2021 21:58
Example conda environment file with PyDOBC
name: arcgis
channels:
- esri
- conda-forge
dependencies:
- arcgis
- arcpy
- jupyterlab
@knu2xs
knu2xs / noaa_ftp.py
Created May 19, 2014 15:23
Connect to the ftp server and retrieve all NOAA quantitative predictive forecast (QPF) resources for day one.
# import modules
from ftplib import FTP
import os
def get_day_one(directory_target):
"""
Retrieve zero to 30 hour precipitation forecasts
"""
# ftp url
url = 'ftp.hpc.ncep.noaa.gov'
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
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 15:12
Enrichment introspection examples
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 22:15
Arcade expression to calculate average drive time.
(
$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 16:43
Errors encountered with PyArrow
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@knu2xs
knu2xs / check_usgs_realtime.ipynb
Last active March 9, 2021 16:27
Check USGS realtime streamflow using Python.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.