Example #1
0
import sys
import matplotlib.pyplot as plt
from matplotlib import ticker, cm  #for log scale
sys.path.insert(0, pwd)
# import copy

import athena_read as ath
import h5py
import hdf5_parser

#%%

#
# data = ath.athdf(filename)
rawhdf = h5py.File(filename, 'r')
out = hdf5_parser.setup(filename)

#%%
### failed reshaping attempts
X = np.reshape(out['posXarray'], [512, 512], order='C')
Y = np.reshape(out['posYarray'], [512, 512], order='C')

thingX = [X[5, 5], X[6, 5], X[5, 6], X[4, 5], X[5, 4]]
thingY = [Y[5, 5], Y[6, 5], Y[5, 6], Y[4, 5], Y[5, 4]]

plt.plot(X, Y)

# plt.plot(thingX, thingY)

#%%
### Math the reshaping
    PyFx = np.diff(magX, n=1, axis = 0) #shape (511, 512)
    return(PxFy[1:] - PyFx[:,1:]) #reselect to rehape

def EZlabels(title, timestamp, savefile = ""):
    if savefile == "": savefile = title
    plt.colorbar(label = title + r" ($\frac{G}{cm} = \frac{1}{10^{-7}} \frac{\mu G}{kpc}$)")
    plt.title("Mag "+title+" (t="+timestamp+")")
    plt.xlabel("x position (cm)")
    plt.ylabel("y position (cm)")
    plt.savefig(pwd + "/Plots/"+savefile+timestamp+".png")
#%% Calculate inital curl div

#import data
timestamp = "0000"
filename = "/Users/bwong/Downloads/URS_Data/m2_c1_16x8_64x64/More Plot Files/parkerCRs_hdf5_plt_cnt_" + timestamp
newOut = hdf5_parser.setup(filename, format = "cartesian")
magY = newOut['magYarray']
magX = newOut['magXarray']
magInit = np.sqrt(pow(magX, 2), pow(magY, 2))[1:, 1:]

divInit = calcDiv(magX, magY)
curlInit = calcCurl(magX, magY)

#load coordinates; you only need to do this once
x = newOut['posXarray']
y = newOut['posYarray']
#%% Select time stamp and calculate curl div

#import data
timestamp = "0080"
filename = "/Users/bwong/Downloads/URS_Data/m2_c1_16x8_64x64/More Plot Files/parkerCRs_hdf5_plt_cnt_" + timestamp
Example #3
0
         label='classical_energy',
         linestyle=':',
         lw=3)
plt.plot(f['t'], f['magnetic_energy'], label='magnetic_energy')
plt.legend()

#%%
###############################
#Calculate total mass SELECTION
###############################

startTime = time.time()
timeStamps = []
mass = []

out = hdf5_parser.setup(filename)
ymax = max(out['posYarray'])
ymin = min(out['posYarray'])
TFselect = np.logical_and(out['posYarray'] != ymax, out['posYarray'] != ymin)

for fileName in os.listdir(filedirectory):
    if (fileName.startswith("parkerCRs")):
        #Start
        print(fileName)
        timeStamp = fileName[len(fileName) - 4:len(fileName)]
        timeStamps.append(int(timeStamp))
        out = hdf5_parser.setup(filedirectory + "/" + fileName)
        ds = yt.load(filedirectory + "/" + fileName)
        ad = ds.all_data()
        mass.append(sum(ad[('gas', 'cell_mass')][TFselect]))
print()
Example #4
0
                   'temp',
                   data_source=dsSelect,
                   center=(np.sum([bounds['xmin'], bounds['xmax']]) / 2,
                           np.sum([bounds['ymin'], bounds['ymax']]) / 2, 0))
# slc.annotate_velocity(factor=16)
# slc.annotate_streamlines('magnetic_field_x','magnetic_field_y',density=3,plot_args={'linewidth':0.5,'color':'r'})
slc.annotate_title("Temp clumps, temp>10^4K, min_cells = 20")
slc.set_width(
    max([
        abs(bounds['xmax'] - bounds['xmin']),
        abs(bounds['ymax'] - bounds['ymin'])
    ]))
slc.annotate_clumps(leaf_clumps)
slc.save(pwd + "/Plots/clumps")

#%%
out = hdf5_parser.setup(filename)
z = out['densityArray']
lev = np.logspace(np.log10(z.min()), np.log10(z.max()), num=1000)
# plt.title("Temp (\N{DEGREE SIGN}K)")
# plt.close()
plt.clf()
fig, ax = plt.subplots(1)
ax[0].tricontourf(out['posXarray'],
                  out['posYarray'],
                  z,
                  locator=ticker.LogLocator(),
                  levels=lev)  #good for irregular Z values
ax[0].title("Density (g/$cm^3$)")
cbar = plt.colorbar(extend='both', orientation='vertical')
cbar.ax.set_yticklabels(lev)
Example #5
0
## returns the indices right before a sign flip
## i.e. findSignFlips([-3, -1, 1, 3, -2]) returns [1, 3]
def findSignFlips(arrayIN):
    result = []
    prevNum = arrayIN[0]
    for index in range(0, len(arrayIN)):
        if prevNum < 0 and arrayIN[index] > 0: result.append(index - 1)
        elif prevNum > 0 and arrayIN[index] < 0: result.append(index - 1)
        prevNum = arrayIN[index]
    return np.array(result)


#%%
### File setup
out = hdf5_parser.setup(filename)
posXarray = out["posXarray"]
posYarray = out["posYarray"]
velXarray = out["velXarray"]
velYarray = out["velYarray"]
densityArray = out["densityArray"]
tempArray = out["tempArray"]
magXarray = out["magXarray"]
magYarray = out["magYarray"]

### Plotting setup?
ds = yt.load(filename)
ad = ds.all_data()
ymax = float(max(ad['y']).value)
ymin = float(min(ad['y']).value)
x = closestNum(posXarray, 2.32838 * pow(10, 22))