Skip to content

Instantly share code, notes, and snippets.

View bennyistanto's full-sized avatar

Benny Istanto bennyistanto

View GitHub Profile
@bennyistanto
bennyistanto / taylor_diagram_outmetrics.py
Last active January 20, 2023 14:05
Generate Taylor Diagram from the output metrics of corrected data to the source
# -*- coding: utf-8 -*-
"""
NAME
taylor_diagram_outmetrics.py
Generate Taylor Diagram from all metrics output
DESCRIPTION
Input data for this script will use metric.csv generated by imerg_cpc_biascorrection.py.
REQUIREMENT
It required numpy, pandas, metpy, matplotlib and xarray module. So it will work on any machine environment
EXAMPLES
@bennyistanto
bennyistanto / clip_netcdf_with_shp.py
Created January 5, 2023 18:01
Batch clip NetCDF in a folder with a shapefile
# -*- coding: utf-8 -*-
"""
NAME
clip_netcdf_with_shp.py
Batch clip NetCDF in a folder with a shapefile
DESCRIPTION
Input data for this script will be NetCDF files and a shapefile in a folder
This script can do batch clipping of NetCDF files, and save it in seperate folder
REQUIREMENT
It required glob, xarray, rasterio and shapely module. So it will work on any machine environment
@bennyistanto
bennyistanto / focal_regression.py
Created December 24, 2022 13:24
Focal regression using python
"""
This code uses the rasterio library to open the two input rasters and the scipy library
to perform the focal regression using the generic_filter function. The size parameter
specifies the size of the neighborhood around each pixel to use for the regression,
in this case a 3x3 window. The extra_arguments parameter is used to pass the second raster
to the np.polyfit function, which fits a polynomial of degree 1 (a linear regression) to
the two rasters. The result is a 3D array with the slope and intercept values for each pixel.
The code then extracts the slope and intercept arrays from the result and saves them to file
using rasterio.
@bennyistanto
bennyistanto / data_ppt.sh
Created October 10, 2022 14:21
TerraClimate's precipitation
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_ppt_1958.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_ppt_1959.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_ppt_1960.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_ppt_1961.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_ppt_1962.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_ppt_1963.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_ppt_1964.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_ppt_1965.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/d
@bennyistanto
bennyistanto / data_pet.sh
Created October 10, 2022 14:20
TerraClimate's potential evapotranspiration
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_pet_1958.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_pet_1959.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_pet_1960.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_pet_1961.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_pet_1962.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_pet_1963.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_pet_1964.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_pet_1965.nc
wget -c http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/d
@bennyistanto
bennyistanto / spei-terraclimate.md
Last active October 10, 2022 14:23
Procedure to calculate TerraClimate-based Standardized Precipitation-Evapotranspiration Index with area of interest Indonesia

TerraClimate-based Standardized Precipitation-Evapotranspiration Index in Indonesia

This section will explain on how to download TerraClimate's precipitation (ppt) and potential evapotranspiration (pet) monthly data in netCDF format and prepare it as input for Standardized Precipitation-Evapotranspiration Index (SPEI) calculation.

This step-by-step guide was tested using Mac mini Server - Late 2012, 2.3 GHz Quad-Core Intel Core i7, 16 GB 1600 MHz DDR3, running on macOS Catalina 10.15.7 and Windows 10 with Windows Subsystem for Linux enabled running on Thinkpad T480 2019, i7-8650U 1.9GHz, 64 GB 2400 MHz DDR4.

Index

@bennyistanto
bennyistanto / imerg_runningsum_daily.py
Created September 22, 2022 10:37
IMERG 2 days or more precipitation running sum
# -*- coding: utf-8 -*-
"""
NAME
imerg_runningsum_daily.py
Global IMERG daily running sum.
DESCRIPTION
Input data for this script will use IMERG daily data generated by imerg_nc2tif.py
This script can do calculation on consecutive 2 days or more precipitation running sum
REQUIREMENT
ArcGIS must installed before using this script, as it required arcpy module.
@bennyistanto
bennyistanto / lagrange-interpolation.py
Created August 29, 2022 04:09
Lagrange interpolation
# Python3 program for implementation
# of Lagrange's Interpolation
# To represent a data point corresponding to x and y = f(x)
class Data:
def __init__(self, x, y):
self.x = x
self.y = y
# function to interpolate the given data points
@bennyistanto
bennyistanto / IMERG_cwd_5mm.py
Last active August 28, 2022 05:17
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)
@bennyistanto
bennyistanto / IMERG_cwd_1mm.py
Last active March 4, 2022 13:56
Global IMERG daily consecutive wet days data extraction
# -*- coding: utf-8 -*-
"""
NAME
imerg_cwd_1mm.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 1mm of rainfall as a rainy day
PROCESS
(i) Extract IMERG's daily rainfall with value greater/less than 1mm (threshold for a day categoried as rainy day)