Updated: 2018/12/10
In [1]:
%load_ext ferretmagic
In [2]:
import numpy as np
b = {}
b['name']='myvar1'
x=np.linspace(-np.pi*4, np.pi*4, 500)
b['data']=np.sin(x)/x
b.keys()
Out[2]:
A dataset must have been opened before putting data to ferret to get list of variables latter.
In [6]:
%%ferret
use levitus_climatology
In [7]:
%ferret_putdata --axis_pos (0,1,2,3,4,5) b
In [8]:
%%ferret
set text/font=arial
show data
ppl color 2, 0, 50, 100, 75
ppl color 3, 100, 50, 0, 75
plot/thick=3/color myvar1, myvar1[x=@shf:50]
Create a dummy 3D array (XY and a Z axis)
In [9]:
nlons, nlats, dim3 = (145, 73, 10)
lats = np.linspace(-np.pi / 2, np.pi / 2, nlats)
lons = np.linspace(0, 2 * np.pi, nlons)
lons, lats = np.meshgrid(lons, lats, indexing='ij')
wave = 0.75 * (np.sin(2 * lats) ** 8) * np.cos(4 * lons)
mean = 0.5 * np.cos(2 * lats) * ((np.sin(2 * lats)) ** 2 + 2)
lats = np.rad2deg(lats)
lons = np.rad2deg(lons)
data2D = wave + mean
myaxis = np.linspace(1, 1000, dim3)
dataXYZ = np.repeat(np.expand_dims(data2D,axis=-1), dim3, axis=2)
print dataXYZ.shape
In [10]:
import pyferret
data2ferret = {}
data2ferret['name']='myvar2'
data2ferret['axis_names']=('lons', 'lats', 'depth')
data2ferret['axis_units']=('degrees_east', 'degrees_north', 'meters')
data2ferret['axis_types']=(
pyferret.AXISTYPE_LONGITUDE,
pyferret.AXISTYPE_LATITUDE,
pyferret.AXISTYPE_LEVEL
)
data2ferret['axis_coords']=(lons[:,0], lats[0,:], myaxis[:])
data2ferret['data']=dataXYZ
data2ferret.keys()
Out[10]:
In [11]:
%ferret_putdata data2ferret
In [12]:
%%ferret
show data
shade myvar2[k=1]
Create a dummy 3D array (XY and a T axis)
In [13]:
dataXYT = np.reshape(dataXYZ, (nlons, nlats, 1, dim3))
print dataXYT.shape
In [14]:
import pyferret
data2ferret = {}
data2ferret['name']='myvar3'
data2ferret['axis_names']=('lons', 'lats', '', 'time')
data2ferret['axis_units']=('degrees_east', 'degrees_north', '', '')
data2ferret['axis_types']=(
pyferret.AXISTYPE_LONGITUDE,
pyferret.AXISTYPE_LATITUDE,
pyferret.AXISTYPE_NORMAL,
pyferret.AXISTYPE_ABSTRACT
)
data2ferret['axis_coords']=(lons[:,0], lats[0,:], None, None)
data2ferret['data']=dataXYT
data2ferret.keys()
Out[14]:
In [15]:
%ferret_putdata data2ferret
In [16]:
%%ferret
show data
shade myvar3[l=1]
In [ ]:
In [ ]: