Skip to content

Instantly share code, notes, and snippets.

@tylermorganwall
tylermorganwall / submarine_cable_map.R
Last active November 18, 2024 06:55
Submarine Cable Map Dataviz
library(geojsonsf)
library(sf)
library(rayrender)
#Data source: https://github.com/telegeography/www.submarinecablemap.com
cables = geojson_sf("cable-geo.json")
cablescene = list()
counter = 1
for(i in 1:length(cables$geometry)) {
@tylermorganwall
tylermorganwall / humanity_globe.R
Created August 17, 2021 14:37
3D Humanity Globe
library(rayshader)
library(rayrender)
popdata = raster::raster("gpw_v4_population_density_rev11_2020_15_min.tif")
population_mat = rayshader:::flipud(raster_to_matrix(popdata))
above1 = population_mat > 1
above5 = population_mat > 5
above10 = population_mat > 10
@tylermorganwall
tylermorganwall / india_historical_map.R
Last active February 25, 2024 18:22
Historical Map of India with 3D elevation
library(raster)
library(rayshader)
#Load QGIS georeference image (see https://www.qgistutorials.com/en/docs/3/georeferencing_basics.html)
testindia = raster::stack("1870_southern-india_modified.tif")
#Set bounding box for final map (cut off edges without data, introduced via reprojection)
india_bb = raster::extent(c(68,92,1,20))
cropped_india = raster::crop(testindia, india_bb)
#Convert to RGB array
#Calibration and Holdouts periods for data split
date_start = ['2013-04-01','2014-04-01','2015-04-01','2016-04-01']
calibration_period_end = ['2015-03-31','2016-03-31','2017-03-31','2018-03-31']
date_end = ['2016-03-31','2017-03-31','2018-03-31','2019-03-31']
#Arrays where to store the results of cross validation
accuracies_1y = []
holdouts_1y = []
predictions_1y = []
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import poisson,expon,nbinom
poisson_lambda = 4.3
p_arr = []
distribution = poisson(poisson_lambda)
for transactions in range(0,10):
p_arr.append(distribution.pmf(transactions))
# taken from https://medium.com/@pouryaayria/k-fold-target-encoding-dfe9a594874b
from sklearn import base
from sklearn.model_selection import KFold
class KFoldTargetEncoderTrain(base.BaseEstimator,
base.TransformerMixin):
def __init__(self,colnames,targetName,
n_fold=5, verbosity=True,
discardOriginal_col=False):
self.colnames = colnames
library(tigris)
library(tidycensus)
library(tidyverse)
library(sf)
ma_income <- get_acs(geography = "county subdivision",
variables = "B19013_001",
state = "MA")
ma_subs <- county_subdivisions(state = "MA", cb = TRUE, class = "sf") %>%
Only including this file so the title of the gist isn't `.gitignore`
@FinanceData
FinanceData / 발틱운임지수(BDI)와 해양운송업(팬오션).ipynb
Last active November 8, 2017 12:49
발틱운임지수와 해양운송업(팬오션)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sjsrey
sjsrey / joy.ipynb
Last active October 30, 2017 00:13
Exploring joy plots for use in regional income inequality dynamics
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.