Skip to content
Snippets Groups Projects
Commit dcead4f6 authored by Nils Brüggemann's avatar Nils Brüggemann Committed by Fraser William Goldsworth
Browse files

pyic_view.py: Some bug fixes with depth dimensions and slider to also allow...

pyic_view.py: Some bug fixes with depth dimensions and slider to also allow plotting atmosphere and ice variables.
parent 957ef859
No related branches found
No related tags found
1 merge request!43Allow users to set projection with cartopy projection object
#!/usr/bin/env python
import matplotlib.pyplot as plt
import tkinter as tk
from tkinter import ttk
import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import pyicon as pyic
import cartopy.crs as ccrs
......@@ -165,7 +164,7 @@ class view(object):
orient="horizontal", label="time", command=self.update_plot)
self.slider_t.grid(row=1, column=0, columnspan=2, sticky="ew")
self.slider_d = tk.Scale(root, from_=0, to=len(self.ds.depth)-1,
self.slider_d = tk.Scale(root, from_=0, to=1,
orient="horizontal", label="depth", command=self.update_plot)
self.slider_d.grid(row=1, column=2, columnspan=2, sticky="ew")
......@@ -306,6 +305,7 @@ class view(object):
delvars = [
"clon_bnds", "clat_bnds", "elon_bnds", "elat_bnds",
"vlon_bnds", "vlat_bnds",
"height_bnds", "height_2_bnds", "depth_bnds", "depth_2_bnds",
"clon", "clat", "elon", "elat",
"lev",
"healpix",
......@@ -319,6 +319,22 @@ class view(object):
print(f"variables in data set: {self.var_names}")
self.var_name = self.var_names[0]
self.depth_names = dict()
self.nzs = dict()
delvars = []
for var in list(self.ds):
try:
if self.ds[var].ndim==3:
self.depth_names[var] = pyic.identify_depth_name(self.ds[var])
self.nzs[var] = self.ds[self.depth_names[var]].size
else:
self.depth_names[var] = 'none'
self.nzs[var] = 0
except:
delvars.append(var)
print(f'Excluding the following variables from data set due to issues with dimension specification: {delvars}')
self.ds = self.ds.drop_vars(delvars)
def plot_data(self):
# get updated limits
self.update_lon_lat_reg()
......@@ -408,6 +424,7 @@ class view(object):
# Function to update plot
def update_plot(self, *args):
# Get current slider values
self.it = int(self.slider_t.get())
self.iz = int(self.slider_d.get())
......@@ -416,6 +433,9 @@ class view(object):
self.var_name = self.selected_var.get()
cmap = self.selected_cmap.get()
self.res = float(self.selected_res.get())
# update depth slider
self.slider_d.config(to=self.nzs[self.var_name]-1)
print(f'{self.var_name}: it = {self.it}; iz = {self.iz}')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment