Skip to content

Instantly share code, notes, and snippets.

This file has been truncated, but you can view the full file.
import numpy as np
from scipy.optimize import root_scalar
from scipy.special import expit # inverse logit
def logit_shift_baseline(df, ndv_col, nrv_col, target=0.5):
ndv = df[ndv_col].values
nrv = df[nrv_col].values
turn = ndv + nrv
# Compute log-odds where turnout > 0
#!/usr/bin/env python3
"""
Feature finder script to match OSM and Overture features based on tags and spatial proximity.
Usage examples:
feature-finder.py aerodrome airport --name OAK
feature-finder.py national_park --name Alcatraz
"""
from __future__ import annotations
#!/usr/bin/env python3
import itertools
import typing
import math
import cairo
import shapely.affinity
import shapely.geometry
DISTANCE_CUTOFF = 2 # max jump length to bridge with a curve
"""Convert input CSV to OpenElections CSV
Adapt large tabular sources like this Lenawee County example (1) converted from PDFs (2)
to format required by OpenElections (3) intepreting categories of votes, candidates, and
offices along the way.
1) https://docs.google.com/spreadsheets/d/1iOEqLFcwuA3J_HXUtEWIZUirA7J1_NdsnVUnc8z0TZY/edit?gid=2129694166#gid=2129694166
2) https://github.com/openelections/openelections-sources-mi/blob/master/2024/general/Gogebic%20MI%20Official%20Statement%20of%20Votes%20Cast%20with%20Certification%2011.5.2024.pdf
3) https://github.com/openelections/openelections-data-mi/issues/69
"""Coalesce Excel sheets that appear to be excerpts of larger sheets
Requires pylightxl: https://pylightxl.readthedocs.io/en/latest/
PDF sources like this Gogebic County example (1) can be converted by AWS Textract
into usable Excel workbooks with multiple sheets (2). This scripts makes a best-effort
attempt to stitch together large tables broken up across multiple pages based on
row counts, column counts, and cell values representing precincts. The results still
require a lot of manual interpretation to be turned into useful OpenElections data (3).
@migurski
migurski / _index.ipynb
Last active February 21, 2024 00:43
Felt API + Jupyter Notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import datetime
import math
import mercantile
import pytz
import suncalc
def date(yyyy, mm, dd, hh):
dt_naive = datetime.datetime(yyyy, mm, dd, int(hh), int((60 * hh) % 60))
dt_local = dt_naive.astimezone(pytz.timezone('America/Los_Angeles'))
dt_utc = dt_local.astimezone(pytz.utc)
@migurski
migurski / weather2calendar.py
Created January 15, 2024 18:26
Pirate Weather → iCal & JSON Script
#!/usr/bin/env python3
import datetime
import json
import os
import sys
import gzip
import ics
import requests
import pytz
@migurski
migurski / README.txt
Created January 13, 2024 06:26
Twitter archive README content
INTRODUCTION
============
This archive was generated at the request of the following user:
- @username at the time the archive was generated: migurski
- Account ID: 2790981
The easiest way to navigate your archive is to open the HTML renderer in a desktop web browser by double clicking the “Your archive” file included in the main folder once the archive is unzipped.
Note that the HTML renderer only works if the archive is less than 50GB. Also note that the HTML renderer only includes a subset of the data included in the archive. To see all the data included in the archive, please navigate the JSON files located in the “data” folder.