Coder Social home page Coder Social logo

hevgyrt / ocean_wave_tracing Goto Github PK

View Code? Open in Web Editor NEW
17.0 2.0 4.0 12.12 MB

A numerical solver of the ray equations for ocean waves

License: GNU General Public License v3.0

Python 1.87% Jupyter Notebook 98.13%
oceanography raytracing waves

ocean_wave_tracing's People

Contributors

gauteh avatar hevgyrt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ocean_wave_tracing's Issues

Get rid of the filterwarnings

In the ocean_wave_tracing.py, get rid of the crude `warnings.filterwarnings('ignore').

The reason for having it there is the nulldivision when computing n = 0.5 * (1 + (2*k*d)/np.sinh(2*k*d)) for deep water

`

Ambient conditions must follow standards

Make sure that ambient parameters when specified within the Wave_tracing object, i.e. bathymetry and currents, follow standard conventions like the standard name and direction from the climate and forecast (CF) convention

fix relative import error

Some import errors that must be fixed:

  • relative import of util_solver functions (with dot in front) works with pytest, but without works when running main method
  • ray_metadata.json file

Make simple POC example

Like:

import numpy as np
import maplotlib.pyplot as plt
from ocean_wave_tracing.ocean_wave_tracing import Wave_tracing
 
# Defining some properties of the medium
nx = 100; ny = 100 # number of grid points in x- and y-direction
x = np.linspace(0,2000,nx) # size x-domain [m]
y = np.linspace(0,3500,ny) # size y-domain [m]
T = 250 # simulation time [s]
U=np.zeros((nx,ny))
U[nx//2:,:]=1
 
# Define a wave tracing object
wt = Wave_tracing(U=U,V=np.zeros((ny,nx)),
                       nx=nx, ny=ny, nt=150,T=T,
                       dx=x[1]-x[0],dy=y[1]-y[0],
                       nb_wave_rays=20,
                       domain_X0=x[0], domain_XN=x[-1],
                       domain_Y0=y[0], domain_YN=y[-1],
                       )
 
# Set initial conditions
wt.set_initial_condition(wave_period=10,
                              theta0=np.pi/8)
# Solve
wt.solve()

# Plot
fig, ax = plt.subplots();
pc=ax.pcolormesh(wt.x,wt.y,wt.U.isel(time=0));
fig.colorbar(pc)

for ray_id in range(wt.nb_wave_rays):
    ax.plot(wt.ray_x[ray_id,:],wt.ray_y[ray_id,:],'-k')

plt.show()

modulus of nan values

Updating ray_theta values to be within [0,360), sometimes we have np.mod(np.nan,2pi). Look how to circumvent this error

implement method for returning a xarray dataset of wave rays once solved

Use the code developed in

https://github.com/gauteh/hada/blob/main/hada/sources.py
https://github.com/gauteh/hada/blob/main/hada/cli.py

for making 1) variables

        vo = np.full(shape, np.nan, dtype=block.dtype)
        vo[:, inbounds] = block.values[:, ty.ravel(), tx.ravel()]

        vo = xr.DataArray(vo,
                          [
                              ("time", var.time.data),
                              ("latitude", target.y),
                              ("longitude", target.x),
                          ],
                          attrs=var.attrs,
                          name=var.name)

        # Positions in source grid
        # vo.attrs['x'] = target_x
        # vo.attrs['y'] = target_y

        vo.latitude.attrs['units'] = 'degrees_north'
        vo.latitude.attrs['standard_name'] = 'latitude'
        vo.latitude.attrs['long_name'] = 'latitude'

        vo.longitude.attrs['units'] = 'degrees_east'
        vo.longitude.attrs['standard_name'] = 'longitude'
        vo.longitude.attrs['long_name'] = 'longitude'
        vo.attrs['grid_mapping'] = target.proj_name
        vo.attrs['source'] = self.url
        vo.attrs['source_name'] = self.name

and 2) making a dataset


    ds = xr.Dataset()

    for var in sources.scalar_variables:
        logger.info(f'Searching for variable {var}')
        (d, v) = sources.find_dataset_for_var(var)

        if v is not None:
            logger.info(f'Extracting {var} from {d}')

            # Acquire variables on target grid
            vo = d.regrid(v, target, t0, t1)
            ds[vo.name] = vo
        else:
            logger.error(f'No dataset found for variable {var}.')

    for vvar in sources.vector_variables:
        varx = vvar[0]
        vary = vvar[1]
        logger.info(f'Searching for variable {varx},{vary}')
        (d, vx, vy) = sources.find_dataset_for_var_pair(varx, vary)

        if vx is not None:
            logger.info(f'Extracting {varx} and {vary} from {d}')

            # Acquire variables on target grid
            vox = d.regrid(vx, target, t0, t1)
            voy = d.regrid(vy, target, t0, t1)

            vox, voy = d.rotate_vectors(vox, voy, target)

            ds[vox.name] = vox
            ds[voy.name] = voy
        else:
            logger.error(f'No dataset found for variable {varx},{vary}.')

Fix velocity checker

The velocity_checker (in ocean_wave_tracing/util_methods.py) fails if the intput velcoity field is a xarray object with wrong dimension names (i.e. X and Y instead of x and y)

Add verification NBs

Add the following notebooks for verification of the numerical solver

  • Snell's law
  • wave deflection
  • numerical convergence

And

  • remove the legacy notebooks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.