Skip to content

Instantly share code, notes, and snippets.

View scbrown86's full-sized avatar

Stuart Brown scbrown86

View GitHub Profile
@sadatnfs
sadatnfs / xarray_to_r.r
Last active January 6, 2023 10:49
Extracting an xarray based netcdf file to use in R
require(ncdf4)
require(ncdf4.helpers)
require(data.table)
## Get the name of the value vars in the nc file
get_nc_value_name <- function(nc_file) {
## Get names
nc_obj <- nc_open(nc_file)
name<-names(nc_obj$var)
@mainvoid007
mainvoid007 / installcdo.sh
Last active November 4, 2021 15:37
install cdo with grib2, hdf5, netcdf4
#!/bin/bash
# Institut für Wetter- und Klimakommunikation GmbH / Qmet
# O. Maywald <maywald@klimagipfel.de>
# This should install CDO with grib2, netcdf and HDF5 support. Note that the binaries are in /opt/cdo-install/bin.
# For further information look:
# http://www.studytrails.com/blog/install-climate-data-operator-cdo-with-netcdf-grib2-and-hdf5-support/
# docker-command
@alirobe
alirobe / reclaimWindows10.ps1
Last active June 7, 2024 16:24
This Windows 10 Setup Script turns off a bunch of unnecessary Windows 10 telemetery, bloatware, & privacy things. Not guaranteed to catch everything. Review and tweak before running. Reboot after running. Scripts for reversing are included and commented. Fork of https://github.com/Disassembler0/Win10-Initial-Setup-Script (different defaults). N.…
###
###
### UPDATE: For Win 11, I recommend using this tool in place of this script:
### https://christitus.com/windows-tool/
### https://github.com/ChrisTitusTech/winutil
### https://www.youtube.com/watch?v=6UQZ5oQg8XA
### iwr -useb https://christitus.com/win | iex
###
###
# somewhat hackish solution to:
# https://twitter.com/EamonCaddigan/status/646759751242620928
# based mostly on copy/pasting from ggplot2 geom_violin source:
# https://github.com/hadley/ggplot2/blob/master/R/geom-violin.r
library(ggplot2)
library(dplyr)
"%||%" <- function(a, b) {
@etiennebr
etiennebr / as.data.table.r
Last active November 13, 2023 11:24
Transform raster or terra object to data.table
#' Transform raster to data.table
#'
#' @param x Raster* object
#' @param row.names `NULL` or a character vector giving the row names for the data frame. Missing values are not allowed
#' @param optional logical. If `TRUE`, setting row names and converting column names (to syntactic names: see make.names) is optional
#' @param xy logical. If `TRUE`, also return the spatial coordinates
#' @param centroids logical. If TRUE return the centroids instead of all spatial coordinates (only relevant if xy=TRUE)
#' @param sepNA logical. If TRUE the parts of the spatial objects are separated by lines that are NA (only if xy=TRUE and, for polygons, if centroids=FALSE
#' @param ... Additional arguments (none) passed to `raster::as.data.frame`
#'