ajdawson / eofs

EOF analysis in Python
http://ajdawson.github.io/eofs/
GNU General Public License v3.0
201 stars 60 forks source link

How To Plot Contours from a 2D Matrix #77

Closed ankurmahesh closed 7 years ago

ankurmahesh commented 8 years ago

I obtained temperature data from 90 weather stations. Each station has data for 3,481 times. I currently have a two-dimensional (space and time) matrix of temperature data (3481 x 90). When I run the module, the solver returns a 1 x 90 EOF. How can I plot this EOF using contourf?

Should I create an empty 90 x 90 matrix and fill in the diagonal the values of the EOF? And the values of lot and lan should also be 90 x 90 matrices?

fill = ax.contourf(lons, lats, np.fill_diagonal(np.zeros((90,90)), eof1.squeeze()), clevs, cmap=plt.cm.RdBu_r, latlon=True)

ajdawson commented 8 years ago

If you have station data you will always need to interpolate or use a plotting method that can accept irregular points, you cannot use contourf. The 1 x 90 EOF is just one temperature value for each station, so to visualise it you need some way to plot values for stations. If you want a contour map then you could use tricontour (or tricontourf to triangulate and plot contours, or you could use some other interpolation method to generate new data on a regular grid. I expect SciPy has some reasonable choices for interpolation. Good luck.

lovechang1986 commented 7 years ago

Hi, What is the difference between the next two steps? 1: First interpolate station data to regular grid data and then use EOF decomposition, 2: First use EOF decomposition on station data and then interpolate to regular grid.

In general or your personal opinion, which steps should I choose for EOF on station data?