ocssw
V2022
|
mapgen_overlay.py
Go to the documentation of this file.
40 #proj=+proj=aea +ellps=WGS84 +datum=WGS84 +lon_0=-80.000000 +lat_0=27.500000 +lat_1=15.000000 +lat_2=40.000000
44 print("Since I have to trust querying https://epsg.io/ (and need an internet connection to do so)...things might go wrong...but we'll give it a try :)")
60 crs = ccrs.AlbersEqualArea(central_longitude=float(proj['lon_0']), central_latitude=float(proj['lat_0']), standard_parallels=(float(proj['lat_1']), float(proj['lat_2'])))
64 crs = ccrs.LambertConformal(central_longitude=float(proj['lon_0']), central_latitude=float(proj['lat_0']), standard_parallels=(float(proj['lat_1']), float(proj['lat_2'])))
68 crs = ccrs.TransverseMercator(central_longitude=float(proj['lon_0']),central_latitude=float(proj['lat_0']), approx=False)
72 crs = ccrs.Stereographic(central_longitude=float(proj['lon_0']), central_latitude=float(proj['lat_0']), true_scale_latitude=float(proj['lat_ts']))
74 crs = ccrs.Orthographic(central_longitude=float(proj['lon_0']), central_latitude=float(proj['lat_0']))
95 grid = np.round(np.linspace(np.floor(minval-increment/2),np.ceil(maxval+increment/2),increment),decimals=0)
101 parser = argparse.ArgumentParser(description="add overlays to mapped PNG images output from mapgen (or l3mapgen)")
103 parser.add_argument('--projinfo', '-p', type=str, default=None, help='input projection info file; default: <ifile>.projtxt')
104 parser.add_argument('--ofile', '-o', type=str, default=None, help='output filename; default: <ifile basename>.overlay.png')
107 parser.add_argument('--label', type=str, default=None, help='add label string (e.g. source file for the image)')
109 parser.add_argument('--colorbar', action='store_true',help='add a colorbar; requires datamin, datamax; optionally: scaletype, palfile, cbartitle')
110 parser.add_argument('--datamin', type=float, default=None, help='minimum value for colorbar scale')
111 parser.add_argument('--datamax', type=float, default=None, help='maximum value for colorbar scale')
112 parser.add_argument('--scale_type', choices=['linear','log'], default=None, help='colorbar scaling method; default: linear')
113 parser.add_argument('--palfile', type=str, default='default-black0.pal', help='colorbar palette name; see $OCDATAROOT/common/palette/')
126 args = parser.parse_args()
128 ofile = args.ofile
130 ofilePath = Path(args.ifile)
131 ofile = "{dir}/{stem}.{ext}".format(dir=ofilePath.parent,stem=ofilePath.stem, ext='overlay.png')
133 pinfofile = args.projinfo
137 pinfo = {}
149 pinfokeys = ['minX','maxX','minY','maxY','north','south','east','west','datamin','datamax','scale_type','proj']
157 img = plt.imread(args.ifile)
160 dpi = 72
166 padheight = np.ceil(imgwidth*0.3)
167 padwidth = np.ceil(imgheight*0.3)
169 figwidth = np.round(imgwidth + padwidth, decimals=2)
170 figheight = np.round(imgheight + padheight, decimals=2)
173 fig = plt.figure(figsize=(figwidth, figheight), dpi=dpi)
180 ax = plt.subplot2grid((figrows,7),(0,0),rowspan=figrows-bottom, colspan=7, fig=fig,projection=crs)
190 ax.set_title(args.label, fontsize=18)
197 labelsize = 14 * (figheight / 14.0)
219 gl.ylocator = mticker.FixedLocator(lats)
223 cbax = plt.subplot2grid((figrows,7),(figrows-bottom,2),fig=fig,rowspan=bottom,colspan=3)
236 cb = mpl.colorbar.ColorbarBase(cbax, cmap=cmap,
242 cb.set_label(args.cbartitle,size=labelsize)
246 plt.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9)
248 plt.savefig(ofile, dpi=dpi, bbox_inches='tight', pad_inches=0.2,transparent=args.use_transparency)
def calculate_gridline_increments(minval, maxval)
Definition: mapgen_overlay.py:87