Skip to content

Instantly share code, notes, and snippets.

@cbchisanga
cbchisanga / IMERG_cwd_5mm.py
Created August 28, 2022 05:17 — forked from bennyistanto/IMERG_cwd_5mm.py
Global IMERG daily consecutive wet days data extraction
# -*- coding: utf-8 -*-
"""
NAME
imerg_cwd_5mm.py
Global IMERG daily indices data extraction
DESCRIPTION
Input data for this script will use IMERG daily data generated by imerg_nc2tif.py
This script can do Consecutive Wet Days (CWD) calculation with threshold 5mm of rainfall as a rainy day
PROCESS
(i) Extract IMERG's daily rainfall with value greater/less than 5mm (threshold for a day categoried as rainy day)
@cbchisanga
cbchisanga / tiff2nc.py
Created August 18, 2022 14:40 — forked from bennyistanto/tiff2nc.py
Convert clipped Java boundary's CHIRPS GeoTIFFs in a folder to single NetCDF file with time dimension enabled and CF-Compliant
#!/usr/bin/env python
"""
-------------------------------------------------------------------------------------------------------------
Convert CHIRPS GeoTIFF in a folder to single NetCDF file with time dimension enabled that is CF-Compliant
http://cfconventions.org/cf-conventions/v1.6.0/cf-conventions.html
Based on Rich Signell's answer on StackExchange: https://gis.stackexchange.com/a/70487
This script was tested using CHIRPS dekad data. Adjustment is needed if using other timesteps data for CHIRPS
NCO (http://nco.sourceforge.net) must be installed before using this script
#!/bin/bash
# Docker-ubuntu-trusty compatible CDO install script
export DEBIAN_FRONTEND=noninteractive
apt() {
apt-get -qq install $1 &>/dev/null
}
apt-get update &>/dev/null && apt-get -y upgrade &>/dev/null
@cbchisanga
cbchisanga / installcdo.sh
Created June 25, 2019 11:50 — forked from mainvoid007/installcdo.sh
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
@cbchisanga
cbchisanga / code.R
Last active August 29, 2015 14:22 — forked from leeper/code.R
read.fwf2 <- function (file, widths, header = FALSE, sep = "\t", skip = 0,
row.names, col.names, n = -1, ...)
{
doone <- function(x) {
x <- substring(x, first, last)
x[!nzchar(x)] <- NA_character_
paste0(x, collapse = sep)
}
if (is.list(widths)) {
recordlength <- length(widths)