1

I'm attempting to overlay my animation over a projected basemap in Matplotlib. Right now I have a animation that is displaying an array in a time series over an X and Y axis in Matplotlib. What I want to do is:

  1. Bring in a basemap, correctly projected in a specific coordinate system.
  2. Set an extent to a specific area (say the general proximity of a section of a city).
  3. Show my array animation over this extent using something from the following toolkit:

from mpl_toolkits.basemap import Basemap

  1. Export my animation to mp4 (as I'm already doing).

Here is my code currently:

import h5py
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
from matplotlib.colors import ListedColormap
import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

dat = h5py.File('NC_File.nc','r')
conc = np.float32(dat['Conc'])

# Creating basemap
my_map = Basemap(projection='lcc',
                llcrnrlon = -77.052143,
                llcrnrlat =  38.882504,
                urcrnrlon = -77.017149,
                urcrnrlat =  38.904427,)

sf = np.max(conc)

fig = plt.figure()
plt.ylim((250,400))
plt.xlim((100,400))

a = conc[290,:,:]/sf

colormap = ListedColormap(["white","green","yellow","orange","red"])

im = plt.imshow(a, interpolation='bilinear', aspect='auto', cmap=colormap, vmin=0, vmax=0.1)
cbar = plt.colorbar(spacing ='uniform')
cbar.set_label('Concentration')
plt.ylabel("Y-Axis")
plt.xlabel("X-Axis")

def animate_func(i):
    plt.title('Time: '+str(i)+' sec')
    a=conc[i,:,:]/sf
    im.set_array(a)
    return [im]

anim = animation.FuncAnimation(fig, animate_func, frames = 900, interval = 1, blit=False, repeat=False)
#plt.show()

# Exporting to mp4 video file
FFwriter = animation.FFMpegWriter(fps=30)
anim.save('NC_Conc_animation.mp4', writer = FFwriter)

As of right now, all I have going is the creation of the basemap, but even that is not being launched when I initialize my_map. That error reads: ValueError: must specify lat_1 or lat_0 and lon_0 for Lambert Conformal basemap (lat_2 is optional) Most of the information and documentation I'm seeing is of coordinates being projected or animated. What I want is this arbitrary set of x,y coordinates to be overtop of somewhere on the earth, anywhere. My array's x,y data is each 1x1 meter from one another (1,1), (2,2) etc. I don't necessarily need to assign the array to a coordinate system or to create a shapefile. I have a background in GIS but am avoiding bringing my data into a GIS format, I just want to visually display my animated array in Matplotlib if anybody has any suggestions how to properly get this going.

Is there a way I can specify the origin or point on the earth in a projection and then center my data around that origin?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.