Last active
May 12, 2018 02:08
-
-
Save bennyistanto/a931ee79815fdaa41ea3f590d6faf3d1 to your computer and use it in GitHub Desktop.
TRMM binary data export
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
TRMM data process | |
Easy way to convert it into GeoTIFF format | |
Edit 3b42rt_daily.ctl using text editor, and make sure you are entering the correct end date and total file | |
Use CDO, open command-prompt and type this code | |
cdo -f nc import_binary 3b42rt_daily.ctl 3b42rt_daily.nc | |
After done the conversion, you will have a single netCDF file which is can be opened using ArcMap | |
ArcToolbox/Multidimension tools/Make NetCDF Raster Layer | |
Or you can export it to GeoTIFF using python (script NetCDF_to_Tiff.py provided) | |
python NetCDF_to_Tiff.py -i inputdata.nc -o output_directory | |
—— | |
dset ^./%y4/3B42RT_daily.%y4.%m2.%d2.bin | |
options template big_endian | |
title TRMM 3B42RT daily rainfall | |
undef -99999.0 | |
xdef 1440 linear 0.125 0.25000000 | |
ydef 480 linear -59.8750000 0.25000000 | |
zdef 1 levels 1000 | |
Tdef 31 linear 1jan2015 1dy | |
* Please check on data files for the end date | |
vars 1 | |
r 0 99 daily acc Rain (mm) | |
endvars | |
—— | |
31=Total data | |
1Jan2015=start data |
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/env python | |
""" | |
SYNOPSIS | |
NetCDF_to_Tiff [-h,--help] [-v,--verbose] [-i,--input] [-o, --output] | |
DESCRIPTION | |
This script converts a NetCDF time-series to a set | |
of TIFF images, one for each time step. It is designed | |
for converting TRMM data. | |
EXAMPLES | |
python NetCDF_to_Tiff.py -i d:/data/3B42RT_daily.nc -o d:/data/3B42RT_daily/ | |
EXIT STATUS | |
TODO: List exit codes | |
AUTHOR | |
Rochelle O'Hagan <[email protected]> | |
LICENSE | |
This script is in the public domain, free from copyrights or restrictions. | |
VERSION | |
$Id$ | |
""" | |
import arcpy | |
import os, optparse, time, sys, traceback | |
def main(in_netcdf, out_dir): | |
try: | |
nc_fp = arcpy.NetCDFFileProperties(in_netcdf) | |
nc_dim = 'time' | |
in_netcdf_layer = os.path.basename(in_netcdf).split('.')[0] | |
out_layer = "{0}_layer".format(in_netcdf_layer) | |
arcpy.MakeNetCDFRasterLayer_md(in_netcdf, "r", "lon", "lat", out_layer, "", "", "") | |
print "Created NetCDF Layer for " + out_layer | |
for i in range(0, nc_fp.getDimensionSize(nc_dim)): | |
nc_dim_value = nc_fp.getDimensionValue(nc_dim, i) | |
print("\tDimension value: {0}".format(nc_dim_value)) | |
print("\tDimension index: {0}".format(nc_fp.getDimensionIndex(nc_dim, nc_dim_value))) | |
dmy = nc_dim_value.split('/') | |
date_str = "{2}.{1}.{0}".format(dmy[0], dmy[1], dmy[2]) | |
out_layer_file = "{0}{1}.{2}.tif".format(out_dir, in_netcdf_layer, date_str) | |
# Execute SelectByDimension tool | |
valueSelect = ["time", i] | |
net_layer = arcpy.SelectByDimension_md(out_layer, [valueSelect], "BY_INDEX") | |
#define output tif name | |
arcpy.CopyRaster_management(net_layer, out_layer_file) | |
arcpy.AddMessage(out_layer_file + " " "exported" + " " + "successfully") | |
except Exception as err: | |
print(err) | |
if __name__ == '__main__': | |
try: | |
start_time = time.time() | |
parser = optparse.OptionParser(formatter=optparse.TitledHelpFormatter(), usage=globals()['__doc__'], version='$Id$') | |
parser.add_option ('-v', '--verbose', action='store_true', default=False, help='verbose output') | |
parser.add_option ('-i', '--input', dest='netcdf_file', action='store', help='netcdf filename') | |
parser.add_option ('-o', '--output', dest='output_dir', action='store', help='output directory') | |
(options, args) = parser.parse_args() | |
#if len(args) < 1: | |
# parser.error ('missing argument') | |
if options.verbose: print time.asctime() | |
input_f = "r:/TRMM/3b42rt_daily.nc" # Default value - should be set using options | |
if options.netcdf_file: | |
input_f = options.netcdf_file | |
print 'netcdf file=', input_f | |
output_d = "r:/TRMM/test2/" # Default value - should be set using options | |
if options.output_dir: | |
output_d = options.output_dir | |
print 'output directory=', output_d | |
main(input_f, output_d) | |
if options.verbose: print time.asctime() | |
if options.verbose: print 'TOTAL TIME IN MINUTES:', | |
if options.verbose: print (time.time() - start_time) / 60.0 | |
sys.exit(0) | |
except KeyboardInterrupt, e: # Ctrl-C | |
raise e | |
except SystemExit, e: # sys.exit() | |
raise e | |
except Exception, e: | |
print 'ERROR, UNEXPECTED EXCEPTION' | |
print str(e) | |
traceback.print_exc() | |
os._exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment