def read_icnctraj_sub(set_name, time_pt, clams, time0, timef):
    basedir = '/work/bb1018/b380873/traj_output/' + set_name + '/'
    if clams == True:
        start_str = 'cirrus_tst'
        end_str = '_trim_extract_clams.nc'
        rho = []
        icnc = []
        t = []
        rhi = []
        for file_id in np.arange(1, 27):
            filename = start_str + general_prefix(
                time_pt,
                8) + '_p' + traj_prefix(file_id) + str(file_id) + end_str
            traj = xr.open_dataset(basedir + filename)
            vals = traj['RHO'].sel(time=slice(time0, timef)).values.flatten()
            rho.extend(vals)
            vals = (traj['ICN_hom'] + traj['ICN_het'] + traj['ICN_pre']).sel(
                time=slice(time0, timef)).values.flatten()
            icnc.extend(vals)
            vals = traj['T'].sel(time=slice(time0, timef)).values.flatten()
            t.extend(vals)
            vals = traj['RHI'].sel(time=slice(time0, timef)).values.flatten()
            rhi.extend(vals)
    else:
        start_str = 'traj_tst'
        end_str = '_trim_extract_dt.nc'
        rho = []
        icnc = []
        t = []
        rhi = []
        for file_id in np.arange(1, 27):
            filename = start_str + general_prefix(
                time_pt,
                8) + '_p' + traj_prefix(file_id) + str(file_id) + end_str
            traj = xr.open_dataset(basedir + filename)
            vals = traj['rho'].sel(time=slice(time0, timef)).values.flatten()
            rho.extend(vals)
            vals = traj['qni'].sel(time=slice(time0, timef)).values.flatten()
            icnc.extend(vals)
            vals = traj['t'].sel(time=slice(time0, timef)).values.flatten()
            t.extend(vals)
            p = traj['p'].sel(time=slice(time0, timef)).values.flatten()
            qv = traj['qv'].sel(time=slice(time0, timef)).values.flatten()
            vals = calc_RHi(vals, p, qv)
            rhi.extend(vals)
    rho = np.array(rho)
    icnc = np.array(icnc)
    t = np.array(t)
    rhi = np.array(rhi)

    # Filter out instances where the ICNC value is not 0 or nan
    icnc, t, rhi = filter_icnc_temp(icnc, rho, t, rhi)
    print(icnc.shape, t.shape, rhi.shape)
    print(np.nanmin(np.log10(icnc)), np.nanmean(np.log10(icnc)),
          np.nanmax(np.log10(icnc)))
    print(np.nanmin(rhi), np.nanmean(rhi), np.nanmax(rhi))
    return t, rhi, icnc
def read_qseditraj(set_name, time_pt, clams):
    basedir = '/work/bb1018/b380873/traj_output/' + set_name + '/'
    if clams == True:
        start_str = 'cirrus_tst'
        end_str = '_trim_extract_clams.nc'
        qsedi = []
        qsedo = []
        t = []
        rhi = []
        for file_id in np.arange(1, 27):
            filename = start_str + general_prefix(
                time_pt,
                8) + '_p' + traj_prefix(file_id) + str(file_id) + end_str
            traj = xr.open_dataset(basedir + filename)
            vals = 10**6 * traj['qsedi'].values.flatten()
            qsedi.extend(vals)
            vals = 10**7 * traj['qsedo'].values.flatten()
            qsedo.extend(vals)
            vals = traj['T'].values.flatten()
            t.extend(vals)
            vals = traj['RHI'].values.flatten()
            rhi.extend(vals)
    else:
        start_str = 'traj_tst'
        end_str = '_trim_extract.nc'
        qsedi = []
        qsedo = []
        t = []
        rhi = []
        for file_id in np.arange(1, 27):
            filename = start_str + general_prefix(
                time_pt,
                8) + '_p' + traj_prefix(file_id) + str(file_id) + end_str
            traj = xr.open_dataset(basedir + filename)
            vals = 10**6 * traj['qsedi'].values.flatten()
            qsedi.extend(vals)
            vals = 10**6 * traj['qsedo'].values.flatten()
            qsedo.extend(vals)
            vals = traj['t'].values.flatten()
            t.extend(vals)
            p = traj['p'].values.flatten()
            qv = traj['qv'].values.flatten()
            vals = calc_RHi(vals, p, qv)
            rhi.extend(vals)
    qsedi = np.array(iwc)
    t = np.array(t)
    rhi = np.array(rhi)

    # Filter out instances where the IWC value is not 0 or nan
    iwc, t, rhi = filter_iwc_temp(iwc, t, rhi)
    print(qsedi.shape, t.shape, rhi.shape)
    print(np.nanmin(np.log10(qsedi)), np.nanmean(np.log10(qsedi)),
          np.nanmax(np.log10(qsedi)))
    print(np.nanmin(rhi), np.nanmean(rhi), np.nanmax(rhi))
    return t, rhi, qsedi
def read_icnctraj_all(set_name, time_pt):
    basedir = '/work/bb1018/b380873/traj_output/' + set_name + '/'
    start_str = 'traj_tst'
    end_str = '.nc'
    rho = []
    icnc = []
    t = []
    rhi = []
    for file_id in np.arange(1, 6):
        filename = start_str + general_prefix(
            time_pt, 8) + '_p' + traj_prefix(file_id) + str(file_id) + end_str
        traj = xr.open_dataset(basedir + filename)
        vals = traj['rho'].values.flatten()
        rho.extend(vals)
        vals = traj['qni'].values.flatten()
        icnc.extend(vals)
        vals = traj['t'].values.flatten()
        t.extend(vals)
        p = traj['p'].values.flatten()
        qv = traj['qv'].values.flatten()
        vals = calc_RHi(vals, p, qv)
        rhi.extend(vals)
    rho = np.array(rho)
    icnc = np.array(icnc)
    t = np.array(t)
    rhi = np.array(rhi)

    # Filter out instances where the ICNC value is not 0 or nan
    icnc, t, rhi = filter_icnc_temp(icnc, rho, t, rhi)
    print(icnc.shape, t.shape, rhi.shape)
    print(np.nanmin(np.log10(icnc)), np.nanmean(np.log10(icnc)),
          np.nanmax(np.log10(icnc)))
    print(np.nanmin(rhi), np.nanmean(rhi), np.nanmax(rhi))
    return t, rhi, icnc
def read_iwctraj_all(set_name, time_pt, outflow):
    basedir = '/work/bb1018/b380873/traj_output/' + set_name + '/'
    start_str = 'traj_tst'
    end_str = '.nc'
    iwc = []
    t = []
    rhi = []
    for file_id in np.arange(1, 6):
        filename = start_str + general_prefix(
            time_pt, 8) + '_p' + traj_prefix(file_id) + str(file_id) + end_str
        traj = xr.open_dataset(basedir + filename)
        vals = 10**6 * traj['qi'].values.flatten()
        iwc.extend(vals)
        vals = traj['t'].values.flatten()
        t.extend(vals)
        p = traj['p'].values.flatten()
        qv = traj['qv'].values.flatten()
        vals = calc_RHi(vals, p, qv)
        rhi.extend(vals)
    iwc = np.array(iwc)
    t = np.array(t)
    rhi = np.array(rhi)

    # Filter out instances where the IWC value is not 0 or nan
    if outflow == True:
        iwc, t, rhi = filter_iwc_temp_outflow(iwc, t, rhi)
    else:
        iwc, t, rhi = filter_iwc_temp_insitu(iwc, t, rhi)
    print(iwc.shape, t.shape, rhi.shape)
    print(np.nanmin(np.log10(iwc)), np.nanmean(np.log10(iwc)),
          np.nanmax(np.log10(iwc)))
    print(np.nanmin(rhi), np.nanmean(rhi), np.nanmax(rhi))
    return t, rhi, iwc
def time_to_datetime(set_name, time_pt, clams):
    basedir = '/work/bb1018/b380873/traj_output/' + set_name + '/'
    start_str = 'traj_tst'
    end_str = '_trim_extract.nc'
    base_time = datetime(2017, 8, 6, 0, 0)
    traj = xr.open_dataset(basedir + start_str + general_prefix(time_pt, 8) +
                           '_p001' + end_str)
    traj_times = traj['rtime']
    real_times = np.array(
        [base_time + timedelta(seconds=int(t.values)) for t in traj_times])
    for file_id in np.arange(1, 31):
        print(file_id)
        traj = xr.open_dataset(basedir + start_str +
                               general_prefix(time_pt, 8) + '_p' +
                               traj_prefix(file_id) + str(file_id) + end_str)
        traj['time'] = real_times
        traj.to_netcdf(basedir + start_str + general_prefix(time_pt, 8) +
                       '_p' + traj_prefix(file_id) + str(file_id) +
                       '_trim_extract_dt.nc')