<filename>xanalysis_st_sph.py
import numpy as np
import pandas as pd
import xarray as xr
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import os
import itertools

if __name__ == "__main__":

    # # Initialization

    # matplotlib.rcParams.update({'font.size': 12, 'text.usetex': True})

    # gParams

    (Lx, Ly, Lz) = (21, 21, 21)
    (dx, dy, dz) = (0.375, 0.375, 0.375)

    NGridPoints_cart = (1 + 2 * Lx / dx) * (1 + 2 * Ly / dy) * (1 + 2 * Lz / dz)

    datapath = '/home/kis/Dropbox/VariationalResearch/HarvardOdyssey/genPol_data/NGridPoints_{:.2E}'.format(NGridPoints_cart)
    # datapath = '/media/kis/Storage/Dropbox/VariationalResearch/HarvardOdyssey/genPol_data/NGridPoints_{:.2E}'.format(NGridPoints_cart)
    innerdatapath = datapath + '/steadystate_spherical'

    # # Concatenate Individual Datasets

    ds_list = []; P_list = []; aIBi_list = []; mI_list = []
    for ind, filename in enumerate(os.listdir(innerdatapath)):
        if filename == 'quench_st_Dataset_sph.nc':
            continue
        print(filename)
        with xr.open_dataset(innerdatapath + '/' + filename) as dsf:
            ds = dsf.compute()
            ds_list.append(ds)
            P_list.append(ds.attrs['P'])
            aIBi_list.append(ds.attrs['aIBi'])
            mI_list.append(ds.attrs['mI'])

    s = sorted(zip(aIBi_list, P_list, ds_list))
    g = itertools.groupby(s, key=lambda x: x[0])

    aIBi_keys = []; aIBi_groups = []; aIBi_ds_list = []
    for key, group in g:
        aIBi_keys.append(key)
        aIBi_groups.append(list(group))

    for ind, group in enumerate(aIBi_groups):
        aIBi = aIBi_keys[ind]
        _, P_list_temp, ds_list_temp = zip(*group)
        ds_temp = xr.concat(ds_list_temp, pd.Index(P_list_temp, name='P'))
        aIBi_ds_list.append(ds_temp)

    ds_tot = xr.concat(aIBi_ds_list, pd.Index(aIBi_keys, name='aIBi'))
    del(ds_tot.attrs['P']); del(ds_tot.attrs['aIBi']); del(ds_tot.attrs['nu']); del(ds_tot.attrs['gIB'])
    ds_tot.to_netcdf(innerdatapath + '/quench_st_Dataset_sph.nc')

    # # Analysis of Total Dataset

    # qds = xr.open_dataset(innerdatapath + '/quench_st_Dataset_sph.nc')
    # qds['NB'].sel(P=0.5).plot()
    # qds['NB'].isel(t=-1).sel(aIBi=-5).plot()
    # qds_St.isel(t=-1).sel(aIBi=-5).plot()
    # plt.show()

<filename>xanalysis_st_sph.py
import numpy as np
import pandas as pd
import xarray as xr
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import os
import itertools

if __name__ == "__main__":

    # # Initialization

    # matplotlib.rcParams.update({'font.size': 12, 'text.usetex': True})

    # gParams

    (Lx, Ly, Lz) = (21, 21, 21)
    (dx, dy, dz) = (0.375, 0.375, 0.375)

    NGridPoints_cart = (1 + 2 * Lx / dx) * (1 + 2 * Ly / dy) * (1 + 2 * Lz / dz)

    datapath = '/home/kis/Dropbox/VariationalResearch/HarvardOdyssey/genPol_data/NGridPoints_{:.2E}'.format(NGridPoints_cart)
    # datapath = '/media/kis/Storage/Dropbox/VariationalResearch/HarvardOdyssey/genPol_data/NGridPoints_{:.2E}'.format(NGridPoints_cart)
    innerdatapath = datapath + '/steadystate_spherical'

    # # Concatenate Individual Datasets

    ds_list = []; P_list = []; aIBi_list = []; mI_list = []
    for ind, filename in enumerate(os.listdir(innerdatapath)):
        if filename == 'quench_st_Dataset_sph.nc':
            continue
        print(filename)
        with xr.open_dataset(innerdatapath + '/' + filename) as dsf:
            ds = dsf.compute()
            ds_list.append(ds)
            P_list.append(ds.attrs['P'])
            aIBi_list.append(ds.attrs['aIBi'])
            mI_list.append(ds.attrs['mI'])

    s = sorted(zip(aIBi_list, P_list, ds_list))
    g = itertools.groupby(s, key=lambda x: x[0])

    aIBi_keys = []; aIBi_groups = []; aIBi_ds_list = []
    for key, group in g:
        aIBi_keys.append(key)
        aIBi_groups.append(list(group))

    for ind, group in enumerate(aIBi_groups):
        aIBi = aIBi_keys[ind]
        _, P_list_temp, ds_list_temp = zip(*group)
        ds_temp = xr.concat(ds_list_temp, pd.Index(P_list_temp, name='P'))
        aIBi_ds_list.append(ds_temp)

    ds_tot = xr.concat(aIBi_ds_list, pd.Index(aIBi_keys, name='aIBi'))
    del(ds_tot.attrs['P']); del(ds_tot.attrs['aIBi']); del(ds_tot.attrs['nu']); del(ds_tot.attrs['gIB'])
    ds_tot.to_netcdf(innerdatapath + '/quench_st_Dataset_sph.nc')

    # # Analysis of Total Dataset

    # qds = xr.open_dataset(innerdatapath + '/quench_st_Dataset_sph.nc')
    # qds['NB'].sel(P=0.5).plot()
    # qds['NB'].isel(t=-1).sel(aIBi=-5).plot()
    # qds_St.isel(t=-1).sel(aIBi=-5).plot()
    # plt.show()

# # Initialization # matplotlib.rcParams.update({'font.size': 12, 'text.usetex': True}) # gParams # datapath = '/media/kis/Storage/Dropbox/VariationalResearch/HarvardOdyssey/genPol_data/NGridPoints_{:.2E}'.format(NGridPoints_cart) # # Concatenate Individual Datasets # # Analysis of Total Dataset # qds = xr.open_dataset(innerdatapath + '/quench_st_Dataset_sph.nc') # qds['NB'].sel(P=0.5).plot() # qds['NB'].isel(t=-1).sel(aIBi=-5).plot() # qds_St.isel(t=-1).sel(aIBi=-5).plot() # plt.show()