```python
import iris
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
```

\begin{equation}
\int_{0}^{t} FA \; dt = \bar{F} \int_{0}^{t} A' \; dt \; + \; \bar{A} \int_{0}^{t} F' \; dt 
\end{equation}


```python
evap_area_file = '/g/data/r87/dbi599/CMIP6/DAMIP/CSIRO/ACCESS-ESM1-5/hist-GHG/r1i1p1f1/Ayr/evspsbl/gn/v20200615/evspsbl-pe-region-sum-anomaly_Ayr_ACCESS-ESM1-5_hist-GHG_r1i1p1f1_gn_185001-202012-cumsum.nc'
evap_bar_file = '/g/data/r87/dbi599/CMIP6/CMIP/CSIRO/ACCESS-ESM1-5/piControl/r1i1p1f1/Ayr/evspsbl/gn/v20191214/evspsbl-pe-region-mean_Ayr_ACCESS-ESM1-5_piControl_r1i1p1f1_gn_010101-100012.nc'
evap_dashed_file = '/g/data/r87/dbi599/CMIP6/DAMIP/CSIRO/ACCESS-ESM1-5/hist-GHG/r1i1p1f1/Ayr/evspsbl/gn/v20200615/evspsbl-pe-region-mean-anomaly_Ayr_ACCESS-ESM1-5_hist-GHG_r1i1p1f1_gn_185001-202012-cumsum.nc'
area_bar_file = '/g/data/r87/dbi599/CMIP6/CMIP/CSIRO/ACCESS-ESM1-5/piControl/r1i1p1f1/Ayr/areacella/gn/v20191214/areacella-pe-region-sum_Ayr_ACCESS-ESM1-5_piControl_r1i1p1f1_gn_010101-100012.nc'
area_dashed_file = '/g/data/r87/dbi599/CMIP6/DAMIP/CSIRO/ACCESS-ESM1-5/hist-GHG/r1i1p1f1/Ayr/areacella/gn/v20200615/areacella-pe-region-sum-anomaly_Ayr_ACCESS-ESM1-5_hist-GHG_r1i1p1f1_gn_185001-202012-cumsum.nc'
```


```python
evap_area_cube = iris.load_cube(evap_area_file, 'water_evapotranspiration_flux')
evap_bar_cube = iris.load_cube(evap_bar_file, 'water_evapotranspiration_flux')
evap_dashed_cube = iris.load_cube(evap_dashed_file, 'water_evapotranspiration_flux')
area_bar_cube = iris.load_cube(area_bar_file, 'cell_area')
area_dashed_cube = iris.load_cube(area_dashed_file, 'cell_area')
```


```python
def get_time_integral(cube, variable):
    """Get time integral"""

    start = cube[0, 0:5, -1].data
    value = cube[-1, 0:5, -1].data - start
    
    return value


def get_average(cube, variable, ntime):
    """Get average"""
    
    data = cube.data[0:ntime, 0:5, -1]
    average = np.mean(data, axis=0)
    
    return average
```


```python
evap_area_integral = get_time_integral(evap_area_cube, 'water_evapotranspiration_flux')
evap_dashed_integral = get_time_integral(evap_dashed_cube, 'water_evapotranspiration_flux')
area_dashed_integral = get_time_integral(area_dashed_cube, 'cell_area')
```


```python
evap_bar = get_average(evap_bar_cube, 'water_evapotranspiration_flux', evap_area_cube.shape[0])
area_bar = get_average(area_bar_cube, 'cell_area', evap_area_cube.shape[0])
```


```python
evap_area_integral.data
```




    array([-8.97865292e+16,  4.66662497e+17,  1.17329324e+17,  2.89853212e+17,
            6.27760929e+16])




```python
(evap_bar * area_dashed_integral) + (area_bar * evap_dashed_integral) 
```




    masked_array(data=[-8.95757164e+16,  4.64583727e+17,  1.19091390e+17,
                        2.91554073e+17,  6.29280691e+16],
                 mask=False,
           fill_value=1e+20)




```python
area_component = evap_bar * area_dashed_integral
intensity_component = area_bar * evap_dashed_integral
```


```python
data = [['total', 'SH precip', evap_area_integral[0]],
        ['total', 'SH evap', evap_area_integral[1]],
        ['total', 'tropical precip', evap_area_integral[2]],
        ['total', 'NH evap', evap_area_integral[3]],
        ['total', 'NH precip', evap_area_integral[4]],
        ['area', 'SH precip', area_component[0]],
        ['area', 'SH evap', area_component[1]],
        ['area', 'tropical precip', area_component[2]],
        ['area', 'NH evap', area_component[3]],
        ['area', 'NH precip', area_component[4]],
        ['intensity', 'SH precip', intensity_component[0]],
        ['intensity', 'SH evap', intensity_component[1]],
        ['intensity', 'tropical precip', intensity_component[2]],
        ['intensity', 'NH evap', intensity_component[3]],
        ['intensity', 'NH precip', intensity_component[4]],
       ]
```


```python
df = pd.DataFrame(data, columns = ['component', 'P-E region', 'time-integrated anomaly (kg)']) 
```


```python
df
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>component</th>
      <th>P-E region</th>
      <th>time-integrated anomaly (kg)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>total</td>
      <td>SH precip</td>
      <td>-8.978653e+16</td>
    </tr>
    <tr>
      <th>1</th>
      <td>total</td>
      <td>SH evap</td>
      <td>4.666625e+17</td>
    </tr>
    <tr>
      <th>2</th>
      <td>total</td>
      <td>tropical precip</td>
      <td>1.173293e+17</td>
    </tr>
    <tr>
      <th>3</th>
      <td>total</td>
      <td>NH evap</td>
      <td>2.898532e+17</td>
    </tr>
    <tr>
      <th>4</th>
      <td>total</td>
      <td>NH precip</td>
      <td>6.277609e+16</td>
    </tr>
    <tr>
      <th>5</th>
      <td>area</td>
      <td>SH precip</td>
      <td>-6.177479e+16</td>
    </tr>
    <tr>
      <th>6</th>
      <td>area</td>
      <td>SH evap</td>
      <td>2.475651e+17</td>
    </tr>
    <tr>
      <th>7</th>
      <td>area</td>
      <td>tropical precip</td>
      <td>-6.613969e+16</td>
    </tr>
    <tr>
      <th>8</th>
      <td>area</td>
      <td>NH evap</td>
      <td>6.413645e+16</td>
    </tr>
    <tr>
      <th>9</th>
      <td>area</td>
      <td>NH precip</td>
      <td>-3.762233e+16</td>
    </tr>
    <tr>
      <th>10</th>
      <td>intensity</td>
      <td>SH precip</td>
      <td>-2.780093e+16</td>
    </tr>
    <tr>
      <th>11</th>
      <td>intensity</td>
      <td>SH evap</td>
      <td>2.170186e+17</td>
    </tr>
    <tr>
      <th>12</th>
      <td>intensity</td>
      <td>tropical precip</td>
      <td>1.852311e+17</td>
    </tr>
    <tr>
      <th>13</th>
      <td>intensity</td>
      <td>NH evap</td>
      <td>2.274176e+17</td>
    </tr>
    <tr>
      <th>14</th>
      <td>intensity</td>
      <td>NH precip</td>
      <td>1.005504e+17</td>
    </tr>
  </tbody>
</table>
</div>




```python
#plt.figure(figsize=[12, 12])
sns.catplot(data=df, kind="bar", x="P-E region", y="time-integrated anomaly (kg)", hue="component")
```


```python

```

ee8b2a6f54a62750c0475f897d762dae8132ea15
ipynb
Jupyter Notebook
development/pe_area_decomposition.ipynb
DamienIrving/ocean-analysis
23a6dbf616fb84e6e158e32534ffd394e0df2e3e
MIT
2017-06-06T20:20:58.000Z
2020-02-05T23:28:41.000Z
development/pe_area_decomposition.ipynb
DamienIrving/ocean-analysis
23a6dbf616fb84e6e158e32534ffd394e0df2e3e
MIT
2017-04-06T04:46:37.000Z
2021-07-01T00:47:50.000Z
development/pe_area_decomposition.ipynb
DamienIrving/ocean-analysis
23a6dbf616fb84e6e158e32534ffd394e0df2e3e
MIT
2021-01-19T01:31:40.000Z
2022-03-15T00:50:11.000Z
Qwen/Qwen-72B
1. YES
2. YES