-
Notifications
You must be signed in to change notification settings - Fork 408
Generalize EC cell widths function #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <ColorMaps> | ||
| <ColorMap space="CIELAB" indexedLookup="false" name="3Wbgy5"> | ||
| <Point x="0.000000" o="1" r="0.831373" g="0.909804" b="0.980392"/> | ||
| <Point x="0.012500" o="1" r="0.749020" g="0.862745" b="0.960784"/> | ||
| <Point x="0.025000" o="1" r="0.694118" g="0.827451" b="0.941176"/> | ||
| <Point x="0.050000" o="1" r="0.568627" g="0.760784" b="0.921569"/> | ||
| <Point x="0.075000" o="1" r="0.450980" g="0.705882" b="0.901961"/> | ||
| <Point x="0.100000" o="1" r="0.345098" g="0.643137" b="0.858824"/> | ||
| <Point x="0.125000" o="1" r="0.247059" g="0.572549" b="0.819608"/> | ||
| <Point x="0.150000" o="1" r="0.180392" g="0.521569" b="0.780392"/> | ||
| <Point x="0.160000" o="1" r="0.149020" g="0.490196" b="0.749020"/> | ||
| <Point x="0.180000" o="1" r="0.129412" g="0.447059" b="0.709804"/> | ||
| <Point x="0.200000" o="1" r="0.101961" g="0.427451" b="0.690196"/> | ||
| <Point x="0.210000" o="1" r="0.094118" g="0.403922" b="0.658824"/> | ||
| <Point x="0.220000" o="1" r="0.090196" g="0.392157" b="0.639216"/> | ||
| <Point x="0.230000" o="1" r="0.082353" g="0.368627" b="0.619608"/> | ||
| <Point x="0.240000" o="1" r="0.070588" g="0.352941" b="0.600000"/> | ||
| <Point x="0.250000" o="1" r="0.066667" g="0.329412" b="0.568627"/> | ||
| <Point x="0.260000" o="1" r="0.074510" g="0.313725" b="0.541176"/> | ||
| <Point x="0.270000" o="1" r="0.086275" g="0.305882" b="0.509804"/> | ||
| <Point x="0.280000" o="1" r="0.094118" g="0.286275" b="0.478431"/> | ||
| <Point x="0.290000" o="1" r="0.101961" g="0.278431" b="0.450980"/> | ||
| <Point x="0.300000" o="1" r="0.109804" g="0.266667" b="0.411765"/> | ||
| <Point x="0.310000" o="1" r="0.113725" g="0.258824" b="0.380392"/> | ||
| <Point x="0.320000" o="1" r="0.113725" g="0.250980" b="0.349020"/> | ||
| <Point x="0.330000" o="1" r="0.109804" g="0.266667" b="0.321569"/> | ||
| <Point x="0.340000" o="1" r="0.105882" g="0.301961" b="0.262745"/> | ||
| <Point x="0.350000" o="1" r="0.094118" g="0.309804" b="0.243137"/> | ||
| <Point x="0.360000" o="1" r="0.082353" g="0.321569" b="0.227451"/> | ||
| <Point x="0.370000" o="1" r="0.074510" g="0.341176" b="0.219608"/> | ||
| <Point x="0.380000" o="1" r="0.070588" g="0.360784" b="0.211765"/> | ||
| <Point x="0.390000" o="1" r="0.066667" g="0.380392" b="0.215686"/> | ||
| <Point x="0.400000" o="1" r="0.062745" g="0.400000" b="0.176471"/> | ||
| <Point x="0.425000" o="1" r="0.074510" g="0.419608" b="0.145098"/> | ||
| <Point x="0.450000" o="1" r="0.086275" g="0.439216" b="0.117647"/> | ||
| <Point x="0.475000" o="1" r="0.121569" g="0.470588" b="0.117647"/> | ||
| <Point x="0.500000" o="1" r="0.184314" g="0.501961" b="0.149020"/> | ||
| <Point x="0.525000" o="1" r="0.254902" g="0.541176" b="0.188235"/> | ||
| <Point x="0.550000" o="1" r="0.325490" g="0.580392" b="0.231373"/> | ||
| <Point x="0.575000" o="1" r="0.403922" g="0.619608" b="0.278431"/> | ||
| <Point x="0.600000" o="1" r="0.501961" g="0.670588" b="0.333333"/> | ||
| <Point x="0.630000" o="1" r="0.592157" g="0.729412" b="0.400000"/> | ||
| <Point x="0.650000" o="1" r="0.741176" g="0.788235" b="0.490196"/> | ||
| <Point x="0.670000" o="1" r="0.858824" g="0.858824" b="0.603922"/> | ||
| <Point x="0.700000" o="1" r="0.921569" g="0.835294" b="0.580392"/> | ||
| <Point x="0.750000" o="1" r="0.901961" g="0.729412" b="0.494118"/> | ||
| <Point x="0.800000" o="1" r="0.858824" g="0.584314" b="0.388235"/> | ||
| <Point x="0.850000" o="1" r="0.800000" g="0.439216" b="0.321569"/> | ||
| <Point x="0.900000" o="1" r="0.678431" g="0.298039" b="0.203922"/> | ||
| <Point x="0.950000" o="1" r="0.549020" g="0.168627" b="0.109804"/> | ||
| <Point x="0.975000" o="1" r="0.478431" g="0.082353" b="0.047059"/> | ||
| <Point x="1.000000" o="1" r="0.450980" g="0.007843" b="0.000000"/> | ||
| <NaN r="0.25" g="0" b="0"/> | ||
| </ColorMap> | ||
| </ColorMaps> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,16 @@ | |
| from __future__ import absolute_import, division, print_function, \ | ||
| unicode_literals | ||
|
|
||
| import os | ||
| import xarray | ||
| import argparse | ||
| import matplotlib | ||
| matplotlib.use('Agg') | ||
| import matplotlib.pyplot as plt | ||
| import cartopy.crs as ccrs | ||
| import cartopy | ||
| import xml.etree.ElementTree as ET | ||
| import pkg_resources | ||
| from matplotlib.colors import LinearSegmentedColormap | ||
|
|
||
| from mpas_tools.conversion import convert | ||
| from mpas_tools.io import write_netcdf | ||
|
|
@@ -51,32 +57,38 @@ def build_mesh( | |
| name='cellWidth') | ||
| cw_filename = 'cellWidthVsLatLon.nc' | ||
| da.to_netcdf(cw_filename) | ||
| plot_cellWidth=True | ||
| plot_cellWidth = True | ||
| if plot_cellWidth: | ||
| import matplotlib | ||
| from cartopy import config | ||
| import cartopy.crs as ccrs | ||
| matplotlib.use('Agg') | ||
| fig = plt.figure() | ||
| fig.set_size_inches(16.0, 8.0) | ||
| plt.clf() | ||
| map_name = '3Wbgy5' | ||
| xmlFile = pkg_resources.resource_filename( | ||
| __name__, '{}.xml'.format(map_name)) | ||
| _read_xml_colormap(xmlFile, map_name) | ||
|
|
||
| fig = plt.figure(figsize=[16.0, 8.0]) | ||
| ax = plt.axes(projection=ccrs.PlateCarree()) | ||
| ax.set_global() | ||
| im = ax.imshow(cellWidth, origin='lower', transform=ccrs.PlateCarree( | ||
| ), extent=[-180, 180, -90, 90], cmap='jet') | ||
| ax.coastlines() | ||
| im = ax.imshow(cellWidth, origin='lower', | ||
| transform=ccrs.PlateCarree(), | ||
| extent=[-180, 180, -90, 90], cmap=map_name, | ||
| zorder=0) | ||
| ax.add_feature(cartopy.feature.LAND, edgecolor='black', zorder=1) | ||
| gl = ax.gridlines( | ||
| crs=ccrs.PlateCarree(), | ||
| draw_labels=True, | ||
| linewidth=1, | ||
| color='gray', | ||
| alpha=0.5, | ||
| linestyle='-') | ||
| linestyle='-', zorder=2) | ||
| gl.xlabels_top = False | ||
| gl.ylabels_right = False | ||
| plt.title('Grid cell size, km') | ||
| plt.title( | ||
| 'Grid cell size, km, min: {:.1f} max: {:.1f}'.format( | ||
| cellWidth.min(),cellWidth.max())) | ||
| plt.colorbar(im, shrink=.60) | ||
| plt.savefig('cellWidthGlobal.png') | ||
| fig.canvas.draw() | ||
| plt.tight_layout() | ||
|
Comment on lines
+88
to
+89
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cleans up some whitespace.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| plt.savefig('cellWidthGlobal.png', bbox_inches='tight') | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, good to know. |
||
| plt.close() | ||
|
|
||
| else: | ||
| cellWidth, x, y, geom_points, geom_edges = define_base_mesh.cellWidthVsXY() | ||
|
|
@@ -130,6 +142,33 @@ def build_mesh( | |
| print("***********************************************") | ||
|
|
||
|
|
||
| def _read_xml_colormap(xmlFile, mapName): | ||
| """Read in an XML colormap""" | ||
|
|
||
| xml = ET.parse(xmlFile) | ||
|
|
||
| root = xml.getroot() | ||
| colormap = root.findall('ColorMap') | ||
| if len(colormap) > 0: | ||
| colormap = colormap[0] | ||
| colorDict = {'red': [], 'green': [], 'blue': []} | ||
| for point in colormap.findall('Point'): | ||
| x = float(point.get('x')) | ||
| color = [float(point.get('r')), float(point.get('g')), | ||
| float(point.get('b'))] | ||
| colorDict['red'].append((x, color[0], color[0])) | ||
| colorDict['green'].append((x, color[1], color[1])) | ||
| colorDict['blue'].append((x, color[2], color[2])) | ||
| cmap = LinearSegmentedColormap(mapName, colorDict, 256) | ||
|
|
||
| _register_colormap_and_reverse(mapName, cmap) | ||
|
|
||
|
|
||
| def _register_colormap_and_reverse(mapName, cmap): | ||
| plt.register_cmap(mapName, cmap) | ||
| plt.register_cmap('{}_r'.format(mapName), cmap.reversed()) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('--preserve_floodplain', action='store_true') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you downloaded this directly from Paraview? That was smart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, copied from MPAS-Analysis, which gives proper credit and got it from the original source (LANL's own SciVisColor web page, I believe).