Skip to content

Commit 2bf6676

Browse files
committed
Allow groups in netcdf files
1 parent 70ed90b commit 2bf6676

File tree

10 files changed

+907
-539
lines changed

10 files changed

+907
-539
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
Changelog
22
---------
33

4-
v4.2 (??? 2024)
4+
v4.2 (Jan 2024)
5+
* Use local copy of `tooltip.py` from idle.
6+
* Allow groups in netcdf files.
57
* Made ``ncvue`` work with newer matplotlib versions, updating
68
colormaps and using matplotlib.pyplot.style 'seaborn-v0_8-dark'.
79
* Made ``ncvue`` work with newer Tcl/Tk versions (ttk.Style.theme_use).

src/ncvue/__init__.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,50 +58,54 @@
5858
* v4.1, final add_cyclic and has_cyclic as committed to cartopy,
5959
Nov 2021, Matthias Cuntz
6060
* v4.1.2, ncvue is gui_script entry_point, Jun 2022, Matthias Cuntz
61+
* v4.2, allow groups in netcdf files, Jan 2024, Matthias Cuntz
6162
6263
"""
63-
# version, author
64-
try:
65-
from ._version import __version__
66-
except ImportError: # pragma: nocover
67-
# package is not installed
68-
__version__ = "0.0.0.dev0"
69-
__author__ = "Matthias Cuntz"
70-
7164
# helper functions
65+
# copy from idle
66+
from .tooltip import TooltipBase, OnHoverTooltipBase, Hovertip
7267
# general helper function
73-
from .ncvutils import DIMMETHODS
74-
from .ncvutils import add_cyclic, has_cyclic, clone_ncvmain
75-
from .ncvutils import format_coord_contour, format_coord_map
76-
from .ncvutils import format_coord_scatter, get_slice
77-
from .ncvutils import list_intersection, set_axis_label, set_miss
78-
from .ncvutils import spinbox_values, vardim2var, zip_dim_name_length
79-
68+
from .ncvutils import DIMMETHODS
69+
from .ncvutils import add_cyclic, has_cyclic, clone_ncvmain
70+
from .ncvutils import format_coord_contour, format_coord_map
71+
from .ncvutils import format_coord_scatter, get_slice
72+
from .ncvutils import list_intersection, set_axis_label, set_miss
73+
from .ncvutils import spinbox_values, vardim2var, zip_dim_name_length
74+
#
8075
# common methods of all panels
8176
from .ncvmethods import analyse_netcdf, get_miss, get_slice_miss
8277
from .ncvmethods import set_dim_lat, set_dim_lon, set_dim_var
8378
from .ncvmethods import set_dim_x, set_dim_y, set_dim_y2, set_dim_z
84-
79+
#
8580
# adding widgets with labels, etc.
8681
from .ncvwidgets import Tooltip
8782
from .ncvwidgets import add_checkbutton, add_combobox, add_entry, add_imagemenu
8883
from .ncvwidgets import add_menu, add_scale, add_spinbox, add_tooltip
89-
84+
#
9085
# scatter/line panel
9186
from .ncvscatter import ncvScatter
9287
# contour panel
9388
from .ncvcontour import ncvContour
9489
# map panel
95-
from .ncvmap import ncvMap
90+
from .ncvmap import ncvMap
9691
# main window with panels
97-
from .ncvmain import ncvMain
98-
92+
from .ncvmain import ncvMain
93+
#
9994
# main calling program
10095
from .ncvue import ncvue
96+
#
97+
# version, author
98+
try:
99+
from ._version import __version__
100+
except ImportError: # pragma: nocover
101+
# package is not installed
102+
__version__ = "0.0.0.dev0"
103+
__author__ = "Matthias Cuntz"
101104

102105

103-
__all__ = ["DIMMETHODS",
104-
"add_cyclic", "clone_ncvmain",
106+
__all__ = ['TooltipBase', 'OnHoverTooltipBase', 'Hovertip',
107+
"DIMMETHODS",
108+
"add_cyclic", "has_cyclic", "clone_ncvmain",
105109
"format_coord_contour", "format_coord_map",
106110
"format_coord_scatter", "get_slice",
107111
"list_intersection", "set_axis_label", "set_miss",

src/ncvue/ncvcontour.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* Write coordinates and value on bottom of plotting canvas,
2626
May 2021, Matthias Cuntz
2727
* Address fi.variables[name] directly by fi[name], Jan 2024, Matthias Cuntz
28+
* Allow groups in netcdf files, Jan 2024, Matthias Cuntz
2829
2930
"""
3031
from __future__ import absolute_import, division, print_function
@@ -370,17 +371,17 @@ def newnetcdf(self):
370371
if self.top.fi:
371372
self.top.fi.close()
372373
# reset empty defaults of top
373-
self.top.dunlim = '' # name of unlimited dimension
374-
self.top.time = None # datetime variable
375-
self.top.tname = '' # datetime variable name
376-
self.top.tvar = '' # datetime variable name in netcdf
377-
self.top.dtime = None # decimal year
378-
self.top.latvar = '' # name of latitude variable
379-
self.top.lonvar = '' # name of longitude variable
380-
self.top.latdim = '' # name of latitude dimension
381-
self.top.londim = '' # name of longitude dimension
382-
self.top.maxdim = 0 # maximum num of dims of all variables
383-
self.top.cols = [] # variable list
374+
self.top.dunlim = [] # name of unlimited dimension
375+
self.top.time = [] # datetime variable
376+
self.top.tname = [] # datetime variable name
377+
self.top.tvar = [] # datetime variable name in netcdf
378+
self.top.dtime = [] # decimal year
379+
self.top.latvar = [] # name of latitude variable
380+
self.top.lonvar = [] # name of longitude variable
381+
self.top.latdim = [] # name of latitude dimension
382+
self.top.londim = [] # name of longitude dimension
383+
self.top.maxdim = 0 # maximum num of dims of all variables
384+
self.top.cols = [] # variable list
384385
# open new netcdf file
385386
self.top.fi = nc.Dataset(ncfile, 'r')
386387
analyse_netcdf(self.top)
@@ -611,13 +612,13 @@ def redraw(self):
611612
if (z != ''):
612613
# z axis
613614
gz, vz = vardim2var(z, self.fi.groups.keys())
614-
if vz == self.tname:
615+
if vz == self.tname[gz]:
615616
# should throw an error later
616617
if mesh:
617-
zz = self.dtime
618+
zz = self.dtime[gz]
618619
zlab = 'Year'
619620
else:
620-
zz = self.time
621+
zz = self.time[gz]
621622
zlab = 'Date'
622623
else:
623624
zz = self.fi[vz]
@@ -630,12 +631,12 @@ def redraw(self):
630631
if (y != ''):
631632
# y axis
632633
gy, vy = vardim2var(y, self.fi.groups.keys())
633-
if vy == self.tname:
634+
if vy == self.tname[gy]:
634635
if mesh:
635-
yy = self.dtime
636+
yy = self.dtime[gy]
636637
ylab = 'Year'
637638
else:
638-
yy = self.time
639+
yy = self.time[gy]
639640
ylab = 'Date'
640641
else:
641642
yy = self.fi[vy]
@@ -644,12 +645,12 @@ def redraw(self):
644645
if (x != ''):
645646
# x axis
646647
gx, vx = vardim2var(x, self.fi.groups.keys())
647-
if vx == self.tname:
648+
if vx == self.tname[gx]:
648649
if mesh:
649-
xx = self.dtime
650+
xx = self.dtime[gx]
650651
xlab = 'Year'
651652
else:
652-
xx = self.time
653+
xx = self.time[gx]
653654
xlab = 'Date'
654655
else:
655656
xx = self.fi[vx]

src/ncvue/ncvmain.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* Written Nov-Dec 2020 by Matthias Cuntz (mc (at) macu (dot) de)
2525
* Added check_new_netcdf method that re-initialises all panels if netcdf
2626
file changed, Jan 2021, Matthias Cuntz
27+
* Address fi.variables[name] directly by fi[name], Jan 2024, Matthias Cuntz
28+
* Allow groups in netcdf files, Jan 2024, Matthias Cuntz
2729
2830
"""
2931
from __future__ import absolute_import, division, print_function
@@ -80,13 +82,17 @@ def __init__(self, master, **kwargs):
8082
self.tab_map = ncvMap(self)
8183

8284
mapfirst = False
83-
if self.top.latvar:
84-
gl, vl = vardim2var(self.top.latvar, self.top.fi.groups.keys())
85-
if np.prod(self.top.fi.variables[vl].shape) > 1:
85+
if any(self.top.latvar):
86+
idx = [ i for i, l in enumerate(self.top.latvar) if l ]
87+
gl, vl = vardim2var(self.top.latvar[idx[0]],
88+
self.top.fi.groups.keys())
89+
if np.prod(self.top.fi[vl].shape) > 1:
8690
mapfirst = True
87-
if self.top.lonvar:
88-
gl, vl = vardim2var(self.top.lonvar, self.top.fi.groups.keys())
89-
if np.prod(self.top.fi.variables[vl].shape) > 1:
91+
if any(self.top.lonvar):
92+
idx = [ i for i, l in enumerate(self.top.lonvar) if l ]
93+
gl, vl = vardim2var(self.top.lonvar[idx[0]],
94+
self.top.fi.groups.keys())
95+
if np.prod(self.top.fi[vl].shape) > 1:
9096
mapfirst = True
9197

9298
if mapfirst:

0 commit comments

Comments
 (0)