Skip to content

Instantly share code, notes, and snippets.

View bennyistanto's full-sized avatar

Benny Istanto bennyistanto

View GitHub Profile
@bennyistanto
bennyistanto / IMERG_nc2tif_subset.py
Last active March 2, 2022 07:32
Global IMERG daily nc4 translation to GeoTIFF and mask the sea
# -*- coding: utf-8 -*-
"""
NAME
imerg_nc2tif_subset.py
Global IMERG daily nc4 translation to GeoTIFF
DESCRIPTION
Input data for this script will use IMERG Final or Late Run downloaded from NASA website
This script can do translation from nc4 to GeoTIFF and mask the sea.
REQUIREMENT
ArcGIS must installed before using this script, as it required arcpy module.
@bennyistanto
bennyistanto / extract_imerg_daily_indices.py
Created December 21, 2021 02:12
Extract bulk of time series IMeRG's nc4 in a folder to GeoTIFF then calculate dry and wet days
# -*- coding: utf-8 -*-
"""
NAME
extract_imerg_daily_indices.py
Global IMERG daily indices data extraction
DESCRIPTION
Input data for this script will use IMERG Final or Late Run downloaded from NASA website
https://gpm1.gesdisc.eosdis.nasa.gov/data/GPM_L3/
This script can do:
(i) Translation from nc4 to GeoTIFF, and
@bennyistanto
bennyistanto / extract_spei_dry_month.py
Last active October 10, 2022 14:45
TerraClimate's SPEI drought characteristics
# -*- coding: utf-8 -*-
"""
NAME
extract_spei_dry_month.py
DESCRIPTION
Input data for this script will use TERRACLIMATE's SPEI-12, generated using pypi climate-indices
This script will calculate number of:
(i) Dry month,
(ii) Total dry month
# -*- coding: utf-8 -*-
"""
Calculate annual rainfall from TERRACLIMATE Precipitation data, 1958-2020
"""
import arcpy
def AnnualRainfall(): # Annual Rainfall
# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = False
## Reorder dimension for SPI and SPEI calculation
ncpdq -a lat,lon,time /Users/benny/Temp/TERRACLIMATE/CDO/Tile11/Tile11_TerraClimate_pet_1958_2020.nc /Users/benny/Temp/TERRACLIMATE/CDO/Tile11/llt_Tile11_TerraClimate_pet_1958_2020.nc
ncpdq -a lat,lon,time /Users/benny/Temp/TERRACLIMATE/CDO/Tile11/Tile11_TerraClimate_ppt_1958_2020.nc /Users/benny/Temp/TERRACLIMATE/CDO/Tile11/llt_Tile11_TerraClimate_ppt_1958_2020.nc
ncks --fix_rec_dmn lat /Users/benny/Temp/TERRACLIMATE/CDO/Tile11/llt_Tile11_TerraClimate_pet_1958_2020.nc -o outfixed.nc4 ; mv outfixed.nc4 /Users/benny/Temp/TERRACLIMATE/CDO/Tile11/llt_Tile11_TerraClimate_pet_1958_2020.nc
ncks --fix_rec_dmn lat /Users/benny/Temp/TERRACLIMATE/CDO/Tile11/llt_Tile11_TerraClimate_ppt_1958_2020.nc -o outfixed.nc4 ; mv outfixed.nc4 /Users/benny/Temp/TERRACLIMATE/CDO/Tile11/llt_Tile11_TerraClimate_ppt_1958_2020.nc
ncks --mk_rec_dmn time /Users/benny/Temp/TERRACLIMATE/CDO/Tile11/llt_Tile11_TerraClimate_pet_1958_2020.nc -o outunlim.nc4 ; mv outunlim.nc4 /Users/benny/Temp/T
# Haversine formula using Py3
import math
def haversine(lat1, lon1, lat2, lon2):
# distance between latitudes and longitudes
dLat = (lat2 - lat1) * math.pi / 180.0
dLon = (lon2 - lon1) * math.pi / 180.0
# convert to radians
@bennyistanto
bennyistanto / gfs_ee_parse.py
Created June 16, 2021 09:46
Check GFS data availability from EarthEngine
import json
import csv
import sys
import datetime as dt
with open('result.json') as f:
content = json.load(f)
w = csv.writer(sys.stdout)
@bennyistanto
bennyistanto / SPI_based_on_CHIRPS_GeoTIFF.md
Last active September 3, 2025 13:56
Calculate SPI using CHIRPS data

Calculate SPI using monthly rainfall data in GeoTIFF format

These last few months, I have tried a lot of difference formulation to calculate Standardized Precipitation Index (SPI) based on rainfall data in netCDF format, check below files as a background:

The reason why I use rainfall in netCDF format in above files because the software to calculate SPI: climate-indices python package will only accept single netCDF as input, and the SPI script will read the netCDF input file based on time dimension.

Converting raster files into netCDF is easy using GDAL or other GIS software, but to make the time dimension enabled n

@bennyistanto
bennyistanto / simpul-jaringan-indonesia.MD
Last active February 23, 2021 04:23
Daftar simpul jaringan Infrastruktur Data Spasial Indonesia.

Simpul Jaringan IDSN Indonesia

Update: 23 Feb 2021

Daftar simpul jaringan Infrastruktur Data Spasial Indonesia.

Daftar ini memuat alamat (server maupun geoportal) dari simpul jaringan Infastruktur Data Spasial yang ada di Indonesia. Referensi awal berasal dari https://github.com/ppids-ugm/simpul-jaringan-indonesia tetapi banyak alamat dari beberapa Kementerian sudah tidak aktif lagi. List berikut diupdate berdasarkan informasi dari Ina-Geoportal https://tanahair.indonesia.go.id/portal-web

Index

@bennyistanto
bennyistanto / tiff2nc.py
Last active August 18, 2022 14:40
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