Skip to content

Instantly share code, notes, and snippets.

View dlebauer's full-sized avatar
😀

David LeBauer dlebauer

😀
View GitHub Profile
@dlebauer
dlebauer / 0_reuse_code.js
Last active August 29, 2015 14:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dlebauer
dlebauer / betydb_schema_constraints.sql
Last active August 29, 2015 14:10
BETYdb Schema with proposed constraints
/*
Navicat PGSQL Data Transfer
Source Server : pecandev
Source Server Version : 90305
Source Host : pecandev.igb.illinois.edu:5432
Source Database : bety_constraints
Source Schema : public
Target Server Type : PGSQL
<?xml version="1.0"?>
<pecan>
<outdir>/home/dlebauer/out/salix-sachalinensis/</outdir>
<pfts>
<pft>
<name>salix-sachalinensis</name>
<constants><file>/home/dlebauer/dev/willow_da/vignettes/salix.xml</file></constants>
</pft>
</pfts>
<database>
library(PEcAn.all)
download.file(url = "http://goo.gl/kPlJ47",
destfile = "foo.xml", method = 'wget', extra = '--no-check-certificate')
settings <- read.settings("foo.xml")
settings$pfts <- get.trait.data(pfts = settings$pfts,
modeltype = "BIOCRO", dbfiles = settings$run$dbfiles,
database = settings$database$bety, forceupdate = TRUE)
run.meta.analysis(pfts = settings$pfts,
iterations = settings$meta.analysis$iter,
dbfiles = settings$run$dbfiles,
library(data.table)
## skip the following by just clicking the link to download
download.file("https://dl.dropboxusercontent.com/u/18092793/plants.csv", method = "auto", destfile = "species.csv")
species <- fread("species.csv")
species[`Berry/Nut/Seed Product` == "Yes"|
`Christmas Tree Product` == "Yes" |
`Pulpwood Product` == "Yes"]
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 19 columns, instead of 11 in line 4.
result_type, id, site_id, sitename, treatment_id, lat, lon, scientificname, author, citation_year, treatment, date, trait, mean, units, n, statname, stat, definition
traits ,51010,601,"Oak Ridge National Environmental Research Park, Free-Air Carbon Dioxide Enrichment",1123,-87.46,36.39,Liquidambar styraciflua,Sholtis,2002,elevated CO2 level,,Amax,30.8,umol CO2 m-2 s-1,,MSE,4.6,553-556 ppm
traits ,51012,601,"Oak Ridge National Environmental Research Park, Free-Air Carbon Dioxide Enrichment",1123,-87.46,36.39,Liquidambar styraciflua,Sholtis,2002,elevated CO2 level,,Amax,11.8,umol CO2 m-2 s-1,,MSE,3.3,553-556 ppm
traits ,51014,601,"Oak Ridge National Environmental Research Park, Free-Air Carbon Dioxide Enrichment",1123,-87.46,36.39,Liquidambar styraciflua,Sholtis,2002,elevated CO2 level,,Amax,12.2,umol CO2 m-2 s-1,,MSE,1.3,553-556 ppm
traits ,51040,601,"Oak Ridge National Environmental Research Park, Free-Air Carbon Dioxide Enrichment",1123,-87.46,36.39,Liquidambar styraciflua,Sholtis,2002,elevated C
library(PEcAn.DB)
library(ggplot2)
dbparms <- list(driver = "PostgreSQL", dbname = "bety", user = "bety", host = "localhost", password = "bety")
con <- db.open(dbparms)
views <- db.query("select * from traits_and_yields_view_private", con = con)
db.close(con)
world <- map_data("world")
ggplot() +
geom_jitter(data = views,
@dlebauer
dlebauer / remove_cultivar_dupes.sql
Last active August 29, 2015 14:14
Remove duplicate Cultivars
update cultivars set name = '64038-2n', updated_at = now() where id = 415;
update cultivars set name = '64038-4n', updated_at = now() where id = 416;
update traits set cultivar_id = 184 where cultivar_id in (196); update yields set cultivar_id = 184 where cultivar_id in (196); delete from cultivars where id in (196);
update traits set cultivar_id = 350 where cultivar_id in (345); update yields set cultivar_id = 350 where cultivar_id in (345); delete from cultivars where id in (345);
update traits set cultivar_id = 352 where cultivar_id in (441); update yields set cultivar_id = 352 where cultivar_id in (441); delete from cultivars where id in (441);
update traits set cultivar_id = 443 , updated_at = now() where cultivar_id in (340, 309, 367, 303); update yields set cultivar_id = 443 , updated_at = now() where cultivar_id in (340, 309, 367, 303); delete from cultivars where id in (340, 309, 367, 303);
update traits set cultivar_id = 293 , updated_at = now() where cultivar_id in (294); update yields set cultivar
@dlebauer
dlebauer / cp_files.sh
Created January 26, 2015 22:25
Moving paperclip files, updating dbfiles PecanProject/bety#183
cp /usr/local/ebi/paperclip/files/b49/762/333/b49762333c0fb3d501f024b8df7f1ee6 /home/share/data/dbfiles/US-UMB.clim
cp /usr/local/ebi/paperclip/files/85c/697/5aa/85c6975aaf49b05f8c333847eabf60ca /home/share/data/dbfiles/US-Ho1.clim
cp /usr/local/ebi/paperclip/files/643/91e/db6/64391edb64c876482d8ea8017bca6994 /home/share/data/dbfiles/US-MMS.clim
cp /usr/local/ebi/paperclip/files/439/286/b54/439286b548f68228614a160e40308fd5 /home/share/data/dbfiles/US-NR1.clim
cp /usr/local/ebi/paperclip/files/96b/c3d/cd3/96bc3dcd34062b83959c073b9e674c80 /home/share/data/dbfiles/wcr.clim
cp /usr/local/ebi/paperclip/files/bcb/be0/4a7/bcbbe04a792b6edcbe030fa8da0c800d /home/share/data/dbfiles/syl.clim
cp /usr/local/ebi/paperclip/files/0a4/4dd/9e0/0a44dd9e06e9d4feba786a4cbc34f42c /home/share/data/dbfiles/yjp.clim
cp /usr/local/ebi/paperclip/files/034/c67/f10/034c67f10466a7424fa1c9aab46bf25e /home/share/data/dbfiles/lcr.clim
cp /usr/local/ebi/paperclip/files/788/85e/cec/78885ecec7a3a7134592c780607f6715 /home/share/data/dbfiles/lef.
@dlebauer
dlebauer / normalize_sites.R
Last active August 29, 2015 14:14
Normalized City, State, Country names using R ggmap revgeocode() function to standardize location from lat x lon
library(ggmap)
library(data.table)
## download data.csv from betydb.org/sites.csv
sites <- fread('~/Downloads/data (11).csv')
]
latlon <- sites[(!is.null(Lat) & !is.null(Lon) & !grepl("Earth", Sitename)),
list(id = Id, lat = Lat, lon = Lon)]
#result <- list()