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:

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

license:

MIT License, see LICENSE for details.

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 or np.datetime64('NaT') 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.

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

  • Make self.time numpy’s datetime64[ms] format, May 2021, Matthias Cuntz

  • Add numpy’s datetime64[ms] to missing values, May 2021, Matthias Cuntz

  • Removed bug in detection of lon/lat (analyse_netcdf), Oct 2021, Matthias Cuntz

  • Identify lon/lat also by axis attributes x/y or X/Y (analyse_netcdf), Oct 2021, Matthias Cuntz

  • Do not default the unlimited dimension to ‘all’ if no lon/lat were found, (get_dim_var) Oct 2021, Matthias Cuntz

  • Address fi.variables[name] directly by fi[name], Jan 2024, Matthias Cuntz

  • Allow groups in netcdf files, Jan 2024, Matthias Cuntz

  • Squeeze output in get_slice_miss only if more than 1 dim, Jan 2024, Matthias Cuntz

  • Allow multiple netcdf files, Jan 2024, Matthias Cuntz

analyse_netcdf(self)[source]#

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

Parameters:

self (class) – ncvue class

Returns:

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

Return type:

Set variables

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:
  • self (class) – ncvue class

  • x (netCDF4._netCDF4.Variable) – netcdf variable

Returns:

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

Return type:

list

Examples

>>> x = fi['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 or np.datetime64(‘NaT’) in slice (set_miss).

Parameters:
  • self (class) – ncvue class

  • dimspins (list) – List of tk.Spinbox widgets of dimensions

  • x (netCDF4._netCDF4.Variable) – netcdf variable

Returns:

Extracted array slice with missing values set to np.NaN or np.datetime64(‘NaT’)

Return type:

ndarray

Examples

>>> x = fi['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:

self (class) – ncvue class

Returns:

Labels and values of spinboxes of latitude-dimensions set.

Return type:

None

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:

self (class) – ncvue class

Returns:

Labels and values of spinboxes of longitude-dimensions set.

Return type:

None

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:

self (class) – ncvue class

Returns:

Labels and values of spinboxes of variable-dimensions set.

Return type:

None

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:

self (class) – ncvue class

Returns:

Labels and values of spinboxes of x-dimensions set.

Return type:

None

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:

self (class) – ncvue class

Returns:

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

Return type:

None

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:

self (class) – ncvue class

Returns:

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

Return type:

None

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:

self (class) – ncvue class

Returns:

Labels and values of spinboxes of z-dimensions set.

Return type:

None

Examples

>>> set_dim_z(self)