Skip to content

Instantly share code, notes, and snippets.

@dvictori
dvictori / rewrite_netcdf.R
Created March 14, 2022 11:43
Rewrite CDS CMIP6 NetCDF files to fix lat_bnds and lon_bnds problem
#!/usr/bin/env Rscript
# NetCDF rewrite - Data downloaded from CDS had some funny dimensions
# CDO did not like it. So rewriting
# usage: rewrite_netcdf input.nc output.nc
library(ncdf4)
# processin arguments ####
args <- commandArgs(trailingOnly = TRUE)
@dvictori
dvictori / fix_encoding.py
Created July 22, 2019 11:55
Get rid of bogus characters in UTF-8 encoding file
#!/usr/bin/env python3
import io
import os, sys
os.rename(sys.argv[1],'tempfile.sql')
saida = open(sys.argv[1], "w")
with io.open("tempfile.sql", encoding="utf-8", errors='ignore') as f:
@dvictori
dvictori / bh.R
Created July 20, 2019 18:37
Thornthwaite-Mather water balance
# balanco hídrico
# Baseado em:
# Pereira, Antonio Roberto. (2005). Simplificado o balanço hídrico de Thornthwaite-Mather.
# Bragantia, 64(2), 311-313. https://dx.doi.org/10.1590/S0006-87052005000200019
# Posse, GO
# https://edisciplinas.usp.br/pluginfile.php/3433083/mod_resource/content/1/Meteoro_aula11-Balanco_Hidrico.pdf
dados <- data.frame(p = c(271, 215, 230, 119, 20, 9, 5, 12, 30, 123, 223, 280),
etp = c(116, 97, 104, 88, 78, 63, 62, 90, 94, 109, 106, 106))
# campina Grande