I will show you how to read a binary dumped two-dimensional array of real numbers from Python. Specifically, the terrain data in here is read. This time, the target is the terrain data used for MSM. As far as the number of grids and latitude / longitude are seen, the data in this directory is the current status. It seems to be compatible with MSM.
According to README
4.file format
(1)data form
4-byte real number(IEEE754)It is a two-dimensional array of.
The sequence of bytes is big endian.
(2)Coordinate system
Equal latitude / longitude grid coordinate system.
(a)Meso Numerical Weather Prediction Model GPV
Number of grids: East-West 481 North-South 505
Lattice spacing: East-West direction 0.0625 degrees north-south direction 0.05 degrees
First grid point: 47th parallel north.6 degrees east longitude 120 degrees
(Omission)
(3)Data storage order
Stores grid points with the same latitude from the first grid point in the east direction in the longitude direction.
It is also stored repeatedly at the latitude just south of it.
... apparently ...
In the example below
Surface geopotential height data
(a) "TOPO.MSM_5K_20071121"Meso Numerical Weather Prediction Model for GPV
Let's take this data as an example. First, download the data.
$ wget http://database.rish.kyoto-u.ac.jp/arch/jmadata/data/gpv/original/etc/200709/TOPO.MSM_5K_20071121
The rest is working with python. It is assumed that numpy
is installed.
import numpy as np
f = open("TOPO.MSM_5K_20071121",mode='rb')
topo = np.fromfile(f, dtype='>f',sep='').reshape(505,481)
You can now load terrain altitude data in the same size as the 505x481 MSM.
I read the data as a bigendian 4-byte float with dtype ='> f'
in fromfile, save it in a one-dimensional array, and reshape
it.
By specifying dtype, fromfile can be obtained other than a one-dimensional array, but dt = np.dtype (('> f', (505,481)))
Even if you specify it like this, topo.shape = It will be a three-dimensional array like (1,505,481)
.
I also checked the dtype document, but it seems that it can not be made into a two-dimensional array in one shot with a good feeling.
Let's visualize it to see if it's loaded correctly. For details, please refer to this article.
%matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import pygrib
grbs = pygrib.open('/temp/Z__C_RJTD_20170102000000_MSM_GPV_Rjp_Lsurf_FH00-15_grib2.bin')
grb = grbs.select(forecastTime=0)[0]
lats, lons = grb.latlons()
flat_lats= np.ravel(lats)
flat_lons= np.ravel(lons)
m = Basemap(llcrnrlat=lats.min(),urcrnrlat=lats.max(), llcrnrlon=lons.min(),urcrnrlon=lons.max())
m.drawcoastlines()
m.contourf(flat_lons, flat_lats, b, latlon=True, tri=True)
plt.colorbar()
plt.show()
By the way, land and sea distribution data is as follows.
Recommended Posts