Skip to content

Instantly share code, notes, and snippets.

View rplzzz's full-sized avatar

Robert Link rplzzz

  • University of Virginia
  • Charlottesville, VA
View GitHub Profile
@rplzzz
rplzzz / save-restore-pkgs.R
Created August 27, 2019 21:57
R functions for saving the list of installed packages and then reinstalling them all when you upgrade R
savepkgs <- function(saveloc)
{
instpkg <- installed.packages()
cranpkg <- available.packages()
iscran <- instpkg[,'Package'] %in% cranpkg[,'Package']
pkgdata <- data.frame(package=instpkg[,'Package'], iscran=iscran, instvers=instpkg[,'Version'])
write.csv(pkgdata, saveloc)
}
restore_pkgs <- function(pkglistfile)
@rplzzz
rplzzz / slowvsfast.Rmd
Created March 17, 2019 09:01
Using Hector to show the difference between early vs. late emissions reductions
---
title: "R Notebook"
output: html_notebook
---
```{r setup}
library(hector)
library(assertthat)
library(ggplot2)
library(ggthemes)
@rplzzz
rplzzz / conv_xpose.py
Created August 10, 2018 20:43
How to use the transpose convolution function in TensorFlow
## a batch of 3 4x4x2 images as input. We will upsample these to 8x8
input_data = np.ones([3, 4, 4, 2])
filter_shape = [3,3,4,2] # width, height, channels-out, channels-in
tconv_filter = np.ones(filter_shape) # make the filter all ones so that we can manually calculate the output
# obviously, having all the filter channels have the same coefficients defeats
# the purpose of having multiple channels, but this is just an example
output_shape = [8, 8, 4] # width, height, channels-out (notice we don't have the batch size dimension -- more on that later)
## set up the slots for the data
@rplzzz
rplzzz / country-codes-with-synonyms.csv
Last active August 29, 2015 14:22
Translation table between country names and ISO 3166-1 codes (including the two-letter, three-letter, and numeric versions). Many countries have more than one entry, reflecting the variant spellings of their names. The intent is that if you have an R data frame with a 'country' column and you merge that data frame with this one, you should get c…
country two-letter ISO numerical
Afghanistan AF AFG 4
Aland Islands AX ALA 248
Albania AL ALB 8
Algeria DZ DZA 12
American Samoa AS ASM 16
Andorra AD AND 20
Angola AO AGO 24
Anguilla AI AIA 660
Antarctica AQ ATA 10
@rplzzz
rplzzz / pyloc.py
Last active August 29, 2015 14:22 — forked from quandyfactory/pyloc.py
#!/usr/bin/env python
# coding: utf-8
"""
Calculates total, nonblank and net lines of code for Python scripts.
"""
import os
import re
def get_line_count(blob):
@rplzzz
rplzzz / gcam2nc.R
Last active August 29, 2015 14:07
Illustration of how to use the R sp, raster, and ncdf packages to output GCAM data in netCDF format
library(sp)
library(rgdal)
library(raster)
library(ncdf)
##aez map
## extract data from shape file
GIS_DIR <- "./cropdata"
GIS_FILE <- "GCAM_region_AEZ"
@rplzzz
rplzzz / .emacs
Last active June 18, 2022 12:58
A sample .emacs file
;; emacs startup file.
;; uncomment next line to disable loading of "default.el" at startup
;; (setq inhibit-default-init t)
;; add personal load path
(push "~/.emacs.d/lisp" load-path)
;; set up MELPA package archive
(require 'package)