Skip to content

Instantly share code, notes, and snippets.

View robertjwilson's full-sized avatar

Robert Wilson robertjwilson

  • Plymouth Marine Laboratory
  • Plymouth
View GitHub Profile
import nctoolkit as nc
ds = nc.open_data("IASI_METOPA_L2_CO_20190921_ULB-LATMOS_V6.4.0.nc")
ds.assign(mask = lambda x: x.longitude > 0 and x.longitude < 180 and x.latitude > 77 and x.latitude < 80, drop = True)
# ds.set_missing(0)
time_steps = list(ds.to_dataframe().reset_index().reset_index(drop = True).query("mask == 1").index)
time_steps = [x for x in time_steps]
ds.select(time = time_steps)
ds.to_nc("cropped.nc")
import os
from collections import OrderedDict
# Function to read line and then replace words based on what is in the dictionary ###
def replace_all(text, dic):
for i, j in dic.iteritems():
text = text.replace(i, j)
return text
library(tidyverse)
library(ggthemes)
library(animation)
library(cowplot)
library(ggpub)
library(readxl)
library(geonames)
# simple function to left join countries based on country names. Works with varients; UK/United Kingdom etc.
country_join <- function(x,y, by = "Country"){
col_2use <- sym(by)
dplyr::mutate(x, country_code54321 = countrycode::countrycode(!!col_2use, "country.name", "iso3c")) %>%
left_join(
library(tidyverse)
library(ncdf4)
bin_value <- function(x, bin_res) {
floor((x + bin_res / 2) / bin_res + 0.5) * bin_res - bin_res / 2
}
library(tidyverse)
library(ncdf4)
bin_value <- function(x, bin_res) {
floor((x + bin_res / 2) / bin_res + 0.5) * bin_res - bin_res / 2
}
import os
rootdir = '.'
# List of possible mirrors. This potentially needs to be updated over time as they update the mirrors
import urllib2
library(pryr)
library(tidyverse)
x <- data.frame(x = 1:1000)
y <- x
object_size(x)+ object_size(y)
object_size(x,y)
library(tidyverse)
order_conflicts <- function(fun, df){
find(fun) %>%
stringr::str_replace_all("package:", "")
}
conflictr <- function(){
x <- 1:10^4
sum_all <- function(x){
sum_all <- 0
for(i in 1:length(x))
sum_all <- sum_all + x[i]
sum_all
}
sum_all_cmp <- compiler::cmpfun(sum_all)