mitgcm
Analysis of MITgcm output using python
Functions
mitgcm.functions Namespace Reference

Useful functions that don't belong elsewhere. More...

Functions

def calc_surface
 Calculate an isosurface of input_array. More...
 
def extract_on_surface (input_array, surface_locations, axis_values)
 Extract the value of a 3D field on a 2D surface. More...
 
def layer_integrate
 Integrate between two non-trivial surfaces, 'upper_contour' and 'lower_contour'. More...
 
def test_layer_integrate ()
 
def interp_field
 Interpolate a given field onto a different grid. More...
 
def export_binary
 Export binary files that can be imported into the MITgcm. More...
 
def show_variables (netcdf_filename)
 A shortcut function to display all of the variables contained within a netcdf file. More...
 
def plt_mon_stats
 Plot some monitor file variables. More...
 
def replace_nans
 Replace NaN elements in an array using an iterative image inpainting algorithm. More...
 
def numerics_replace_nans (max_iter, n_nans, inans, jnans, filled, kernel, kernel_size, tol, replaced_new, replaced_old)
 
def shift_vort_to_T (array)
 Shift the array from vorticity points to the corresponding tracer point. More...
 
def shift_U_to_T (array)
 Shift the array from UVEL points to the corresponding tracer point. More...
 
def shift_V_to_T (array)
 Shift the array from VVEL points to the corresponding tracer point. More...
 
def shift_W_to_T (array)
 Shift the array from WVEL points to the corresponding tracer point. More...
 

Detailed Description

Useful functions that don't belong elsewhere.

A collection of functions for analysing model output. These include functions to extract surfaces at a constant value of some variable and extract a variable on a surface.

Each function has a detailed docstring.

Function Documentation

def mitgcm.functions.calc_surface (   input_array,
  surface_value,
  axis_values,
  method = 'linear' 
)

Calculate an isosurface of input_array.

This function is fast, but it is not designed to deal well with non-monotonicity in the search direction.

There are two search options:

  • 'nearest' finds the index just before the search value
  • 'linear' uses linear interpolation to find the location between grid points.

May give silly answers if input_array is not monotonic in the search direction.

Definition at line 21 of file functions.py.

def mitgcm.functions.export_binary (   filename,
  field,
  dtype = 'float64' 
)

Export binary files that can be imported into the MITgcm.

The files are big endian, and the datatype can either be 'float64' (= double precision), or 'float32' (=single precision).

Might not work for very large datasets.

Definition at line 349 of file functions.py.

def mitgcm.functions.extract_on_surface (   input_array,
  surface_locations,
  axis_values 
)

Extract the value of a 3D field on a 2D surface.

This function takes an 3 dimensional matrix 'input_array' and an 2 dimensional matrix 'surface_locations' and returns a 2 dimensional matrix that contains the values of input_array at the location specified by surface_locations along the third dimension using the values for that axis contained in 'axis_values'. Linear interpolation is used to find the values.

Definition at line 107 of file functions.py.

def mitgcm.functions.interp_field (   field,
  old_x,
  old_y,
  new_x,
  new_y,
  interp_order,
  fill_nans = 'no',
  max_its = 5 
)

Interpolate a given field onto a different grid.

Only performs interpolation in the horizontal directions.


Parameters

  • field - the variable to be interpolated
  • old_x, old_y - the axis on which the original field is defined.
  • new_x, new_y - the axis onto which the field will be interpolated.
  • interp_order - the order of the interpolation function, integer between 1 and 5 inclusive. 1 -> linear, 3 -> cubic, &c..
  • fill_nans - if 'no' values in field are not altered. If 'yes', then NaNs in 'field' are replace with the mean of surrounding non-NaNs.
  • max_its - maximum number of iterations to perform when healing NaNs in field.

Definition at line 295 of file functions.py.

def mitgcm.functions.layer_integrate (   upper_contour,
  lower_contour,
  grid_obect,
  integrand = 'none',
  interp_method = 'none' 
)

Integrate between two non-trivial surfaces, 'upper_contour' and 'lower_contour'.

At the moment this only works if all the inputs are defined at the same grid location.

The input array 'integrand' is optional. If it is not included then the output is the volume per unit area (difference in depth) between the two surfaces at each grid point,


Parameters

  • upper_contour - the higher surface
  • lower_contour - the lower surface
  • axis_values - the vertical axis. ** defined at the cell centres if using interp_method = 'linear' ** defined at the cell faces if using interp_method = 'none'
  • interp_method - defines whether the function interpolates values of the integrand. Possible options are 'none' or 'linear'.
  • integrand - the field to be integrated between the contours

Definition at line 148 of file functions.py.

def mitgcm.functions.numerics_replace_nans (   max_iter,
  n_nans,
  inans,
  jnans,
  filled,
  kernel,
  kernel_size,
  tol,
  replaced_new,
  replaced_old 
)

Definition at line 610 of file functions.py.

def mitgcm.functions.plt_mon_stats (   netcdf_filename,
  variables = ['advcfl_uvel_max',
  advcfl_vvel_max,
  advcfl_wvel_max,
  time_units = 'days',
  output_filename = None 
)

Plot some monitor file variables.

'netcdf_filename' can contain shell wild cards, but only the first matching file will be used.

Options include:

  • advcfl_uvel_max
  • advcfl_vvel_max
  • advcfl_wvel_max
  • ke_mean
  • dynstat_theta_mean
  • dynstat_sst_mean
  • dynstat_sst_sd
  • dynstat_salt_max
  • dynstat_salt_min
  • dynstat_uvel_mean
  • dynstat_vvel_mean
  • dynstat_wvel_mean
  • ...
  • and many others.

Definition at line 378 of file functions.py.

def mitgcm.functions.replace_nans (   array,
  max_iter,
  tol,
  kernel_size,
  method = 'localmean' 
)

Replace NaN elements in an array using an iterative image inpainting algorithm.

The algorithm is the following:

1) For each element in the input array, replace it by a weighted average of the neighbouring elements which are not NaN themselves. The weights depends of the method type. If method=localmean weight are equal to 1/( (2*kernel_size+1)**2 -1 )

2) Several iterations are needed if there are adjacent NaN elements. If this is the case, information is "spread" from the edges of the missing regions iteratively, until the variation is below a certain threshold.

Parameters

array : 2d np.ndarray an array containing NaN elements that have to be replaced

max_iter : int the number of iterations

tol: float the difference between subsequent iterations for stopping the algorithm

kernel_size : int the size of the kernel, default is 1

method : str the method used to replace invalid values. Valid options are localmean.

Returns

filled : 2d np.ndarray a copy of the input array, where NaN elements have been replaced.


Acknowledgements

Code for this function is (very slightly modified) from https://github.com/gasagna/openpiv-python/commit/81038df6d218b893b044193a739026630238fb22#diff-9b2f4f9bb8180e4451e8f85164df7217 which is part of the OpenPIV project.

Definition at line 422 of file functions.py.

def mitgcm.functions.shift_U_to_T (   array)

Shift the array from UVEL points to the corresponding tracer point.

Definition at line 668 of file functions.py.

def mitgcm.functions.shift_V_to_T (   array)

Shift the array from VVEL points to the corresponding tracer point.

Definition at line 674 of file functions.py.

def mitgcm.functions.shift_vort_to_T (   array)

Shift the array from vorticity points to the corresponding tracer point.

Definition at line 662 of file functions.py.

def mitgcm.functions.shift_W_to_T (   array)

Shift the array from WVEL points to the corresponding tracer point.

Definition at line 680 of file functions.py.

def mitgcm.functions.show_variables (   netcdf_filename)

A shortcut function to display all of the variables contained within a netcdf file.

If the filename contains wildcards, they'll be expanded and only the first file used.

Definition at line 363 of file functions.py.

def mitgcm.functions.test_layer_integrate ( )
Test function to check that the layer integrate function is working correctly.

Definition at line 281 of file functions.py.