CLUSTER_Python_Programme/Bachelorthesis/POWER_LAW.py
lisa 3de9073b27 POWER_LAW.py
This program calculates the average flux (3D distribution) for each energy bin
across all times and viewing directions. The resulting energy
spectrum is then plotted on a double-logarithmic graph.
2026-06-10 22:09:23 +02:00

136 lines
2.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from rapid_fgm import *
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt
#---------USER INPUT------------------
SC_ID = 'C3'
TIME_PERIOD = (datetime(2002,6,27,23), datetime(2002,6,28,23))
PARTICLE_TYPE = "electron" #'electron' oder "ion"
#-----------------------------------------------------
instrument = "IES" if PARTICLE_TYPE == "electron" else "IIMS"
r = RAPID(sc_id=SC_ID, time_period=TIME_PERIOD, particle_type=PARTICLE_TYPE)
data_rapid = r.load_rapid()
r.get_rapid_var(r.data_rapid)
print('rapid time:', r.time_rapid[0], r.time_rapid[-1])
flow = FLOW(
sc_id=SC_ID,
time_period=TIME_PERIOD,
particle_type=PARTICLE_TYPE
)
flow.get_flow_var(flow.data_flow)
flow.load_flow()
#font in Times New Roman
plt.rcParams['font.family'] = 'Times New Roman'
plt.rcParams['mathtext.fontset'] = 'stix'
f = FGM(sc_id=SC_ID, time_period=TIME_PERIOD)
f.load_fgm()
f.get_fgm_var(f.data_fgm)
p = PITCH_CSA(sc_id=SC_ID, time_period=TIME_PERIOD)
p.load_pad()
pad_data = p.get_pad_var(p.data_pad)
w = WORKSPACE()
sync = w.sync_all_by_resolution(r, f, flow)
t_sync = sync['time']
rapid_sync = sync['rapid']
fgm_sync = sync['fgm']
sc2gse = sync['sc2gse']
sc_data = w.spacecrafts(
sc_id=SC_ID,
t_sync=t_sync,
rapid_sync=rapid_sync,
fgm_sync=fgm_sync,
sc2gse=sc2gse,
time_period=None
)
flux = sc_data['flux']
time = sc_data['time'][:flux.shape[0]]
mask = (time >= start) & (time <= end)
flux = np.where(flux < 0, np.nan, flux)
print(len(time))
print(flux.shape)
energy = r.energy_table
mean_flux_energy = np.nanmean(flux, axis=(0, 2, 3))
# Standardabweichung aus denselben Dimensionen
flux_sd = np.nanstd(flux, axis=(0, 2, 3))
plt.figure()
color1 = '#0070C0'
color2 = '#63A375'
plt.errorbar(
energy,
mean_flux_energy,
yerr = flux_sd,
marker='o',
markerfacecolor = color1,
markeredgecolor = None,
linestyle='None',
color=color2,
label=r'Flux $\pm$ SD',
capsize=5
)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
plt.xscale('log')
plt.yscale('log')
#plt.tick_params(fontsize = 14)
gamma_ref = -1.5
scale_factor = 2
ref_line = mean_flux_energy[0] * scale_factor * (energy / energy[0])**gamma_ref
plt.plot(
energy,
ref_line,
linestyle='--',
color='black',
label=rf'$E^{{{gamma_ref}}}$'
)
plt.xlabel(r'Energy / $\mathrm{keV}$', fontsize = 12)
plt.ylabel(r'Flux / $(\mathrm{cm^{2}\,s\,sr\,keV})^{-1}$',fontsize = 12)
t0, t1 = (t.strftime('%Y-%m-%d') for t in TIME_PERIOD)
plt.title(f'{SC_ID} RAPID {instrument} Energy Spectrum {t0} to {t1}', fontsize = 14)
plt.grid(True, which='both')
plt.legend()
filename = 'C:/Users/lview/OneDrive/Dokumente/Desktop/C3_RAPID_20020628/'+ f'{SC_ID}_{instrument}_Power_law_fit_'+'20020627_20020629.pdf'
print(filename)
plt.savefig(filename)
plt.show()