Created
July 1, 2020 07:47
-
-
Save bennyistanto/758bd32ef843de3e3287f8336c8b9d3a to your computer and use it in GitHub Desktop.
Convert multiple monthly CHIRPS GeoTIFF in a folder to NetCDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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