SPINS MATLAB tools: Difference between revisions
No edit summary |
(Added descriptions for some key MATLAB scripts) |
||
Line 14: | Line 14: | ||
SPINSmatlab has a host of useful functions. Some are very general, while some are specialized. Below is a list of every function included in SPINSmatlab (as of October 2021), as well as a short description of what the function does. In parentheses is the directory in which the described script is located. | SPINSmatlab has a host of useful functions. Some are very general, while some are specialized. Below is a list of every function included in SPINSmatlab (as of October 2021), as well as a short description of what the function does. In parentheses is the directory in which the described script is located. | ||
Following the description of the scripts, a list of "MUST KNOW" scripts is included. These scripts are the most widely used on the day-to-day and fluency in them is imperative to a smooth workflow. | Following the description of the scripts, a list of "MUST KNOW" scripts is included. These scripts are the most widely used on the day-to-day and fluency in them is imperative to a smooth workflow. Many of these codes rely on the <code>spins.conf</code>, so ensure that the working directory contains it. | ||
'''Reading in parameters from the <code>spins.conf</code>''' | |||
Reading in parameters from the <code>spins.conf</code> takes place in two steps. The first is to generate a MATLAB structure containing all the parameters from the <code>spins.conf</code>. This is done by writing <code>params = spins_gridparams()</code>. The output <code>params</code> is a structure containing all of the parameters from the <code>spins.conf</code>. | |||
The second step is to access the variables within the structure <code>params</code> and recast then as workspace variables. This is done by writing <code>par2var(params)</code>. Now, all parameters from the <code>spins.conf</code> can be accessed as MATLAB variables. To learn more about the size and datatype of each parameter, type <code>whos</code> in the MATLAB command window. | |||
'''<code>spins_reader()</code>''' | '''<code>spins_reader()</code>''' | ||
Line 27: | Line 30: | ||
If data is two-dimensional, accessing custom subsets of the data is done by ignoring the fifth argument. When only four arguments are supplied, <code>spins_reader()</code> assumes that the data only has an <math>x</math> and <math>z</math> dimension and no <math>y</math> dimension. | If data is two-dimensional, accessing custom subsets of the data is done by ignoring the fifth argument. When only four arguments are supplied, <code>spins_reader()</code> assumes that the data only has an <math>x</math> and <math>z</math> dimension and no <math>y</math> dimension. | ||
'''<code>plot_diagnos()</code>''' | |||
<code>plot_diagnos()</code> | |||
'''<code>cmocean()</code>''' | '''<code>cmocean()</code>''' | ||
Line 39: | Line 41: | ||
'''<code>print_figure()</code>''' | '''<code>print_figure()</code>''' | ||
<code>print_figure()</code> is used to print the contents of a figure to a file whose filetype is specified by the user. To use the basic functionality, write <code>print_figure(filename,'opt1',val1,'opt2',val2,...)</code>. The filename is a character vector. The different options, <code>opt1, opt2, ...</code> and values <code>val1, val2, ...</code> are given in the following table. | |||
{| class="wikitable" | |||
!colspan="3"|<code>print_figure()</code> options | |||
|- | |||
!|Option | |||
!|Value | |||
!|Description | |||
|- | |||
|<code>fig_hand</code> | |||
|integer/figure handle | |||
|Figure window | |||
|- | |||
|<code>format</code> | |||
|<code>'pdf'</code>, <code>'pdf'</code>, <code>'eps'</code> (not recommended) ... | |||
|File format to save figure | |||
|- | |||
|<code>units</code> | |||
|<code>'inches'</code>, <code>'cm'</code> | |||
|Units of figure size | |||
|- | |||
|<code>size</code> | |||
|<code>[width height]</code> | |||
|Vector of dimensions (in units specified by <code>units</code>) | |||
|- | |||
|<code>res</code> | |||
|integer | |||
|Resolution in dpi | |||
|- | |||
|<code>renderer</code> | |||
|<code>'painters'</code>, <code>'opengl'</code> | |||
|This option can often be ignored | |||
|} | |||
'''<code>resize_all()</code>''' | '''<code>resize_all()</code>''' |
Revision as of 15:00, 13 October 2021
Many versatile MATLAB functions have been written to easily read and analyze SPINS outputs. They are accessible for use on Belize and Boogaloo, and can also be pulled from github at https://github.com/ddeepwel/SPINSmatlab.git.
The main functionality are:
- parse spins.conf file into a matlab structure
- automatic calculation of secondary grid parameters (spacing, expansion type, ...)
- easy reading of grid
- easy cross-sectional plotting
- plotting of spins diagnostics
- functions for calculating characteristics (amplitude, wavelength) of waves
- SPINS resize
The first three are organized into the spins_gridparams function. The plotting is accomplished by spins_plot2d which has many optional arguments for making plots with very little work. See David Deepwell (ddeepwel@uwaterloo.ca) or the github page for more information on usage, making bug reports, or suggesting other options or functions to add.
SPINSmatlab has a host of useful functions. Some are very general, while some are specialized. Below is a list of every function included in SPINSmatlab (as of October 2021), as well as a short description of what the function does. In parentheses is the directory in which the described script is located.
Following the description of the scripts, a list of "MUST KNOW" scripts is included. These scripts are the most widely used on the day-to-day and fluency in them is imperative to a smooth workflow. Many of these codes rely on the spins.conf
, so ensure that the working directory contains it.
Reading in parameters from the spins.conf
Reading in parameters from the spins.conf
takes place in two steps. The first is to generate a MATLAB structure containing all the parameters from the spins.conf
. This is done by writing params = spins_gridparams()
. The output params
is a structure containing all of the parameters from the spins.conf
.
The second step is to access the variables within the structure params
and recast then as workspace variables. This is done by writing par2var(params)
. Now, all parameters from the spins.conf
can be accessed as MATLAB variables. To learn more about the size and datatype of each parameter, type whos
in the MATLAB command window.
spins_reader()
spins_reader()
is the function one uses to read in SPINS output into a MATLAB array. The basic functionality comes rom specifying the field name as a character vector, as well as the output index. As an example, if one would like to import the file rho.14
(i.e. the density field at the 14th output), they could write my_rho = spins_reader('rho',14)
.
For larger datasets, it is often impractical to load the entire dataset into MATLAB. To this end, the user can specify certain subsets of the data they wish to import. This is done by specifying index ranges in the dimension (xrange
), dimension (yrange
), and/or dimension (zrange
). Each of the range arguments take an index or set of indices and return the field values at those indices. To access this functionality, one could write my_rho = spins_reader('rho',14,xstart:xend,y_slice_ind,[])
. For the dimension, a custom range of indices beginning at xstart
and ending at xend
was used. For the dimension, the field was sliced at a single location indicated by y_slice_ind
. Finally, the entire dimension was imported by using []
.
If data is two-dimensional, accessing custom subsets of the data is done by ignoring the fifth argument. When only four arguments are supplied, spins_reader()
assumes that the data only has an and dimension and no dimension.
plot_diagnos()
plot_diagnos()
cmocean()
cmocean()
is a package of perceptually uniform colourmaps(Add Thyng reference). These colourmaps should be used whenever possible, as they avoid artificial gradients created by using some other colourmaps.
To access the colourmaps within the package, when writing the colormap
command, write colormap(cmocean(my_colourmap))
where my_colourmap
(character vector) is any of the available colourmaps found by typing help cmocean
.
print_figure()
print_figure()
is used to print the contents of a figure to a file whose filetype is specified by the user. To use the basic functionality, write print_figure(filename,'opt1',val1,'opt2',val2,...)
. The filename is a character vector. The different options, opt1, opt2, ...
and values val1, val2, ...
are given in the following table.
print_figure() options
| ||
---|---|---|
Option | Value | Description |
fig_hand
|
integer/figure handle | Figure window |
format
|
'pdf' , 'pdf' , 'eps' (not recommended) ...
|
File format to save figure |
units
|
'inches' , 'cm'
|
Units of figure size |
size
|
[width height]
|
Vector of dimensions (in units specified by units )
|
res
|
integer | Resolution in dpi |
renderer
|
'painters' , 'opengl'
|
This option can often be ignored |
resize_all()
extend_all()
ind = nearest_index(x1d,xi)
diagnos = plot_diagnos(make_plots,do_filter)
clean_diagnostics
print_figure(filename, 'opt1', val1, 'opt2', val2, ...)
cmocean
resize_all(out,[Nx_new, Ny_new, Nz_new])
extend_all(out,Ly,Ny)