def get_cat3_iwc(model, region, stat=STAT): """Returns the profiles of iwc only for CAT 3""" fwp = load.get_iwp(model, region, ice_only=False) if model.lower() != "sam": fwp = fwp[11::12] twc = load.get_twc(model, region) print(fwp.shape, twc.shape) if (fwp.shape[0] != twc.shape[0]): raise Exception("fwp and twc time not aligned: shapes", fwp.shape, twc.shape) if len(fwp.shape) == len(twc.shape): twc3 = np.where((fwp > 1e-4) & (fwp < 1e-2), twc, np.nan) elif len(fwp.shape) < len(twc.shape): fwp = fwp[:, np.newaxis] twc3 = np.where((fwp > 1e-4) & (fwp < 1e-2), twc, np.nan) else: raise Exception("fwp and twc shapes don't match", fwp.shape, twc.shape) if stat.lower() == "mean": if len(twc3.shape) < 4: # icon twc3 = np.nanmean(twc3, axis=(0, 2)) else: twc3 = np.nanmean(twc3, axis=(0, 2, 3)) elif stat.lower() == "median": if len(twc3.shape) < 4: # icon twc3 = np.nanmedian(twc3, axis=(0, 2)) else: twc3 = np.nanmedian(twc3, axis=(0, 2, 3)) else: raise Exception( "stat ({}) not defined. Try 'mean' or 'median'.".format(stat)) return twc3
def cat3_profiles(model, region): if model.lower() == "nicam": ice_only = False else: ice_only = True if model.lower() == "cccm": ds = load01deg.get_cccm(region) iwc = ds[ "iwc used in CERES radiation, avg over cloudy part of CERES footprint"].values / 1000 fwp = ds["iwp MODIS"].values / 1000 z = ds["alt"].values * 1000 # print(model, "\n", iwc.mean()) elif model.lower() == "dardar": ds = load01deg.get_dardar(region) iwc = ds["iwc"].values / 1000 fwp = ds["iwp"].values / 1000 z = ds["height"].values # print(model, "\n", iwc.mean()) else: iwc = load.get_twc(model, region).values fwp = load.get_iwp(model, region, ice_only=False).values z = load.get_levels(model, region) # print(model,"\n\t", iwc.shape, fwp.shape, z.shape) if model.lower() == "fv3" or model.lower() == "icon": fwp = fwp[11::12, np.newaxis] elif model.lower() == "nicam": fwp = fwp[11::12] else: fwp = fwp[:, np.newaxis] # print(fwp.shape, iwc.shape, z.shape) iwc3 = np.where((fwp >= 1e-4) & (fwp < 1e-2), iwc, np.nan) # print(fwp.shape, iwc.shape, iwc3.shape, z.shape) return (iwc3, z)
def get_cat_ttl_iwp(model, region): """ Returns tuple of (ttliwp1, ttliwp2, ttliwp3), the frozen water path in the 14-18km layer for each category.""" if model == "DARDAR": if region == "TWP": diwc = xr.open_dataset(ap.DARDAR_TWP)['iwc'] iwp = xr.open_dataset(ap.DARDAR_TWP)['iwp'] elif region == "NAU": diwc = xr.open_dataset(ap.DARDAR_NAU)['iwc'] iwp = xr.open_dataset(ap.DARDAR_NAU)['iwp'] else: diwc = xr.open_dataset(ap.DARDAR_SHL)['iwc'] iwp = xr.open_dataset(ap.DARDAR_SHL)['iwp'] ttliwp = util.int_wrt_alt( diwc.values[:, np.argmin(abs(diwc.height.values - 18000)):np. argmin(abs(diwc.height.values - 14000))], diwc.height.values[np.argmin(abs(diwc.height.values - 18000)):np. argmin(abs(diwc.height.values - 14000))]) del diwc print(iwp.shape, ttliwp.shape) ttliwp1 = np.where((iwp >= 1000), ttliwp, np.nan) ttliwp2 = np.where((iwp >= 10), ttliwp, np.nan) ttliwp3 = np.where((iwp >= 0.1) & (iwp < 10), ttliwp, np.nan) del iwp else: ttliwp = load.get_ttliwp(model, region) iwp = load.get_iwp(model, region, ice_only=False) print(ttliwp.shape, iwp.shape) if model.lower() == "nicam": iwp = iwp[1::12, 0, :, :] if model.lower() == "icon": iwp = iwp[1::12, :] elif model.lower() == "fv3": iwp = iwp[1::12, :, :] print(iwp.shape, ttliwp.shape) ttliwp1 = np.where((iwp >= 1.0), ttliwp, np.nan) ttliwp2 = np.where((iwp >= 1e-2) & (iwp < 1.0), ttliwp, np.nan) ttliwp3 = np.where((iwp >= 1e-4) & (iwp < 1e-2), ttliwp, np.nan) del iwp print("returning ttliwp per category for ", model, region) return (ttliwp1, ttliwp2, ttliwp3)
def get_isottlci(model, region, thres=0.1): """ Saves the clear sky olr, alb, lw and sw cre to a csv file for both the mean and median values of isolated TTL cirrus columns. Parameters: -thres (f) : clear-sky threshold in g/m2 -model (str): model acronym -region(str): region acronym """ thres = thres # to kg/m2 olr, alb = load.get_olr_alb(model, region) time = np.arange(3,alb.shape[0]*3+3,3)%24 if model.lower()=="nicam": time = time[:, np.newaxis, np.newaxis, np.newaxis] elif model.lower()=="icon": time = time[:, np.newaxis] else: time = np.array(time)[:, np.newaxis, np.newaxis] if region.lower()=="twp": alb = alb.where(time>=20) olr = olr.where(time>=20) elif region.lower()=="nau": alb = alb.where((time>=22)|(time<=2)) olr = olr.where((time>=22)|(time<=2)) else: alb = alb.where((time>=11)&(time<=15)) olr = olr.where((time>=11)&(time<=15)) fwp = load.get_iwp(model, region, ice_only=False)*1000 ttliwp = load.get_ttliwp(model, region)*1000 lwp = load.get_lwp(model, region, rain=False)*1000 if model.lower()!="sam": fwp = fwp[11::12] lwp = lwp[11::12] print(olr.shape, fwp.shape, lwp.shape, alb.shape) olrcs = load.get_clearskyolr(model, region, fwp, lwp) albcs = load.get_clearskyalb(model, region, fwp, lwp) print(olr.shape, olrcs.shape, fwp.shape, lwp.shape, alb.shape, albcs.shape) if model.lower()=="nicam": fwp = fwp[:,0] lwp = lwp[:,0] olr = olr[:,0] alb = alb[:,0] albcs = albcs[:,0] olrcs = olrcs[:,0] # get isolated ttl ci print("fwp and ttliwp shape", fwp.shape, ttliwp.shape) wp_below14km = (fwp.values - ttliwp.values) + lwp.values del fwp, lwp print("got wp below 14km") if region.lower()=="shl": solar_const = 435.2760211 else: solar_const = 413.2335274 isottlci_mask = np.where((wp_below14km<thres)&(ttliwp>=thres), True, False) olr_iso = np.where(isottlci_mask, olr, np.nan) del olr alb_iso = np.where(isottlci_mask, alb, np.nan) del alb freq = np.sum(isottlci_mask)/len(isottlci_mask.flatten()) print("freq", model, region, freq, np.sum(isottlci_mask), len(isottlci_mask.flatten())) lwcre_mean = np.nanmean(olrcs-olr_iso) swcre_mean = np.nanmean(albcs-alb_iso)*solar_const df_mean = pd.read_csv("../tables/iso_ttl_ci_all_mean.csv", index_col=0) print("mean",[np.nanmean(olr_iso), np.nanmean(alb_iso), lwcre_mean, swcre_mean]) df_mean[model+"_"+region] = [freq, np.nanmean(olr_iso), np.nanmean(alb_iso), lwcre_mean, swcre_mean] df_mean.to_csv("../tables/iso_ttl_ci_all_mean.csv") lwcre_med = np.nanmedian(olrcs-olr_iso) swcre_med = np.nanmedian(albcs-alb_iso)*solar_const df_med = pd.read_csv("../tables/iso_ttl_ci_all_median.csv", index_col=0) print("median",[np.nanmedian(olr_iso), np.nanmedian(alb_iso), lwcre_med, swcre_med]) df_med[model+"_"+region] = [freq, np.nanmedian(olr_iso), np.nanmedian(alb_iso), lwcre_med, swcre_med] df_med.to_csv("../tables/iso_ttl_ci_all_median.csv") print("...done.") return
def get_cat_lw_sw(model, region, save=True, mean=False): if model.lower()=="cccm": ds = load01deg.get_cccm(region) olr = ds["Outgoing LW radiation at TOA"] swu = ds["Outgoing SW radiation at TOA"] swd = ds["Incoming SW radiation at TOA"] alb = swu/swd.values olrcs = ds["Clear-sky outgoing LW radiation at TOA"] swucs = ds["Clear-sky outgoing SW radiation at TOA"] albcs = swucs/swd.values fwp = ds["iwp MODIS"] lwp = ds["lwp MODIS"] else: olr, alb = load.get_olr_alb(model, region) fwp = load.get_iwp(model, region, ice_only=False)*1000 lwp = load.get_lwp(model, region, rain=False)*1000 if model.lower()!="sam": fwp = fwp[11::12] lwp = lwp[11::12] print(olr.shape, fwp.shape, lwp.shape, alb.shape) olrcs = load.get_clearskyolr(model, region, fwp, lwp) albcs = load.get_clearskyalb(model, region, fwp, lwp) if mean: olrcs = np.nanmean(olrcs, axis=0) albcs = np.nanmean(albcs, axis=0) else: olrcs = np.nanmedian(olrcs, axis=0) albcs = np.nanmedian(albcs, axis=0) print(olr.shape, olrcs.shape, fwp.shape, lwp.shape, alb.shape, albcs.shape) # cat mean values (olr, lwcre, alb, swcre) thres1 = 1000 thres2 = 10 thres3 = 0.1 if mean: # cat 1 olr1 = np.nanmean(np.where(fwp>thres1, olr, np.nan)) lwcre1 = np.nanmean(olrcs-(np.where(fwp>thres1, olr, np.nan))) alb1 = np.nanmean(np.where(fwp>thres1, alb, np.nan)) swcre1 = np.nanmean(albcs-(np.where(fwp>thres1, alb, np.nan))) # cat 2 olr2 = np.nanmean(np.where((fwp>thres2)&(fwp<=thres1), olr, np.nan)) lwcre2= np.nanmean(olrcs-(np.where((fwp>thres2)&(fwp<=thres1), olr, np.nan))) alb2 = np.nanmean(np.where((fwp>thres2)&(fwp<=thres1), alb, np.nan)) swcre2 = np.nanmean(albcs-(np.where((fwp>thres2)&(fwp<=thres1), alb, np.nan))) # cat 3 olr3 = np.nanmean(np.where((fwp>thres3)&(fwp<=thres2), olr, np.nan)) lwcre3= np.nanmean(olrcs-(np.where((fwp>thres3)&(fwp<=thres2), olr, np.nan))) alb3 = np.nanmean(np.where((fwp>thres3)&(fwp<=thres2), alb, np.nan)) swcre3 = np.nanmean(albcs-(np.where((fwp>thres3)&(fwp<=thres2), alb, np.nan))) # clear sky olr4 = np.nanmean(olrcs) alb4 = np.nanmean(albcs) else: # cat 1 olr1 = np.nanmedian(np.where(fwp>thres1, olr, np.nan)) lwcre1 = np.nanmedian(olrcs-(np.where(fwp>thres1, olr, np.nan))) alb1 = np.nanmedian(np.where(fwp>thres1, alb, np.nan)) swcre1 = np.nanmedian(albcs-(np.where(fwp>thres1, alb, np.nan))) # cat 2 olr2 = np.nanmedian(np.where((fwp>thres2)&(fwp<=thres1), olr, np.nan)) lwcre2= np.nanmedian(olrcs-(np.where((fwp>thres2)&(fwp<=thres1), olr, np.nan))) alb2 = np.nanmedian(np.where((fwp>thres2)&(fwp<=thres1), alb, np.nan)) swcre2 = np.nanmedian(albcs-(np.where((fwp>thres2)&(fwp<=thres1), alb, np.nan))) # cat 3 olr3 = np.nanmedian(np.where((fwp>thres3)&(fwp<=thres2), olr, np.nan)) lwcre3= np.nanmedian(olrcs-(np.where((fwp>thres3)&(fwp<=thres2), olr, np.nan))) alb3 = np.nanmedian(np.where((fwp>thres3)&(fwp<=thres2), alb, np.nan)) swcre3 = np.nanmedian(albcs-(np.where((fwp>thres3)&(fwp<=thres2), alb, np.nan))) # clear sky olr4 = np.nanmedian(olrcs) alb4 = np.nanmedian(albcs) if region.lower()=="shl": solar_const = 435.2760211 else: solar_const = 413.2335274 olr_list = np.array([olr1, olr2, olr3, olr4]) alb_list = np.array([alb1, alb2, alb3, alb4]) lw_list = np.array([lwcre1, lwcre2, lwcre3, 0]) sw_list = np.array([swcre1, swcre2, swcre3, 0])*solar_const df = pd.DataFrame(np.array([olr_list, alb_list, lw_list, sw_list]).T, columns=["olr","alb","lwcre","swcre"], index=["CAT1","CAT2","CAT3","CS"]) print(df) if save: df.to_csv("../tables/mean_{}_{}.csv".format(model, region)) print("saved.") return df
# return ret[n - 1:] / n if len(a)%3==1: a = a[:-1] elif len(a)%3==2: a = a[:-2] print(len(a)%3) avg = (a[0::3]+a[1::3]+a[2::3])/3 return avg # load all fwp obs = "DARDAR" print("Getting frozen hydrometeors") # giwp = util.iwp_wrt_pres("GEOS", REGION, hydro_type=hydro_type, geos_graupel=True) print("geos zeros until we get new data") iiwp_twp = load.get_iwp("ICON", "TWP", ice_only=False).values iiwp_shl = load.get_iwp("ICON", "SHL", ice_only=False).values iiwp_nau = load.get_iwp("ICON", "NAU", ice_only=False).values print("loaded icon") fiwp_twp = load.get_iwp("FV3", "TWP", ice_only=False).values fiwp_shl = load.get_iwp("FV3", "SHL", ice_only=False).values fiwp_nau = load.get_iwp("FV3", "NAU", ice_only=False).values print("loaded fv3") niwp_twp = load.get_iwp("NICAM", "TWP", ice_only=False).values niwp_shl = load.get_iwp("NICAM", "SHL", ice_only=False).values niwp_nau = load.get_iwp("NICAM", "NAU", ice_only=False).values print("loaded nicam") siwp_twp = load.get_iwp("SAM", "TWP", ice_only=False) siwp_shl = load.get_iwp("SAM", "SHL", ice_only=False) siwp_nau = load.get_iwp("SAM", "NAU", ice_only=False) sno_twp = siwp_twp.count().values
c1s = np.nanmedian(c1s) c2s = np.nanmedian(c2s) c3s = np.nanmedian(c3s) c4s = np.nanmedian(c4s) c1n = np.nanmedian(c1n) c2n = np.nanmedian(c2n) c3n = np.nanmedian(c3n) c4n = np.nanmedian(c4n) print("... done") # %% # load sam cat1 = 1 cat2 = 1e-2 cat3 = 1e-4 siwpt = load.get_iwp("SAM", "TWP", ice_only=False) siwps = load.get_iwp("SAM", "SHL", ice_only=False) siwpn = load.get_iwp("SAM", "NAU", ice_only=False) print("sam...") s1t = np.nanmedian(np.where(siwpt >= cat1, siwpt, np.nan)) s2t = np.nanmedian(np.where((siwpt >= cat2) & (siwpt < cat1), siwpt, np.nan)) s3t = np.nanmedian(np.where((siwpt >= cat3) & (siwpt < cat2), siwpt, np.nan)) s4t = np.nanmedian(np.where((siwpt < cat3), siwpt, np.nan)) s1s = np.nanmedian(np.where(siwps >= cat1, siwps, np.nan)) s2s = np.nanmedian(np.where((siwps >= cat2) & (siwps < cat1), siwps, np.nan)) s3s = np.nanmedian(np.where((siwps >= cat3) & (siwps < cat2), siwps, np.nan)) s4s = np.nanmedian(np.where((siwps < cat3), siwps, np.nan)) s1n = np.nanmedian(np.where(siwpn >= cat1, siwpn, np.nan)) s2n = np.nanmedian(np.where((siwpn >= cat2) & (siwpn < cat1), siwpn, np.nan)) s3n = np.nanmedian(np.where((siwpn >= cat3) & (siwpn < cat2), siwpn, np.nan)) s4n = np.nanmedian(np.where((siwpn < cat3), siwpn, np.nan))
#!/usr/bin/env python """ fig03_nicam_iwc_cat_profiles.py author: sami turbeville """ import matplotlib.pyplot as plt import numpy as np import xarray as xr from utility import load, util, analysis_parameters as ap MODEL = "NICAM" iwp = load.get_iwp(MODEL, "TWP").values[11::12] # load one at a time to get category mean print("... categorize ice ...") iwc = xr.open_dataarray(ap.NICAM+"NICAM_iwc_TWP.nc")[16:] print(iwp.shape, iwc.shape) iwc1 = iwc.where(iwp>=1).mean(axis=(0,2,3)) iwc2 = iwc.where((iwp<1)&(iwp>=1e-2)).mean(axis=(0,2,3)) iwc3 = iwc.where((iwp<1e-2)&(iwp>=1e-4)).mean(axis=(0,2,3)) del iwc print("... categorize snow ...") swc = xr.open_dataarray(ap.NICAM+"NICAM_swc_TWP.nc")[16:] swc1 = swc.where(iwp>=1).mean(axis=(0,2,3)) swc2 = swc.where((iwp<1)&(iwp>=1e-2)).mean(axis=(0,2,3)) swc3 = swc.where((iwp<1e-2)&(iwp>=1e-4)).mean(axis=(0,2,3)) del swc print("... categorize graupel ...") gwc = xr.open_dataarray(ap.NICAM+"NICAM_gwc_TWP.nc")[16:] gwc1 = gwc.where(iwp>=1).mean(axis=(0,2,3)) gwc2 = gwc.where((iwp<1)&(iwp>=1e-2)).mean(axis=(0,2,3)) gwc3 = gwc.where((iwp<1e-2)&(iwp>=1e-4)).mean(axis=(0,2,3))
print( "skipping observed IWV until I can figure out how to integrate wv mixing ratio" ) # %% # define cat limits cat1 = 1 cat2 = 1e-2 cat3 = 1e-4 # %% # load icon iiwvt = load.get_iwv("ICON", "TWP") iiwvs = load.get_iwv("ICON", "SHL") iiwvn = load.get_iwv("ICON", "NAU") ifwpt = load.get_iwp("ICON", "TWP", ice_only=False).values[::12] ifwps = load.get_iwp("ICON", "SHL", ice_only=False).values[::12] ifwpn = load.get_iwp("ICON", "NAU", ice_only=False).values[::12] print("icon...") i1t = np.nanmedian(np.where(ifwpt >= cat1, iiwvt, np.nan)) i2t = np.nanmedian(np.where((ifwpt >= cat2) & (ifwpt < cat1), iiwvt, np.nan)) i3t = np.nanmedian(np.where((ifwpt >= cat3) & (ifwpt < cat2), iiwvt, np.nan)) i4t = np.nanmedian(np.where((ifwpt < cat3), iiwvt, np.nan)) i1s = np.nanmedian(np.where(ifwps >= cat1, iiwvs, np.nan)) i2s = np.nanmedian(np.where((ifwps >= cat2) & (ifwps < cat1), iiwvs, np.nan)) i3s = np.nanmedian(np.where((ifwps >= cat3) & (ifwps < cat2), iiwvs, np.nan)) i4s = np.nanmedian(np.where((ifwps < cat3), iiwvs, np.nan)) i1n = np.nanmedian(np.where(ifwpn >= cat1, iiwvn, np.nan)) i2n = np.nanmedian(np.where((ifwpn >= cat2) & (ifwpn < cat1), iiwvn, np.nan)) i3n = np.nanmedian(np.where((ifwpn >= cat3) & (ifwpn < cat2), iiwvn, np.nan)) i4n = np.nanmedian(np.where((ifwpn < cat3), iiwvn, np.nan))
import numpy as np import matplotlib.pyplot as plt import pandas as pd from scipy import stats from utility import load, load01deg REGION = "NAU" # %% c_olrcs = load01deg.get_cccm(REGION)["Clear-sky outgoing LW radiation at TOA"] c_swucs = load01deg.get_cccm(REGION)["Clear-sky outgoing SW radiation at TOA"] c_swd = load01deg.get_cccm(REGION)["Incoming SW radiation at TOA"] c_albcs = c_swucs / c_swd del c_swucs, c_swd fwp = load.get_iwp("NICAM", REGION, ice_only=False) lwp = load.get_lwp("NICAM", REGION, rain=False) fwp = fwp[11::12] lwp = lwp[11::12] n_olrcs = load.get_clearskyolr("NICAM", REGION, fwp, lwp) n_albcs = load.get_clearskyalb("NICAM", REGION, fwp, lwp) n_olrcs = n_olrcs[:, 0] n_albcs = n_albcs[:, 0] fwp = load.get_iwp("FV3", REGION, ice_only=False) lwp = load.get_lwp("FV3", REGION, rain=False) fwp = fwp[11::12] lwp = lwp[11::12] f_olrcs = load.get_clearskyolr("FV3", REGION, fwp, lwp) f_albcs = load.get_clearskyalb("FV3", REGION, fwp, lwp) fwp = load.get_iwp("ICON", REGION, ice_only=False) lwp = load.get_lwp("ICON", REGION, rain=False)