Comments (5)
I can see many uses for that. Unfortunately, that ends up being a limitation of matplotlib, so there's not much we can do; feel free to open an issue there. It is possible to use imagemagick
to convert PNG files from matplotlib into the GIFs you're interested in.
from metpy.
Here is a solution that works rather well converting them to transparent PNGs with PIL. These can be easily transported into Google Earth.
#SETUP PLOT TO SAVE WITHOUT ANY BORDERS OR INFO
fig = plt.figure(frameon=False)
cmap = ctables.registry.get_colortable('Carbone42')
plt.pcolormesh(xlocs, ylocs, data, cmap=cmap)
plt.gca().set_aspect('equal','datalim')
#SET LIMITS IF WANTED
plt.xlim(-160, 160)
plt.ylim(-160, 160)
#SETUP FIGURE TO HAVE JUST IMAGE DATA
a=fig.gca()
a.set_frame_on(False)
a.set_xticks([]); a.set_yticks([])
plt.axis('off')
plt.savefig('myimage.png', dpi=430, bbox_inches='tight', pad_inches = 0)
#******************* CONVERT TO TRANSPARENT *********************
# CONVERT ALL WHITE PIXELS TO TRANSPARENT
img = Image.open('myimage.png')
img = img.convert("RGBA")
pixdata = img.load()
for y in range(img.size[1]):
for x in range(img.size[0]):
if pixdata[x, y] == (255, 255, 255, 255):
pixdata[x, y] = (255, 255, 255, 0)
img.save('myimage.png', "PNG")
from metpy.
Well if transparent PNGs are enough (before you specifically asked about GIF
), then you can just set it to transparent using the matplotlib API:
fig.patch.set_alpha(0.0)
a.patch.set_alpha(0.0)
I just tried this out and it worked fine.
from metpy.
Much easier. Thanks!
I did notice something else. On the level II example I think the functions of MetPy are assuming that the level II scans will always have all of the data it requests. I have noticed a few of the files I download throw errors. I think it may be because they are missing data on some of the radial scans. I have had to catch the following errors on occasion:
try:
name = each
fn = each.split('\\')[-1]
f = Level2File(name)
#f.sweeps[0][0]
# Pull data out of the file
sweep = 0
# First item in ray is header, which has azimuth angle
az = np.array([ray[0].az_angle for ray in f.sweeps[sweep]])
# 5th item is a dict mapping a var name (byte string) to a tuple of (header, data array)
ref_hdr = f.sweeps[sweep][0][4][b'REF'][0]
ref_range = np.arange(ref_hdr.num_gates) * ref_hdr.gate_width + ref_hdr.first_gate
ref = np.array([ray[4][b'REF'][1] for ray in f.sweeps[sweep]])
var_data = ref
var_range = ref_range
# Turn into an array, then mask
data = ma.array(var_data)
data[np.isnan(data)] = ma.masked
# Convert az,range to x,y
xlocs = var_range * np.sin(np.deg2rad(az[:, np.newaxis]))
ylocs = var_range * np.cos(np.deg2rad(az[:, np.newaxis]))
#******************* SETUP AND SAVE FIGURE ********************
fig = plt.figure(frameon=False)
#norm, cmap = ctables.registry.get_with_steps('NWSReflectivity', 16, 16)
cmap = ctables.registry.get_colortable('Carbone42')
plt.pcolormesh(xlocs, ylocs, data, cmap=cmap)
plt.gca().set_aspect('equal','datalim')
#SET LIMITS IF WANTED
plt.xlim(-160, 160)
plt.ylim(-160, 160)
# fig.tight_layout()
a=fig.gca()
a.set_frame_on(False)
a.set_xticks([]); a.set_yticks([])
fig.patch.set_alpha(0.0)
a.patch.set_alpha(0.0)
plt.axis('off')
plt.savefig(each + '.png', dpi=430, bbox_inches='tight', pad_inches = 0)
self.time['text'] = fn + ".png Saved"
plt.clf() #CLEAR FIGURE FROM MEMORY?
del fig #CLEAE FIGURE FROM MEMORY?
except (OSError,IndexError,AssertionError,TypeError,MemoryError):
print('ERROR ON FILE ' + each)
self.time['text'] = fn + ".png Converted"
continue
from metpy.
The level 2 code should be fault tolerant. Go ahead and open a new issue for that problem and post a link to the problematic file, if you can.
Ryan
On Jun 13, 2015, at 11:22, rankinstudio [email protected] wrote:
Much easier. Thanks!
I did notice something else. On the level II example I think the functions of MetPy are assuming that the level II scans will always have all of the data it requests. I have noticed a few of the files I download throw errors. I think it may be because they are missing data on some of the radial scans. I have had to catch the following errors on occasion:
try: name = each fn = each.split('\\')[-1] f = Level2File(name) #f.sweeps[0][0] # Pull data out of the file sweep = 0 # First item in ray is header, which has azimuth angle az = np.array([ray[0].az_angle for ray in f.sweeps[sweep]]) # 5th item is a dict mapping a var name (byte string) to a tuple of (header, data array) ref_hdr = f.sweeps[sweep][0][4][b'REF'][0] ref_range = np.arange(ref_hdr.num_gates) * ref_hdr.gate_width + ref_hdr.first_gate ref = np.array([ray[4][b'REF'][1] for ray in f.sweeps[sweep]]) var_data = ref var_range = ref_range # Turn into an array, then mask data = ma.array(var_data) data[np.isnan(data)] = ma.masked # Convert az,range to x,y xlocs = var_range * np.sin(np.deg2rad(az[:, np.newaxis])) ylocs = var_range * np.cos(np.deg2rad(az[:, np.newaxis])) #******************* SETUP AND SAVE FIGURE ******************** fig = plt.figure(frameon=False) #norm, cmap = ctables.registry.get_with_steps('NWSReflectivity', 16, 16) cmap = ctables.registry.get_colortable('Carbone42') plt.pcolormesh(xlocs, ylocs, data, cmap=cmap) plt.gca().set_aspect('equal','datalim') #SET LIMITS IF WANTED plt.xlim(-160, 160) plt.ylim(-160, 160) # fig.tight_layout() a=fig.gca() a.set_frame_on(False) a.set_xticks([]); a.set_yticks([]) fig.patch.set_alpha(0.0) a.patch.set_alpha(0.0) plt.axis('off') plt.savefig(each + '.png', dpi=430, bbox_inches='tight', pad_inches = 0) self.time['text'] = fn + ".png Saved" plt.clf() #CLEAR FIGURE FROM MEMORY? del fig #CLEAE FIGURE FROM MEMORY? except (OSError,IndexError,AssertionError,TypeError,MemoryError): print('ERROR ON FILE ' + each) self.time['text'] = fn + ".png Converted" continue
—
Reply to this email directly or view it on GitHub.
from metpy.
Related Issues (20)
- UndefinedUnitError: 'dBZ' is not defined in the unit registry HOT 4
- PlotGeometry fails to plot multiple fill colors HOT 2
- Nightly build is failing
- Avoid setuptools_scm import at runtime for deployed package
- Nightly build is failing
- Calculate altimiter values from station pressure? HOT 2
- Interactive skewT plot HOT 3
- Examine wet bulb temperature implementation
- Major sidebars missing on all pages except API docs HOT 1
- Inconsistent parsing of longitudes across cpu architectures HOT 1
- Nightly build is failing
- Traceback error using `Level2File` opening a start L2 radar chunk file HOT 1
- mpcalc.isentropic_interpolation_as_dataset "vertical attribute is not available." HOT 8
- numpy.arctan2 returns an angle in radian HOT 1
- GEMPAK Comparison Guide gets cut off with wide browser HOT 2
- AttributeError: module 'numpy' has no attribute 'alen' HOT 6
- Integration with Python performance tools like JAX HOT 10
- Feature request: wind_direction_categorical HOT 2
- Create GHA for doctests HOT 3
- cast angle_to_direction to input array type HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from metpy.