Skip to content

Instantly share code, notes, and snippets.

View tommylees112's full-sized avatar
🐘

Tommy Lees tommylees112

🐘
View GitHub Profile
@tommylees112
tommylees112 / wave2web_env.sh
Last active October 28, 2021 15:09
Environment with rasterio, skimage, pytorch, xarray, networkx
conda create -n w2w python=3.8 --yes
conda activate w2w
conda install -c conda-forge pytorch xarray=0.16 pytorch torchvision cudatoolkit --yes
conda install dask --yes
conda install -c conda-forge rasterio scikit-image --yes
conda install -c conda-forge seaborn=0.11 --yes
conda install -c anaconda networkx --yes
conda install -c conda-forge zarr gcsfs netcdf4 numba tqdm jupyterlab tensorboard ipython pip ruamel.yaml descartes statsmodels scikit-learn black mypy --yes
conda install -c conda-forge geopandas --yes
conda install -c conda-forge cdsapi --yes
@tommylees112
tommylees112 / clip_netcdf_to_shapefile.py
Created March 28, 2021 09:33
chopping a shapefile from netcdf files
"""
Mask xarray dataset using a shapefile [closed]
https://stackoverflow.com/a/64587946/9940782
"""
from typing import Tuple
import geopandas as gpd
import xarray as xr
import rasterio as rio
from pathlib import Path
import numpy as np
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nadya-p
nadya-p / pdf_to_text.py
Last active August 15, 2022 04:42
Extract text contents of PDF files recursively
from tika import parser
import os
def extract_text_from_pdfs_recursively(dir):
for root, dirs, files in os.walk(dir):
for file in files:
path_to_pdf = os.path.join(root, file)
[stem, ext] = os.path.splitext(path_to_pdf)
if ext == '.pdf':
@ahartikainen
ahartikainen / prior_and_posterior.ipynb
Last active February 22, 2019 01:22
Simple example on PyStan
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PaulC91
PaulC91 / network_wc.R
Last active July 19, 2018 13:28
network graph of world cup players connected by club and country
library(rvest)
library(tidyverse)
library(tidygraph)
library(ggraph)
wc_squads <- html("https://en.wikipedia.org/wiki/2018_FIFA_World_Cup_squads")
tables <- wc_squads %>%
html_table()
@jdossgollin
jdossgollin / gen_extreme_value.stan
Last active December 27, 2022 13:50
Fit a univariate GEV distribution in stan
/*
Fit a GEV distribution in stan
Code is largely based on previous code by
Cameron Bracken: http://bechtel.colorado.edu/~bracken/tutorials/stan/
and Yenan Wu: http://discourse.mc-stan.org/t/troubles-in-rejecting-initial-value/1827
*/
functions{
real gev_lpdf(vector y, real mu, real sigma, real xi) {
vector[rows(y)] z;
vector[rows(y)] lp;
@BertrandBordage
BertrandBordage / autoreplyer.py
Last active June 5, 2023 07:03
Automatically reply to unread and unanswered messages in Python
"""
Automatically replies to mails both unread and unanswered.
WARNING: This answers to any both unread and unanswered mail, even if it is years old.
Don’t use on a mailbox with old messages left unread and unanswered.
Simply subclass ``AutoReplyer``, define the undefined class attribute,
and call the ``run`` method on an instance. This loops until you stop the script
(using Ctrl+C, typically) or until an error occurs, like a network failure.
@sboysel
sboysel / rspatialresources.md
Last active September 5, 2022 15:28
R Spatial Analysis Notes

R Spatial Analysis Notes

Spatial Analysis in R

Key Packages

  • sp - defines the set of base classes for spatial data in R. Most useful for creating, converting, merging, transforming (e.g. projection), and plotting (see spplot) Spatial* objects.
  • rgdal - wrapper
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.