In [1]:
import numpy as np
import mmap

Create a test dataset, and replicate it to simulate two variabiles in the same binary file, each of the same 3D grid size.


In [2]:
outmap = np.memmap('test-memmap.dat', dtype='uint8', mode ='w+', shape=(1000,500,200))
outmap[:] = np.arange(1000*500*200).reshape((1000,500,200))
del outmap

In [3]:
%%bash
cat test-memmap.dat test-memmap.dat > two-vars.dat
ls -l test-memmap.dat two-vars.dat


-rw-r--r--  1 ebruning  staff  100000000 Sep  2 19:23 test-memmap.dat
-rw-r--r--  1 ebruning  staff  200000000 Sep  2 19:23 two-vars.dat

Now read the data by creating a memmap object for each variable (e.g., temp, pressure)


In [4]:
T = np.memmap('two-vars.dat', dtype='uint8', mode ='r', shape=(1000,500,200), offset=0)
P = np.memmap('two-vars.dat', dtype='uint8', mode ='r', shape=(1000,500,200), offset=1000*500*200)

In [5]:
stride = 2
x_slice = slice(300,400, stride)
y_slice = slice(20,452, stride)
z_slice = 16
T_subset = T[x_slice, y_slice, z_slice]
P_subset = P[x_slice, y_slice, z_slice]

print type(T_subset), type(P_subset)
print T_subset.shape, P_subset.shape

print np.squeeze(T_subset).shape, np.squeeze(P_subset).shape


<class 'numpy.core.memmap.memmap'> <class 'numpy.core.memmap.memmap'>
(50, 216) (50, 216)
(50, 216) (50, 216)

In [6]:
%matplotlib inline
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,10))
ax_T = fig.add_subplot(121)
ax_P = fig.add_subplot(122)
T_art = ax_T.contourf(T_subset, 20, cmap='gray', vmin=0, vmax=400)
plt.colorbar(T_art, ax=ax_T)
P_art = ax_P.contourf(T_subset, 100, cmap='gray', vmin=100, vmax=200)
plt.colorbar(P_art, ax=ax_P)
ax_T.contourf?



In [ ]: