<jupyter_start><jupyter_text>Analyzing QUBICC Data**For Figure 1 of the paper**<jupyter_code>import os
import sys
import xarray as xr
import numpy as np
import pandas as pd
import importlib
import matplotlib
import matplotlib.pyplot as plt

# For psyplot
import psyplot.project as psy
import matplotlib as mpl
# %matplotlib inline
# %config InlineBackend.close_figures = False

psy.rcParams['plotter.maps.xgrid'] = False
psy.rcParams['plotter.maps.ygrid'] = False
mpl.rcParams['figure.figsize'] = [10., 8.]
# path = '/pf/b/b309170/my_work/QUBICC/data_var_vertinterp/cl/'

# file = 'int_var_hc2_02_p1m_cl_ml_20041110T010000Z.nc'
path = '/pf/b/b309170/my_work/QUBICC/'
file_cg = 'data_hor_interp/hc2_02_p1m_cl_ml_20041105T150000Z.nc'
file_orig = 'some_orig_data/hc2_02_p1m_cl_ml_20041105T150000Z.nc'<jupyter_output><empty_output><jupyter_text>Question 1: Does the coarse-graining look right? Of horizontal coarse-graining (psyplot): If you get the error 'ValueError: Can only plot 2-dimensional data!', then you need to use cdo setgrid on the file first.**'height' 40 is layer 41 counting from 1 to 91**<jupyter_code># # Note that the cloud cover scheme used was a 0-1 cloud cover scheme.
# maps = psy.plot.mapplot(os.path.join(path, file_orig), dims = {'name': 'ccl', 'height': 40}, 
#                         projection='robin', cmap='Blues_r', title='Cloud cover on 20041105 at 15:00 (on layer 40)')
# plt.savefig('original_cloud_cover_snapshot.pdf')

# Note that the cloud cover scheme used was a 0-1 cloud cover scheme.
maps = psy.plot.mapplot(os.path.join(path, file_orig), dims = {'name': 'ccl', 'height': 40}, cticksize=34,
                        projection='robin', cmap='Blues_r')
plt.savefig('original_cloud_cover_snapshot_untitled.pdf')
# maps = psy.plot.mapplot(os.path.join(path, file_cg), dims = {'name': 'cl', 'height': 40}, 
#                         projection='robin', cmap='Blues_r', title='Horizontally interpolated cloud cover on 20041105 at 15:00 (on layer 40)')
# plt.savefig('horizontally_coarse_grained_cloud_cover.pdf')

maps = psy.plot.mapplot(os.path.join(path, file_cg), dims = {'name': 'cl', 'height': 40}, cticksize=34,
                        projection='robin', cmap='Blues_r')
# plt.savefig('horizontally_coarse_grained_cloud_cover_untitled.pdf')<jupyter_output><empty_output><jupyter_text>Of vertical coarse-graining:<jupyter_code># Some arbitrary horizontal field
rand_field = np.random.randint(20480)
# rand_field = 15252 # To reproduce the profile from the paper
rand_field
## Load original data
# Load zg profile
DS = xr.open_dataset('/pf/b/b309170/my_work/QUBICC/grids/qubicc_l191_zg_ml_0015_R02B04_G.nc')
da = DS.zg.values
zg_hr = da[:, rand_field]
zg_hr = zg_hr[-91:] # Need the 91 earth-bound layers
# Load clc profile
DS = xr.open_dataset('/pf/b/b309170/my_work/QUBICC/data_hor_interp/hc2_02_p1m_cl_ml_20041105T150000Z.nc')
da = DS.cl.values
print(da.shape)
cl_hr = da[0, :, rand_field]
## Load vertically coarse-grained data
# Load clc profile
DS = xr.open_dataset('/pf/b/b309170/my_work/QUBICC/data_var_vertinterp/cl/int_var_hc2_02_p1m_cl_ml_20041105T150000Z_R02B04.nc')
da = DS.cl.values
not_nan = ~np.isnan(da[0,:,rand_field])
cl_lr = da[0, not_nan, rand_field]
# Load zg profile
DS = xr.open_dataset('/pf/b/b309170/my_work/QUBICC/data_var_vertinterp/zg/zg_icon-a_capped.nc')
da = DS.zg.values
zg_lr = da[not_nan, rand_field] 
# Increase the general font size
size_plot_elements = 16
matplotlib.rcParams['legend.fontsize'] = size_plot_elements
matplotlib.rcParams['axes.labelsize'] = size_plot_elements # For an axes xlabel and ylabel
matplotlib.rcParams['xtick.labelsize'] = size_plot_elements
matplotlib.rcParams['ytick.labelsize'] = size_plot_elements
fig = plt.figure(figsize=(2,4))

# # Units in kilometers
# zg_hr = zg_hr/1000
# zg_lr = zg_lr/1000

# ax = fig.add_subplot(211, title='High-res vertical cloud cover profile', ylim=(0, np.max(zg_lr)), xlim=(-0.05,1),
#                     xlabel='Cloud Cover Fraction', ylabel='Mean height of a vertical layer in km')
ax = fig.add_subplot(111, ylim=(0, np.max(zg_lr)), xlim=(-0.05,1), ylabel='z [km]', xticks=[0,0.5,1])
ax.plot(cl_hr, zg_hr)
ax.plot(cl_hr, zg_hr, 'b.')

plt.savefig('vertical_coarse-graining_qubicc_example_v2_1.pdf', bbox_inches='tight')
fig = plt.figure(figsize=(2,4))

# ax_2 = fig.add_subplot(212, title='Low-res vertical cloud cover profile', ylim=(0, np.max(zg_lr)), xlim=(-0.05,1),
#                       xlabel='Cloud Cover Fraction', ylabel='Mean height of a vertical layer in km')
ax_2 = fig.add_subplot(111, ylim=(0, np.max(zg_lr)), xlim=(-0.05,1),
                      xlabel='Cloud Fraction', ylabel='z [km]', xticks=[0,0.5,1])
ax_2.plot(cl_lr, zg_lr)
ax_2.plot(cl_lr, zg_lr, 'b.')

plt.savefig('vertical_coarse-graining_qubicc_example_v2_2.pdf', bbox_inches='tight')
fig = plt.figure(figsize=(10,7))

ax = fig.add_subplot(121, title='High-res vertical cloud cover profile')
ax.plot(cl_hr, zg_hr)
ax.plot(cl_hr, zg_hr, 'b.')

ax_2 = fig.add_subplot(122, title='Low-res vertical cloud cover profile')
ax_2.plot(cl_lr, zg_lr)
ax_2.plot(cl_lr, zg_lr, 'b.')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1409028727770178, 'fraction_numerical': 0.05647840531561462, 'mean_word_length': 5.12200956937799, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '150703', 'license': 'MIT', 'n_tokens_mistral': 2202, 'n_tokens_neox': 2006, 'n_words': 404, 'path': 'additional_content/analyzing_the_data/analyzing_qubicc.ipynb', 'repo_name': 'agrundner24/iconml_clc', 'size': '5117'}