{ "cells": [ { "cell_type": "code", "execution_count": 11, "id": "2e336d6e", "metadata": {}, "outputs": [], "source": [ "#Import libraries\n", "import numpy as np\n", "import xarray as xr\n", "import scipy\n", "from scipy import stats\n", "import scipy.special as sp\n", "import matplotlib.pyplot as plt\n", "from glob import glob\n", "import os\n", "import warnings" ] }, { "cell_type": "code", "execution_count": 12, "id": "6130b8b3", "metadata": {}, "outputs": [], "source": [ "#Set paths\n", "dir_data = '/Users/jzhang/Documents/Data/'\n", "dir_proj = '/Users/jzhang/Documents/Projects/Albedo_Symmetry_WE/codes/open_code/'\n", "\n", "#Load data\n", "ebaf = xr.open_mfdataset(sorted(glob(dir_data+'CERES/EBAFed421/CERES_EBAF_Ed4.2.1_Subset_*.nc'))).sel(time=slice(np.datetime64('2001-01-01'),np.datetime64('2024-12-31')))\n", "ocean = xr.open_dataset(dir_data+'CERES/SYN1deg/CERES_SYN1deg-Month_Terra-Aqua-NOAA20_Ed4.2_Subset_200003-202512.nc').sel(time=slice(np.datetime64('2001-01-01'),np.datetime64('2024-12-31')))\n", "oce_frac = ocean['aux_ocean_mon']/100.\n", "snow_frac = ocean['aux_snow_mon']/100." ] }, { "cell_type": "code", "execution_count": null, "id": "7e673245", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Calculating:\n", "...all...\n", "...clr...\n", "...clr...\n", "...aer...\n", "...sfc...\n", "Done!\n", "\n", "Saving files:\n", "...all...\n", "...cld...\n", "...ocean and snow...\n", "...clr...\n", "Done!\n" ] } ], "source": [ "#Set up master array to store decompositions\n", "xR = xr.Dataset() \n", "xR['time'] = ebaf.time\n", "xR['lat'] = ebaf.lat\n", "xR['lon'] = ebaf.lon\n", "xR['month'] = np.arange(1,13)\n", "xR['month'].attrs = {'units' : '1', 'long_name' : 'Month of the year'}\n", "\n", "###All-sky total\n", "\n", "R = ebaf['toa_sw_all_mon']\n", "R = R.where(R>0,0)\n", "\n", "xR['R'] = R\n", "xR['R'].attrs = {'units' : 'W m-2', 'long_name' : 'All-sky reflection'}\n", "\n", "S = ebaf['solar_mon']\n", "\n", "xR['S'] = S\n", "xR['S'].attrs = {'units' : 'W m-2', 'long_name' : 'Insolation'}\n", "\n", "###Clear-sky\n", "\n", "R_clr = ebaf['toa_sw_clr_t_mon']\n", "R_clr = R_clr.where(R_clr>0,0)\n", "\n", "xR['R_clr'] = R_clr\n", "xR['R_clr'].attrs = {'units' : 'W m-2', 'long_name' : 'Clear-sky reflection for total region'}\n", "\n", "###Cloudy-sky, i.e. Cloud Radiative Effect (CRE)\n", "\n", "R_cld = R - R_clr\n", "\n", "xR['R_cld'] = R_cld\n", "xR['R_cld'].attrs = {'units' : 'W m-2', 'long_name' : 'Cloudy-sky reflection for total region'}\n", "\n", "### Out going LW\n", "\n", "OLR = ebaf['toa_lw_all_mon']\n", "OLR = OLR.where(OLR>0,0)\n", "xR['OLR'] = OLR\n", "xR['OLR'].attrs = {'units' : 'W m-2', 'long_name' : 'Outgoing longwave radiation'}\n", "\n", "### Earth Energy Imbalance (EEI)\n", "EEI = S - R - OLR\n", "xR['EEI'] = EEI\n", "xR['EEI'].attrs = {'units' : 'W m-2', 'long_name' : 'Earth Energy Imbalance'}\n", "\n", "#Use EBAF values to help with clear-sky decomposition\n", "\n", "rsdt = ebaf['solar_mon']\n", "rsut = ebaf['toa_sw_clr_t_mon']\n", "rsds = ebaf['sfc_sw_down_clr_t_mon']\n", "rsus = ebaf['sfc_sw_up_clr_t_mon']\n", "\n", "R_aer = S*(rsdt*rsut-rsds*rsus)/(rsdt**2-rsus**2)\n", "R_aer = R_aer.where(R_aer>0,0)\n", "R_aer = R_aer.where(R_aer