#!/usr/bin/env python # coding: utf-8 # This is a notebook to experiment with calling a python wrapper for the teos-10 matlab library. # # The python module is gsw_calls.py, currently stored in /data/nsoontie/MEOPAR/tools/I_ForcingFiles/OBC, along with the matlab wrappers for the gsw routines. # # The function call_generic_gsw() links the appropriate matlab scripts to the current directory, saves all the input files to individual text files, then calls the matlab wrapper script which read the input files and saves the ouptut to a text file. Python then reads the output file, rehsapes and returns as a numpy array. It also removes the links and deletes the temporary text files. # In[1]: import sys sys.path.append('/data/nsoontie/MEOPAR/tools/I_ForcingFiles/OBC/') import gsw_calls import netCDF4 as nc import numpy as np import matplotlib.pyplot as plt get_ipython().run_line_magic('matplotlib', 'inline') # In[2]: F = nc.Dataset('/data/nsoontie/MEOPAR/NEMO-forcing/open_boundaries/west/SalishSea2_Masson_corrected.nc', 'r') # In[3]: sal = F.variables['vosaline'] temp = F.variables['votemper'] dep = np.expand_dims(np.expand_dims(np.expand_dims(F.variables['deptht'][:],axis=0),axis=2),axis=3) \ + np.zeros(sal.shape) long = F.variables['nav_lon'][:] + np.zeros(sal[:].shape) lat = F.variables['nav_lat'][:] + np.zeros(sal[:].shape) # In[4]: p = gsw_calls.generic_gsw_caller('mw_gsw_p_from_z.m', [-dep, lat]) # In[5]: p.shape # In[6]: plt.pcolormesh(p[0,:,0,:]) plt.colorbar() # In[7]: sal_ref = gsw_calls.generic_gsw_caller('mw_gsw_SR_from_SP.m', [sal[:],]) # In[8]: plt.pcolormesh(sal_ref[0,:,0,:]) plt.colorbar() # In[9]: temp_cons = gsw_calls.generic_gsw_caller('mw_gsw_CT_from_pt.m', [sal_ref[:], temp[:],]) # In[10]: plt.pcolormesh(temp_cons[0,:,0,:]) plt.colorbar() # ## What wrappers exist? # In[11]: get_ipython().system('ls /data/nsoontie/MEOPAR/tools/I_ForcingFiles/OBC/*.m') # ## Checking on the inputs for a wrapper # In[12]: get_ipython().system('cat /data/nsoontie/MEOPAR/tools/I_ForcingFiles/OBC/mw_gsw_SA_from_SP.m') # In[13]: sal_abs = gsw_calls.generic_gsw_caller('mw_gsw_SA_from_SP.m', [sal[:], p[:], long[:], lat[:]]) # In[14]: plt.pcolormesh(sal_abs[0,:,0,:]) plt.colorbar() # In[15]: get_ipython().system('ls *.txt') # In[16]: get_ipython().system('ls *.m') # In[ ]: