Skip to content

Instantly share code, notes, and snippets.

@bennyistanto
Created July 1, 2020 07:47
Show Gist options
  • Save bennyistanto/758bd32ef843de3e3287f8336c8b9d3a to your computer and use it in GitHub Desktop.
Save bennyistanto/758bd32ef843de3e3287f8336c8b9d3a to your computer and use it in GitHub Desktop.
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"
ws_out = r"Z:\Temp\CHIRPS\SPI\Month1D1\Outputs"
#CHIRPS geotiff to nc
variable = "precip"
units = "mm/month"
XDimension = "x"
YDimension = "y"
bandDimension = ""
arcpy.env.workspace = ws_in
rasters = arcpy.ListRasters("*","TIF")
for rasname in rasters:
raspath = os.path.join(ws_in, rasname)
name, ext = os.path.splitext(rasname)
netcdf = os.path.join(ws_out, name)
# Process: RasterToNetCDF
print "Exporting {0} to {1}".format(rasname, netcdf)
arcpy.RasterToNetCDF_md(raspath, netcdf, variable, units, XDimension,
YDimension, bandDimension)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment