Skip to content

Instantly share code, notes, and snippets.

View ntabris's full-sized avatar

Nat Tabris ntabris

View GitHub Profile
@ntabris
ntabris / dask_local_tcp.py
Last active January 31, 2025 23:56
dask_local_tcp.py
from dask.distributed import Client
client = Client("tcp://127.0.0.1:8786")
print(client)
import dask
# generate random timeseries of data
df = dask.datasets.timeseries(
@ntabris
ntabris / dask_from_batch_example.py
Created January 31, 2025 23:07
dask_from_batch_example.py
### GET DASK CLIENT ###
import os
import coiled
cluster = coiled.Cluster(os.environ.get("COILED_CLUSTER_NAME"))
cluster.adapt()
client = cluster.get_client()
print("dask client:", client)
### USER CODE FOLLOWS ###
@ntabris
ntabris / hello.py
Last active December 5, 2024 14:05
hello
print("Hello from Python!")
@ntabris
ntabris / gee_on_coiled.py
Created May 24, 2024 16:43
gee_on_coiled.py
import coiled
cluster = coiled.Cluster(...)
# this will send long-lived Application Default Credentials, with the OAuth scope needed for GEE
coiled.credentials.google.send_application_default_credentials(cluster, scopes=["https://www.googleapis.com/auth/earthengine"])
# plugin to init GEE on each worker
from distributed.diagnostics.plugin import WorkerPlugin
@ntabris
ntabris / aws-spot-rates-to-dataframe.py
Created July 13, 2023 19:31
aws-spot-rates-to-dataframe.py
import pandas as pd
import requests
raw = requests.get("https://spot-bid-advisor.s3.amazonaws.com/spot-advisor-data.json").json()
ranges = {r["index"]: r["label"] for r in raw["ranges"]}
flat = []
for region in raw["spot_advisor"].keys():
for instance in raw["spot_advisor"][region]["Linux"].keys():
savings = raw["spot_advisor"][region]["Linux"][instance]["s"]
@ntabris
ntabris / tracking_h5_to_sleap.py
Last active April 2, 2020 21:09
converts "tracking" h5 to sleap dataset
"""
Script to make a labels dataset from a "tracking" h5 file.
> python tracking_h5_to_sleap.py path/to/tracking.h5 path/to/video.mp4
"""
import h5py
import numpy as np
from sleap import Labels, LabeledFrame, PredictedInstance, Skeleton, Video
from sleap.instance import Track
@ntabris
ntabris / remove_low_scores.py
Created March 2, 2020 16:22
remove low-score instances from sleap labels dataset
from sleap import Labels
SCORE_THRESHOLD = 10
filename = "tests/data/json_format_v2/centered_pair_predictions.json"
out_filename = "tests/data/json_format_v2/centered_pair_predictions.high_scores.json"
labels = Labels.load_file(filename)
lf_inst_list = []
@ntabris
ntabris / diagnostic.py
Created February 20, 2020 15:59
diagnostic output for debugging sleap installation
"""
Outputs diagnostic information to help with debugging SLEAP installation.
"""
print_to_screen = False
output_text = ""
def print_(text=""):
global output_text
@ntabris
ntabris / astroids.py
Created November 16, 2019 15:42
python text astroids game
import attr
import os
import curses
from math import pi, cos, sin
import time
import random
@attr.s(auto_attribs=True)
class Board(object):