# TIEGCM


The kamodofied tiegcm requires the pytiegcm reader available on github:

    pip install -e git+https://github.com/asher-pembroke/pytiegcm.git#egg=pytiegcm

The TIEGCM reader also requires `netcdf4` (and numpy, scipy, and pandas, but those are required by kamodo)

    pip install netcdf4

!!! warning
    This is a work in progress!


```python
filename = '/Users/apembrok/Work/TIEGCM/sample_data/jasoon_shim_040118_IT_1/s001.nc' # ccmc run (no zgmid)
fname = '/Users/apembrok/Downloads/2013.03.01.tie-gcm.data/s003.nc' # (no zgmid)
```


```python
from kamodo import readers
```


```python
from kamodo.readers.tiegcm import TIEGCM_Kamodo
```

By default, the kamodofied TIEGCM reader will load all 3d and 4d variables from the model. For performance reasons, you may want to only include certain variables for analysis. To do so, pass a list of variables in addition to the filename:


```python
tiegcm = TIEGCM_Kamodo(fname, ['TN', 'UN', 'VN', 'EFLUX', 'Z'])

```

    initializing tiegcm with /Users/apembrok/Downloads/2013.03.01.tie-gcm.data/s003.nc


    /Users/apembrok/git/kamodo/docs/notebooks/src/pytiegcm/tiegcm/tiegcm.py:213: UserWarning:
    
    WARNING: missing_value not used since it
    cannot be safely cast to variable data type
    


    registered 5 variables



```python
tiegcm
```




\begin{equation}\operatorname{TN}{\left(t,ilev,lat,lon \right)} [K] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}\operatorname{UN}{\left(t,ilev,lat,lon \right)} [cm/s] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}\operatorname{VN}{\left(t,ilev,lat,lon \right)} [cm/s] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}Z{\left(t,ilev,lat,lon \right)} [cm] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}\operatorname{EFLUX}{\left(t,lat,lon \right)} = \lambda{\left(t,lat,lon \right)}\end{equation}\begin{equation}\operatorname{ilev}{\left(t,z,lat,lon \right)} = \lambda{\left(t,z,lat,lon \right)}\end{equation}



Below is an attempt to use function composition to solve variables as a function of height.


```python
from scipy.interpolate import interp1d
```


```python
import numpy as np
z = np.squeeze(tiegcm.Z(tiegcm._time[0], lat = 0, lon = 0))
```


```python
tiegcm['T_N(t, z, lat, lon)'] = 'TN(t,ilev, lat, lon)'
```


```python
tiegcm
```




\begin{equation}\operatorname{TN}{\left(t,ilev,lat,lon \right)} [K] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}\operatorname{UN}{\left(t,ilev,lat,lon \right)} [cm/s] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}\operatorname{VN}{\left(t,ilev,lat,lon \right)} [cm/s] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}Z{\left(t,ilev,lat,lon \right)} [cm] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}\operatorname{EFLUX}{\left(t,lat,lon \right)} = \lambda{\left(t,lat,lon \right)}\end{equation}\begin{equation}\operatorname{ilev}{\left(t,z,lat,lon \right)} = \lambda{\left(t,z,lat,lon \right)}\end{equation}\begin{equation}\operatorname{T_{N}}{\left(t,z,lat,lon \right)} = \operatorname{TN}{\left(t,\operatorname{ilev}{\left(t,z,lat,lon \right)},lat,lon \right)}\end{equation}




```python
import numpy as np

@np.vectorize
def lev(self, t, z, lat, lon):
    # 1) meshgrid and squeeze the shapes of time, lat, lon if they are not the same
    # 2) calculate z_levels for all points
    # 3) construct rgi for (time, z_level, lat, lon)
    # 4) interpolate over z
    
    z_levels = self.Z(time = t, lat = lat, lon = lon)
    level = scipy.interpolate.interp1d(z_levels, ilev, bounds_error=False)
    return level(z)
tiegcm.lev = lev
```


```python
tiegcm['ilev'] = lev
```


```python
tiegcm['T_N(t, z, lat, lon)'] = 'TN(t, ilev, lat, lon)'
```


```python
tiegcm
```




\begin{equation}\operatorname{TN}{\left(t,ilev,lat,lon \right)} [K] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}\operatorname{UN}{\left(t,ilev,lat,lon \right)} [cm/s] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}\operatorname{VN}{\left(t,ilev,lat,lon \right)} [cm/s] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}Z{\left(t,ilev,lat,lon \right)} [cm] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}\operatorname{EFLUX}{\left(t,lat,lon \right)} = \lambda{\left(t,lat,lon \right)}\end{equation}\begin{equation}\operatorname{ilev}{\left(t,z,lat,lon \right)} = \lambda{\left(t,z,lat,lon \right)}\end{equation}\begin{equation}\operatorname{T_{N}}{\left(t,z,lat,lon \right)} = \operatorname{TN}{\left(t,\operatorname{ilev}{\left(t,z,lat,lon \right)},lat,lon \right)}\end{equation}




```python
tiegcm['eflux'] = 'EFLUX(t, lat, lon)'
```


```python
tiegcm
```




\begin{equation}\operatorname{TN}{\left(t,ilev,lat,lon \right)} [K] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}\operatorname{UN}{\left(t,ilev,lat,lon \right)} [cm/s] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}\operatorname{VN}{\left(t,ilev,lat,lon \right)} [cm/s] = \lambda{\left(t,ilev,lat,lon \right)}\end{equation}\begin{equation}\operatorname{EFLUX}{\left(t,lat,lon \right)} = \lambda{\left(t,lat,lon \right)}\end{equation}\begin{equation}t{\left(ilev \right)} = \lambda{\left(ilev \right)}\end{equation}\begin{equation}\operatorname{eflux}{\left(ilev,lat,lon \right)} = \operatorname{EFLUX}{\left(t{\left(ilev \right)},lat,lon \right)}\end{equation}




```python
%load_ext autoreload
%autoreload 2
```

    The autoreload extension is already loaded. To reload it, use:
      %reload_ext autoreload



```python

```

ipynb
b3127cbb61e2cd2ea184c1554a6de6e3ac58c21e
Jupyter Notebook
2022-03-07T15:39:18.000Z
2019-08-16T21:22:40.000Z
75841f7ad832997159046d4b2523e0a244316e9d
NASA-1.3
EnsembleGovServices/Kamodo-ccmc-readers
docs/notebooks/TIEGCM.ipynb
75841f7ad832997159046d4b2523e0a244316e9d
2022-01-18T17:00:15.000Z
2020-02-13T20:46:13.000Z
NASA-1.3
EnsembleGovServices/Kamodo-ccmc-readers
docs/notebooks/TIEGCM.ipynb
75841f7ad832997159046d4b2523e0a244316e9d
NASA-1.3
EnsembleGovServices/Kamodo-ccmc-readers
docs/notebooks/TIEGCM.ipynb
2022-01-13T16:33:51.000Z
2019-08-30T16:18:53.000Z