Editorial by Hafez Ahmad
  • Twitter
  • Facebook
  • linkedin
  • Instagram
  • Medium

Numerical Oceanography

Most Governing Equations & Numerical Modeling

Numerical ocean models have become increasingly valuable tools as we strive to understand the nature of the ocean’s dynamics. They have progressed from the necessarily crude and idealized tools of decades past to capture much of the complexity and beauty of the real ocean. Many oceanographic research projects utilize numerical models as a fully equal partner and complement to the long-established physical oceanographic approaches of seagoing observational inference, theory, and fluids lab experimentation.
Simulation models can calculate realistic oceanic circulation by resolving the primitive equations coupled with the international equation of the state of the sea, as well as the equations temperature and salt conservation (Maria, 2012). Furthermore, The importance of predicting the state of the ocean currents, tide, temperature, salinity, and sea level in real time have been recognized years ago in many modern developed countries for their different regional and global purposes. Different ocean models can be loosely characterized by their approaches to spatial discretization and vertical coordinate treatment
Most important equations in Ocean Modeling

  1. hydrostatic equation
  2. continuity equation
  3. state equation
  4. conservation of temperature and salt
  5. Navier-Stokes equations
  6. Momentum equations
  7. Advection-diffusion equation

  8. sources 1. https://stephengriffies.github.io/assets/pdfs/CH18_griffies_adcroft.pdf 2. https://www.myroms.org/wiki/Documentation_Portal

  • Learn More

Oceanography with Programming

Computational Oceanography


let's solve and visualize Laplace Equations with python programming ,Laplace equation in 2-D cartesian coordinates (for heat equation)



$$ {\nabla ^2}T = \frac{{{\partial ^2}T}}{{\partial {x^2}}} + \frac{{{\partial ^2}T}}{{\partial {y^2}}} = 0$$


Where T is temperature, x is x-dimension, and y is y-dimension. x and y are functions of position in Cartesian coordinates

In [ ]:
import numpy as np
import matplotlib.pyplot as plt
# Set maximum iteration
maxIter = 500

import numpy as np
import matplotlib.pyplot as plt
# Set maximum iteration
maxIter = 500

# Set Dimension and delta
lenX = lenY = 20 #we set it rectangular
delta = 1

# Boundary condition
Ttop = 0 #100,0
Tbottom = 100
Tleft = 30
Tright = 30 #0,30

# Initial guess of interior grid
Tguess = 30
# Set colour interpolation and colour map.
# You can try set it to 10, or 100 to see the difference
# You can also try: colourMap = plt.cm.coolwarm
colorinterpolation = 50
colourMap = plt.cm.jet

#set mesh

X,Y=np.meshgrid(np.arange(0,lenX),np.arange(0,lenY))

# Set array size and set the interior value with Tguess
T = np.empty((lenX, lenY))
T.fill(Tguess)

# Set Boundary condition
T[(lenY-1):, :] = Ttop # bottom row 100
T[:1, :] = Tbottom  #top row 0
T[:, (lenX-1):] = Tright
T[:, :1] = Tleft

# Iteration (We assume that the iteration is convergence in maxIter = 500)
print("Please wait for a moment")
for k in range(0,maxIter):
    for i in range(1,lenX-1,delta):
        for j in range(1,lenY-1,delta):
            T[i,j]=0.25*(T[i+1][j]+T[i-1][j]+T[i][j+1]+T[i][j-1])
        
print('finisted')
#Configure the contour
plt.title("Contour of Temperature")
plt.contourf(X,Y,T, colorinterpolation, cmap=colourMap)

# Set Colorbar
plt.colorbar()

# Show the result in the plot window
plt.show()



import numpy as np
from scipy.integrate import odeint

Ca0 = 2     # Entering concentration
vo = 2      # volumetric flow rate
volume = 20 # total volume of reactor, spacetime = 10
k = 1       # reaction rate constant

N = 100     # number of points to discretize the reactor volume on

init = np.zeros(N)    # Concentration in reactor at t = 0
init[0] = Ca0         # concentration at entrance

V = np.linspace(0, volume, N) # discretized volume elements
tspan = np.linspace(0, 25)    # time span to integrate over

def method_of_lines(C, t):
    'coupled ODES at each node point'
    D = -vo * np.diff(C) / np.diff(V) - k * C[1:]**2
    return np.concatenate([[0],D])

sol = odeint(method_of_lines, init, tspan)

    
# steady state solution
def pfr(C, V):
    return 1.0 / vo * (-k * C**2)

ssol = odeint(pfr, Ca0, V)

plt.plot(tspan,sol[:,1])
plt.show()
plt.plot(V, ssol, label='Steady state')
plt.plot(V, sol[-1], label='t = {}'.format(tspan[-1]))
plt.xlabel('Volume')
plt.ylabel('$C_A$')
plt.legend(loc='best')


from matplotlib import animation 

fig=plt.figure()
ax=plt.axes()
line,=ax.plot(V,init,lw=2)
plt.show()

def anim(i):
    line.set_xdata(V)
    line.set_ydata(sol[i])
    ax.set_title('t = {0}'.format(tspan[i]))
    ax.figure.canvas.draw()
    return line,

anim=animation.FuncAnimation(fig,anim,frames=50,blit=True)
anim
plt.show()
# save it as mp4 file 
anim.save('transient_pfr.mp4', fps=10)


How to make a [animated barplot] race_barplot with python?


code here ,note : [you have to configure your system with ffmpeg]

In [ ]:
# load library
import bar_chart_race as bcr
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("datasets_826161_1412128_Countries Population from 1995 to 2020.csv")

# bcr_html = bcr.bar_chart_race(df=df, filename=None)

pop = df.drop(['Yearly % Change', 'Yearly Change',
               'Migrants (net)', 'Median Age', 'Fertility Rate', 'Density (P/Km²)',
               'Urban Pop %', 'Urban Population', "Country's Share of World Pop %",
               'World Population', 'Country Global Rank'], axis=1)

# year=colum first ,column, country =first row
# making pivot table 
df = pop.pivot_table("Population", ['Year'], "Country")
df.sort_values(list(df.columns), inplace=True)
df = df.sort_index()

# make animated barplot as pop2020_horiz.mp4

bcr.bar_chart_race(
    df=df,
    filename='pop2020_horiz.mp4',
    orientation='h',
    sort='desc',
    n_bars=10,
    fixed_order=False,
    fixed_max=True,
    steps_per_period=10,
    interpolate_period=False,
    label_bars=True,
    bar_size=.90,
    period_label={'x': .99, 'y': .25, 'ha': 'right', 'va': 'center'},
    period_summary_func=lambda v, r: {'x': .99, 'y': .18,
                                      's': f'Population{v.nlargest(39).sum():,.0f}',
                                      'ha': 'right', 'size': 8, 'family': 'Courier New'},
    period_length=600,
    figsize=(6.5, 5),
    dpi=300,
    cmap='dark12',
    title='Population by Country from 1955 to 2020',
    title_size='',
    bar_label_size=7,
    tick_label_size=5,
    shared_fontdict={'family': 'Helvetica', 'color': '.1'},
    scale='linear',
    writer=None,
    fig=None,
    bar_kwargs={'alpha': .7},
    filter_column_colors=True)

  • under development

Get in touch

I love to work in the field of Oceanography and Data analysis.If you think, you can contact with me at any moment.

  • hafezahmad100@gmail.com
  • (+880)1785601208
  • Bangladesh
    Chittagong,Kotowali

© hafez. All rights reserved. : hafez. Design: hafez ahmad.