ncvue.ncvmethods

Common methods for panels of ncvue.

Methods normally belong to a class and be called like self.method(args). We have several panels in ncvue that would have the same methods such as getting slices from arrays. These are hence gathered here, all start with the first argument self, which is the class instance, and are called like method(self, args).

The methods could also be put onto a common class (based on ttk.Frame) on which ncvContour, etc. would then be based.

This module was written by Matthias Cuntz while at Institut National de Recherche pour l’Agriculture, l’Alimentation et l’Environnement (INRAE), Nancy, France.

Copyright (c) 2020-2021 Matthias Cuntz - mc (at) macu (dot) de

Released under the MIT License; see LICENSE file for details.

History:

  • Written Nov-Dec 2020 by Matthias Cuntz (mc (at) macu (dot) de)

  • Slice arrays with slice function rather than numpy.take, Dec 2020, Matthias Cuntz

  • Moved individual get_slice_? methods for x, y, y2, z as general get_slice function to ncvutils, Dec 2020, Matthias Cuntz

  • Added convenience method get_slice_miss, Dec 2020, Matthias Cuntz

  • set_dim_lon, set_dim_lat, set_dim_var for Map panel, Jan 2021, Matthias Cuntz

  • set latdim, londim to all on map var, determined in ncvMain, Jan 2021, Matthias Cuntz

  • catch non numpy.dtype in set_miss, Jan 2021, Matthias Cuntz

  • catch variables that have only one string or similar, Jan 2021, Matthias Cuntz

  • added tooltip to dimensions, Jan 2021, Matthias Cuntz

  • added analyse_netcdf from ncvmain, Jan 2021, Matthias Cuntz

  • use dlblval instead of dlbl to set dimension labels, Jan 2021, Matthias Cuntz

The following methods are provided:

analyse_netcdf(self)

Analyse a netcdf file for the unlimited dimension, calculating datetime, variables, latitudes/longitudes variables and dimensions.

get_miss(self, x)

Get list of missing values, i.e. self.miss, x._FillValue, x.missing_value, and from netcdf4.default_fillvals.

get_slice_miss(self, dimspins, x)

Convenience method to get list of missing values (get_miss), choose slice of array (get_slice), and set missing values to NaN in slice (set_miss).

set_dim_lat(self)

Set spinboxes of latitude-dimensions.

set_dim_lon(self)

Set spinboxes of longitude-dimensions.

set_dim_var(self)

Set spinboxes of varable-dimensions in Map panel.

set_dim_x(self)

Set spinboxes of x-dimensions.

set_dim_y(self)

Set spinboxes of y-dimensions of the left-hand-side (lhs).

set_dim_y2(self)

Set spinboxes of y2-dimensions of the right-hand-side (rhs).

set_dim_z(self)

Set spinboxes of z-dimensions.

analyse_netcdf(self)[source]

Analyse a netcdf file for the unlimited dimension, calculating datetime, variables, latitudes/longitudes variables and dimensions.

Parameters
selfclass

ncvue class

Returns
Set variables:

self.dunlim, self.time, self.tname, self.tvar, self.dtime, self.cols, self.latvar, self.lonvar, self.latdim, self.londim

Examples

>>> analyse_netcdf(self)
get_miss(self, x)[source]

Get list of missing values, i.e. self.miss, x._FillValue, x.missing_value, and from netcdf4.default_fillvals.

Parameters
selfclass

ncvue class

xnetCDF4._netCDF4.Variable

netcdf variable

Returns
list

List with missing values self.miss, x._FillValue, x.missing_value if present, and from netcdf4.default_fillvals

Examples

>>> x = fi.variables['time']
>>> miss = get_miss(self, x)
get_slice_miss(self, dimspins, x)[source]

Convenience method to get list of missing values (get_miss), choose slice of array (get_slice), and set missing values to NaN in slice (set_miss).

Parameters
selfclass

ncvue class

dimspinslist

List of tk.Spinbox widgets of dimensions

xnetCDF4._netCDF4.Variable

netcdf variable

Returns
ndarray

Extracted array slice with missing values set to np.NaN

Examples

>>> x = fi.variables['time']
>>> xx = get_slice_miss(self, x)
set_dim_lat(self)[source]

Set spinboxes of latitude-dimensions.

Set labels and value lists. Select ‘all’ for all dimension.

Parameters
selfclass

ncvue class

Returns
None

Labels and values of spinboxes of latitude-dimensions set.

Examples

>>> set_dim_lat(self)
set_dim_lon(self)[source]

Set spinboxes of longitude-dimensions.

Set labels and value lists. Select ‘all’ for all dimension.

Parameters
selfclass

ncvue class

Returns
None

Labels and values of spinboxes of longitude-dimensions set.

Examples

>>> set_dim_lon(self)
set_dim_var(self)[source]

Set spinboxes of varable-dimensions in Map panel.

Set labels and value lists, including ‘all’ to select all entries, as well as ‘mean’, ‘std’, etc. for common operations on the axis.

Select ‘all’ for the first two limited dimensions and select 0 for all other dimensions.

Parameters
selfclass

ncvue class

Returns
None

Labels and values of spinboxes of variable-dimensions set.

Examples

>>> set_dim_var(self)
set_dim_x(self)[source]

Set spinboxes of x-dimensions.

Set labels and value lists, including ‘all’ to select all entries, as well as ‘mean’, ‘std’, etc. for common operations on the axis.

Select ‘all’ for the unlimited dimension if it exists, otherwise for the first dimension, and select 0 for all other dimensions.

Parameters
selfclass

ncvue class

Returns
None

Labels and values of spinboxes of x-dimensions set.

Examples

>>> set_dim_x(self)
set_dim_y(self)[source]

Set spinboxes of y-dimensions of the left-hand-side (lhs).

Set labels and value lists, including ‘all’ to select all entries, as well as ‘mean’, ‘std’, etc. for common operations on the axis.

Select ‘all’ for the unlimited dimension if it exists, otherwise for the first dimension, and select 0 for all other dimensions.

Parameters
selfclass

ncvue class

Returns
None

Labels and values of spinboxes of lhs y-dimensions set.

Examples

>>> set_dim_y(self)
set_dim_y2(self)[source]

Set spinboxes of y2-dimensions of the right-hand-side (rhs).

Set labels and value lists, including ‘all’ to select all entries, as well as ‘mean’, ‘std’, etc. for common operations on the axis.

Select ‘all’ for the unlimited dimension if it exists, otherwise for the first dimension, and select 0 for all other dimensions.

Parameters
selfclass

ncvue class

Returns
None

Labels and values of spinboxes of rhs y-dimensions set.

Examples

>>> set_dim_y2(self)
set_dim_z(self)[source]

Set spinboxes of z-dimensions.

Set labels and value lists, including ‘all’ to select all entries, as well as ‘mean’, ‘std’, etc. for common operations on the axis.

Select ‘all’ for the unlimited dimension if it exists, otherwise for the first dimension, as well as for a second dimension and select 0 for all other dimensions.

Parameters
selfclass

ncvue class

Returns
None

Labels and values of spinboxes of z-dimensions set.

Examples

>>> set_dim_z(self)