Coder Social home page Coder Social logo

swantools's Introduction

swantools is deprecated.

Please to the oceanwaves package https://github.com/openearth/oceanwaves-python

This repository gathers some useful functions and tools to be used alongside SWAN wave model.

For downloading, installing and using SWAN, please see: http://swanmodel.sourceforge.net/

To install the module, fork or download the source code and run:

sudo setup.py install

There are several dependencies that have to be met in order to use all funcions. The major ones are

  • Numpy
  • Pandas
  • NetCDF4
  • Matplotlib
  • Scipy.io

Nowadays, there is a I/O class which can handle TABLE, SPECOUT and BLOCK outputs and write SPECOUT and TPAR files.

For example, to use the I/O structure for reading a TABLE made HEAD option do:

import swantools.io

R   = swantools.io.SwanIO()
df  = R.read_swantable('file.txt')

This will return a pandas DataFrame with the model data.

For quickly plotting the results, just do:

import swantools.plot
import seaborn as sns

P = swantools.plot.SwanPlot()

y = df["Hsig"]
x = df.index.values

P.timeseries(x,y,"Significant Wave Heights")

Reading spectral files (.spc) wrote with "SPECOUT SPEC2D" become very easy:

import swantools.io

R = swantools.io.SwanIO()

lon,lat,freqs,dirs,times,factors,spec = R.read_swanspc('file.spc')

Plotting this data is also easy:

import swantools.plot

P = swantools.plot.SwanPlot()

P.spcplot(freqs,dirs,spectra)

Block (.mat) files can be handled in both stationay and non-stationary versions. For extracting variables from this files, one can do:

import swantools.io

R = swantools.io.SwanIO()
lon,lat,times,hs = R.read_swanblock('block.mat','Hsig')

Plotting field data can be done whith swantools.plot or creating a netCDF file and using ncview:

import swantools.plot
P    = swantools.plot.SwanPlot()
P.blockplot(lon,lat,hs[0,:,:],"Non-stationary Results")

or,

W = swantools.io.Converters()
W.np2nc("Hsig.nc",lat,lon,times,hs,"Significant Wave Height")
subprocess.call(ncview Hsig.nc,shell=True)

Non-stationary two-dimensional spectral files (SPEC2D) can be saved as netCDF:

R = swantools.io.SwanIO()
W = swantools.io.Converters()
lon,lat,freqs,dirs,times,factors,spectrum = R.read_swanspc('spectrum.spc')
W.spc2nc("spectrum.nc",lat,lon,freqs,dirs,times,factors,spectrum)

Non-stationary two-dimensional spectral files (SPEC2D) can be written as well:

# Getting some data to play with
R = swantools.io.SwanIO()
lat,lon,freqs,dirs,times,factors,spectrum = R.read_swanspc('spectrum.spc')
# Re-writing the data
R.write_spectrum("spcout.spc",lat,lon,times,freqs,dirs,factors,spectrum)

Much more will be added in the future.

Enjoy !

swantools's People

Contributors

caiostringari avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

swantools's Issues

while running test.py

I am getting error while running test.py

the error is like that

P.spcplot(freqs,dirs,times[5],spectrum[5,:,:]*factors[5])
TypeError: string indices must be integers, not tuple

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.