plot.py 1.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#%%
import xarray as xr
import matplotlib.pyplot as plt
import numpy as np

from IPython import get_ipython
get_ipython().magic('reset -sf')

import matplotlib
get_ipython().magic('matplotlib inline')


class section:
    def __init__(self, filename, varname):
        self.filename = filename
        self.varname = varname
        try:
            self.var = self.load()[varname]
        except KeyError:
            print('Variable does not exist, choose new from:')
            print(self.load().data_vars)
            
        self.data = 'something'
        
    def load(self):
        return xr.open_dataset(self.filename)
    
    
    def select(self, timestep, axis, position):
        try: 
            self.var[axis]
            if axis == 'xu':
                self.data = self.var.isel(xu=position).isel(Time=timestep)
            elif axis == 'yt':
                self.data = self.var.isel(yt=position).isel(Time=timestep)
            elif axis == 'zt':
                self.data = self.var.isel(zt=position).isel(Time=timestep)
            elif axis == 'xt':
                self.data = self.var.isel(xt=position).isel(Time=timestep)
        except KeyError:
            print('Axis does not exist, choose new from: \n', self.var.coords)
            


        
        return self.data
        
    def figure(self):
        pass
    
    def fileinfo(self):
        print('Info: ', self.load())


try:
    del p
except NameError:
    pass

p = section('dwbc1.snapshot.nc','temp')


plt.figure()
p.select(28,'zt',15).plot.contourf()
# 

# plt.colorbar()
# plt.show()