Skip to content

Instantly share code, notes, and snippets.

@sdtaylor
sdtaylor / variable_tickmark_length.R
Last active October 20, 2022 15:53
ggplot varying length tickmarks
library(tidyverse)
#------------------------------------
# Have x-axis labels offset slightly for clarity using guide_axis(n.dodge = 2),
# but also have different length tickmarks to make it look nicer.
# See https://twitter.com/ecologyofgavin/status/1344102509585997824
# Derived from https://stackoverflow.com/a/51312611/6615512
# Requires ggplot 3.0.0 or greater
#------------------------------------
@sdtaylor
sdtaylor / idenfity_continuous_non_zero_series.R
Last active July 21, 2021 13:59
idenfity continuous non-zero values in timeseries
library(tidyverse)
identify_continuous_non_zero_series = function(df, min_sequence_size =5){
# adds a new column called 'continuous_series' to the df data.frame
# identifying where 'value' column is >0 for at least min_sequence_size
# filter to only continous chunks > 0, assign each an ID,
# and flag each chunk >= min_sequence_size.
# the cumsum() trick is from https://stackoverflow.com/a/42734207/6615512
temp_df = df %>%
@sdtaylor
sdtaylor / install_stuff.sh
Created September 17, 2021 12:57
python geospatial environment
conda create --name geo python=3.8
conda activate geo
# with a spyder install outside the geo environment, but
# pointing to the geo environment bin/python, the following
# must be installed in the geo env to get the spyder ipython console working
pip install spyder-kernels~=2.0.0
# primary geospatial things
pip install xarray rasterio geopandas numpy pandas scipy netcdf4 dask
@sdtaylor
sdtaylor / mp_example.py
Created November 5, 2021 13:57
Basci python multipocessing
def processSpecies(speciesName):
#do stuff for this species
return(result)
speciesList=['a','b','c','d']
#############################################
#how stuff is typically done
results=[]
for species in speciesList:
@sdtaylor
sdtaylor / interaction_plot.R
Created March 31, 2022 00:51
ggplot interaction plot
library(tidyverse)
timing_results = tribble(
~treatment, ~object, ~mouse_id, ~time,
'vehicle', 'familiar', '1', 15,
'vehicle', 'novel', '1', 55,
'vehicle', 'familiar', '2', 19,
'vehicle', 'novel', '2', 60,
# Built-in modules
import os
import datetime
import itertools
from glob import glob
from aenum import MultiValueEnum
# Basics of Python data handling and visualization
import numpy as np
@sdtaylor
sdtaylor / cap_tests.py
Created November 28, 2022 23:39
CAP Stuff
# Various tests with Common Alert Protocal (CAP) feeds at https://severeweather.wmo.int/v2/
from datetime import datetime, timedelta
import requests
import re
#import xmltodict
import feedparser
from capparselib.parsers import CAPParser