-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
60 lines (52 loc) · 1.94 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#This script loads data from MMS1_FGM using pyspedas
import pyspedas
import numpy as np
import mfdfa_lib as mfdfa
from pyspedas import tplot
def main():
#Gather data and plot it:
pyspedas.mms.fgm(time_clip=True,probe=1,trange=["2024-03-10","2024-03-11"])
#t_plot=tplot(['mms1_fgm_b_gse_srvy_l2_btot', 'mms1_fgm_b_gse_srvy_l2_bvec'])
#Get data to be put in array format:
magdata=pyspedas.get_data("mms1_fgm_b_gse_srvy_l2_btot")
#extract time and B-field magnitudes:
times=magdata.times
bmag=magdata.y
print("loaded data!")
print(times)
print("Calculating the cumulative sum...")
#Obtain a list of integrated time series values and save to csv:
#Also obtain the reverse list to segment the list backwards for 2N entries
int_series=mfdfa.int_series(bmag)
reverse_int_series = list(reversed(int_series))
# np.savetxt('data/Yfunc_values.csv',(np.array(int_series)),delimiter=',')
print("Done integrating...")
print("Segmenting...")
#Segment the integrated series:
s=4
print(len(int_series))
#Now reverse the series to include points that are left out of the last
#paritition of the integrated time series:
#This gives us 2N_s total points to apply a polynomial fit.
seg_series=mfdfa.int_segments(int_series,s)
reverse_seg_series=mfdfa.int_segments(reverse_int_series,s)
print(len(seg_series))
print(len(reverse_seg_series))
#Concatenate the entire list of both the reversed segments and the
#non-reversed segments:
segment_list = seg_series + reverse_seg_series
print(len(segment_list))
print("Constructing polynomial fits...")
#fit the series to a n degree plynomial:
n=3
#this function returns the coefficients of the polynomial:
fitList=mfdfa.poly_fit(segment_list,n,s)
#print(f"Polynomial fits: {fitList}")
#Now we construct the polynomial values for a given value i
#WIP
Ns=len(seg_series)
print(f"Ns=, {Ns}")
print(len(segment_list))
print(mfdfa.variance(int_series,fitList,s,n,Ns,len(seg_series)))
print("Finished!")
main()