#! /usr/bin/env python # encoding: utf-8 ''' @author: nick.bearson@ssec.wisc.edu Copyright (c) 2012 University of Wisconsin SSEC. All rights reserved. Util script to, dun dun dun, make plots! ''' from optparse import OptionParser import os import matplotlib.pyplot as pyplot import numpy as np import matplotlib as mpl import pyvcm.vcm_break_bytes as vcmbb from pypre.files.HDF5File import HDF5File #from mpl_toolkits.basemap import Basemap """ Need two scripts: 1. plot 'gathered' files (not as important!) 2. plot VCM files """ # FIXME: do something that isn't a gross list of everything in our gathered file gathered = ["10 metre wind speed", "DEM_LW", "MODIS IGBP" , "VIIRS IGBP" , "Latitude" , "Longitude" , "NDVI" , "NISE" , "PrecipitableWater_L0", "SVI01_Reflectance" , "SVI02_Reflectance" , "SVI04_BrightnessTemperature" , "SVI05_BrightnessTemperature" , "SVM01_Reflectance" , "SVM04_Reflectance" , "SVM05_Reflectance" , "SVM07_Reflectance" , "SVM08_Reflectance" , "SVM09_Reflectance" , "SVM10_Reflectance" , "SVM11_Reflectance" , "SVM12_BrightnessTemperature" , "SVM12_Radiance" , "SVM13_BrightnessTemperature" , "SVM14_BrightnessTemperature" , "SVM15_BrightnessTemperature" , "SVM16_BrightnessTemperature" , "SatelliteAzimuthAngle" , "SatelliteZenithAngle" , "SolarAzimuthAngle" , "SolarZenithAngle" , # "SurfaceTemperature" , "snowice", "height" , # "nScans" , "qstlwm" , # "SurfaceTemperature_Water", # "SurfaceTemperature_Land", # "Land-sea mask", # "sfct mask land", # "sfct mask water", "SurfaceTemperature", ] def enum_gathered(filename): f = HDF5File(filename) for g in gathered: yield g, f.getDataset(g) def plot_field(name, field): outf = name.lower() name = name.replace('/', '_') name = name.replace(' ', '_') name = name.replace('(', '_') name = name.replace(')', '_') name = name.replace('\\', '_') name = name + ".png" figsize=(np.array(field.shape)/100.0)[::-1] mpl.rcParams.update({'figure.figsize':figsize}) fig = pyplot.figure(figsize=figsize) pyplot.axes([0,0,1,1]) # Make the plot occupy the whole canvas pyplot.axis('off') fig.set_size_inches(figsize) # fig = pyplot.figure() pyplot.imshow(field) # nticks = int(np.nanmax(field)) mini = np.nanmin(field).round() maxi = np.nanmax(field).round() ticks = np.linspace(mini, maxi, 11) # ticks = (ticks * np.nanmax(field)).round() print "ticks: ", ticks cb = pyplot.colorbar(ticks=ticks, shrink=0.7) # cb = pyplot.colorbar(ticks=range(0, nticks+1), shrink=0.7) pyplot.savefig(name) pyplot.close(fig) def plot_gathered(filename): e = enum_gathered(filename) for name, field in e: print "Plotting: ", name plot_field(name, field) def plot_vcm(filename): e = vcmbb.enum_cm(filename) for name, bitfield in e: print "Plotting: ", name plot_field(name, bitfield) def handle_args(): parser = OptionParser() parser.add_option("-g", "--gathered", dest="gathered", action="store_true", default=False) parser.add_option("-c", "--cloudmask", dest="cloudmask", action="store_true", default=False) # parser.add_option("-i", "--infile", action="store", type="string", dest="infile", help="Input file.") # parser.add_option("-o", "--outfile", action="store", type="string", dest="outfile", help="Output file.") # parser.add_option("-n", "--navfile", action="store", type="string", dest="navfile", help="Navigation file.") return parser.parse_args() def main(): (options, args) = handle_args() if options.gathered: plot_gathered(args[0]) elif options.cloudmask: plot_vcm(args[0]) else: print "MUST GIVE OPTION -c OR -g" # plot_gathered(args[0]) # plot_cloudmask(args[1]) if __name__ == '__main__': main()