Skip to content
Snippets Groups Projects
Commit c579843a authored by Coda Phillips's avatar Coda Phillips
Browse files

add dcc notebook

parent 826874f7
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
%pylab inline
```
%% Output
%pylab is deprecated, use %matplotlib inline and import the required libraries.
Populating the interactive namespace from numpy and matplotlib
%% Cell type:code id: tags:
``` python
import numpy as np
import pandas as pd
from collections import defaultdict
from pathlib import Path
from tqdm import tqdm
import netCDF4
import l2bc_utils
from l2bc_utils import PLATFORM_COLORS
```
%% Cell type:code id: tags:
``` python
# Read csv of file metadata
root = Path('/data/www/patmosx_l2bc')
_files = pd.read_csv(root / 'index.csv', parse_dates=['date'])
# Fast
_files['root'] = str(root) + '/'
_files['path'] = _files['root'].str.cat(_files['path'])
```
%% Cell type:code id: tags:
``` python
# pivot into variable columns
files = l2bc_utils.pivot_files(_files)
```
%% Cell type:code id: tags:
``` python
# Grab the first file to get the lat/lon
for f in files.values.ravel():
if f:
nc = netCDF4.Dataset(f)
lat = nc.variables['latitude'][:]
lon = nc.variables['longitude'][:]
nc.close()
break
```
%% Cell type:code id: tags:
``` python
lon, lat = np.meshgrid(lon, lat)
```
%% Cell type:code id: tags:
``` python
df = []
count = 0
for (platform, date, node), (sza, vza, t11, r065) in l2bc_utils.iter_nc_var(files, 'solar_zenith_angle', 'sensor_zenith_angle', 'temp_11_0um_nom', 'refl_0_65um_nom_counts'):
cold = t11 < 200
day = sza < 80
tropics = (lat > -20) & (lat < 20)
near_nadir = abs(vza) < 15
mask = cold & day & tropics & near_nadir
_df = (pd.DataFrame({
'solar_zenith_angle': sza[mask],
'sensor_zenith_angle': vza[mask],
'refl_0_65um_nom_counts': r065[mask],
'latitude': lat[mask],
'longitude': lon[mask],
}))
# subset
_df['platform'] = platform
_df['date'] = date
_df['node'] = node
df.append(_df)
count += len(_df)
```
%% Output
0%| | 0/79822 [00:00<?, ?it/s]
100%|██████████| 79822/79822 [25:33<00:00, 52.07it/s]
%% Cell type:code id: tags:
``` python
df = pd.concat(df)
```
%% Cell type:code id: tags:
``` python
k = 'refl_0_65um_nom_counts'
cos_sza = np.cos(np.deg2rad(df.solar_zenith_angle))
norm_counts = df[k] / cos_sza
norm_counts.index = pd.MultiIndex.from_frame(df[['platform', 'date', 'node']])
```
%% Cell type:code id: tags:
``` python
norm_counts_means = norm_counts.groupby('platform').apply(lambda x: x.droplevel(['platform','node']).resample('1MS').mean())
```
%% Cell type:code id: tags:
``` python
figure(figsize=(15,5))
for platform, s in norm_counts_means.groupby('platform'):
s = s.droplevel('platform')
s = s.groupby(lambda x: x.month, group_keys=False).apply(lambda x: x-x.mean()) + s.mean()
scatter(s.index, s.values, label=platform, color=PLATFORM_COLORS[platform.lower()], s=5)
ylabel(f'({k} / µ)')
title('Deseasonalized Normalized Counts')
legend(loc='center left', bbox_to_anchor=(1, .5))
ylim([400, 900])
grid()
```
%% Output
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment