Skip to content

Instantly share code, notes, and snippets.

View bennyistanto's full-sized avatar

Benny Istanto bennyistanto

View GitHub Profile
@bennyistanto
bennyistanto / percentile.py
Created June 19, 2020 07:10
Extract percentile from each cell based on raster timeseries
#!/usr/bin/python
# -*- coding: utf8 -*-
import arcpy
import numpy
import sys
#Overwrite the output if exist
arcpy.env.overwriteOutput = True
reload(sys)
@bennyistanto
bennyistanto / CHIRPS_sum2days.py
Last active June 19, 2020 07:32
Generate 2days rolling accumulation of rainfall, and calculate maximum value from the result using arcpy
import arcpy
import os
from datetime import date
from datetime import timedelta
import multiprocessing
#Overwrite the output if exist
arcpy.env.overwriteOutput = True
#Working directory
@bennyistanto
bennyistanto / CHIRPS_sum3days.py
Last active June 19, 2020 07:32
Generate 3days rolling accumulation of rainfall, and calculate maximum value from the result using arcpy
import arcpy
import os
from datetime import date
from datetime import timedelta
import multiprocessing
#Overwrite the output if exist
arcpy.env.overwriteOutput = True
#Working directory
@bennyistanto
bennyistanto / CHIRPS_sum4days.py
Created June 19, 2020 07:36
Generate 4days rolling accumulation of rainfall, and calculate maximum value from the result using arcpy
import arcpy
import os
from datetime import date
from datetime import timedelta
import multiprocessing
#Overwrite the output if exist
arcpy.env.overwriteOutput = True
#Working directory
@bennyistanto
bennyistanto / CHIRPS_sum5days.py
Created June 19, 2020 07:41
Generate 5days rolling accumulation of rainfall, and calculate maximum value from the result using arcpy
import arcpy
import os
from datetime import date
from datetime import timedelta
import multiprocessing
#Overwrite the output if exist
arcpy.env.overwriteOutput = True
#Working directory
#This script required daily CHIRPS data and previous drspell data, if previous data not available
#then it will start with 0.
import os
import arcpy
from arcpy.sa import *
from datetime import date, timedelta
# to execute first DSLR data
def execute_first_DSLR(_tiffolder, _DSLRFolder, threshold):
sr = arcpy.SpatialReference(4326)
#This script required daily CHIRPS data and previous wetspell data, if previous data not available
#then it will start with 0.
import os
import arcpy
from arcpy.sa import *
from datetime import date, timedelta
# to execute first DSLD data
def execute_first_DSLD(_tiffolder, _DSLDFolder, threshold):
sr = arcpy.SpatialReference(4326)
@bennyistanto
bennyistanto / Tiff_to_NetCDF.py
Created July 1, 2020 07:47
Convert multiple monthly CHIRPS GeoTIFF in a folder to NetCDF
#!/usr/bin/python
# -*- coding: utf8 -*-
import arcpy
import os
#Overwrite the output if exist
arcpy.env.overwriteOutput = True
# Set local variables
ws_in = r"Z:\Temp\CHIRPS\SPI\Month1D1"
@bennyistanto
bennyistanto / imerg.sh
Created July 5, 2020 15:11
Arrange IMERG data based on number of days within month
#!/bin/bash
# Arrange IMERG data based on number of days within month
# Source: https://github.com/andyprasetya
# -- Start script: change directory ke target directory, misal: 'imerg'
cd imerg
# -- Set shell option ke 'nullglob' - optional, bisa di-comment/disabled
shopt -s nullglob
# Mulai loop ke seluruh file dalam target directory.
# Biasanya menggunakan 'i', tapi ini pakai 'file' untuk memperjelas penulisan variable
@bennyistanto
bennyistanto / GeoTIFF_to_NetCDF.py
Last active January 4, 2024 00:52
Convert CHIRPS GeoTIFF in a folder to single NetCDF file with time dimension enabled that is CF-Compliant
#!/usr/bin/env python
"""
-------------------------------------------------------------------------------------------------------------
Convert raster 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 TerraClimate monthly data. Adjustment is needed if using other timesteps data
NCO (http://nco.sourceforge.net), GDAL, NetCDF4, numpy must be installed before using this script