Moments validation with PySPEDAS
Retrieve the data from PySPEDAS into Julia, and compute the moments directly from the raw distribution — no per-timestep mms_get_fpi_dist calls needed.
Here we load the data from a JLD2 file in order to avoid the slow PySPEDAS run.
using VelocityDistributionFunctions
using Downloads
using JLD2
function download_test_data(url, filename = basename(url))
cache_dir = joinpath(pkgdir(VelocityDistributionFunctions), "data")
mkpath(cache_dir)
filepath = joinpath(cache_dir, filename)
if !isfile(filepath)
@info "Downloading test data: $filename"
Downloads.download(url, filepath)
end
return filepath
end
const ref_url = "https://github.com/JuliaSpacePhysics/VelocityDistributionFunctions.jl/releases/download/v0.2.1/pyspedas_mms_fpi_brst_i.jld2"
reffile = download_test_data(ref_url)
saved = JLD2.load(reffile)["result"]Dict{String, Any} with 6 entries:
"mag_data" => [-8.11571 11.8063 -16.7582; -8.20437 10.5389 -18.0987; … ;…
"ref" => Dict{String, Array{Float64}}("ptens"=>[4047.98 5204.16 … 3…
"distributions" => Dict{String, Any}[Dict("theta"=>[-84.375 -84.375 … 84.375 …
"times" => [1.445e9, 1.445e9, 1.445e9, 1.445e9, 1.445e9, 1.445e9, 1.4…
"scpot_data" => [4.44189, 4.37592, 4.34478, 4.42955, 4.65947, 4.76109, 4.8…
"dis_dist_brst" => Dict{String, Array{Float32}}("theta"=>[5.625, 16.875, 28.1…For MMS: thetagse = colat - 90, phigse = (phi + 180) % 360
mms1_dis_dist_brst = saved["dis_dist_brst"]
data = mms1_dis_dist_brst["data"]
theta = mms1_dis_dist_brst["theta"] .- 90
phi = (mms1_dis_dist_brst["phi"] .+ 180) .% 360
energy = mms1_dis_dist_brst["energy"]
scpot_data = saved["scpot_data"]
out = tmoments(data, theta, phi, energy, scpot_data; edim=4, tdim=1, units=:df_cm)66-element StructArray(::Vector{Float64}, ::Vector{StaticArraysCore.SVector{3, Float32}}, ::Vector{StaticArraysCore.SVector{3, Float64}}, ::Vector{StaticArraysCore.SVector{3, Float32}}, ::Vector{StaticArraysCore.SVector{3, Float64}}, ::Vector{StaticArraysCore.SVector{6, Float32}}, ::Vector{StaticArraysCore.SVector{6, Float64}}, ::Vector{StaticArraysCore.SMatrix{3, 3, Float64, 9}}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{StaticArraysCore.MVector{3, Float64}}) with eltype @NamedTuple{density::Float64, flux::StaticArraysCore.SVector{3, Float32}, velocity::StaticArraysCore.SVector{3, Float64}, eflux::StaticArraysCore.SVector{3, Float32}, qflux::StaticArraysCore.SVector{3, Float64}, mftens::StaticArraysCore.SVector{6, Float32}, ptens::StaticArraysCore.SVector{6, Float64}, ttens::StaticArraysCore.SMatrix{3, 3, Float64, 9}, avgtemp::Float64, vthermal::Float64, t3::StaticArraysCore.MVector{3, Float64}}:
(density = 12.105852769003079, flux = [-1.8199693f8, 1.7629342f8, -1.6948355f8], velocity = [-1.5033796583583225e7, 1.456266050512341e7, -1.4000133260662233e7], eflux = [-2.5428073f11, 3.1527502f11, -2.2911944f11], qflux = [-2.2642981660364014e10, 6.009965096471602e10, -4.1232610873294215e9], mftens = [6908.167, 7887.8857, 6384.6714, -3293.1516, 2968.5332, -3824.742], ptens = [4047.979845372915, 5204.157346005775, 3904.2729418115846, -522.5983336775598, 305.00100863168745, -1244.6807540767732], ttens = [334.3820483045795 -43.169064059300965 25.19450834662715; -43.169064059300965 429.8877117794602 -102.81644571655178; 25.19450834662715 -102.81644571655178 322.511186639279], avgtemp = 362.2603155744396, vthermal = 2.6326584340675697e7, t3 = [260.19886106920103, 319.8968494430607, 506.68523621105646])
(density = 12.4163052232694, flux = [-1.7924269f8, 1.7935093f8, -1.6744386f8], velocity = [-1.4436072952208137e7, 1.4444790521408767e7, -1.3485803786958573e7], eflux = [-2.4201583f11, 3.038092f11, -2.3623921f11], qflux = [-1.8399975541793068e10, 5.392264383583354e10, -1.8088445800413277e10], mftens = [6835.157, 7826.3745, 6262.0493, -3215.5479, 2960.8098, -3834.5552], ptens = [4130.250836857273, 5118.2002903186985, 3901.5288143822836, -509.0080392006016, 433.9566353081991, -1306.1760956851476], ttens = [332.6473344998614 -40.9951293921697 34.95054506995534; -40.9951293921697 412.2160496446784 -105.19845253459481; 34.95054506995534 -105.19845253459481 314.2262327016919], avgtemp = 353.0298722820773, vthermal = 2.598901763638376e7, t3 = [246.42518033058587, 316.0132150987455, 496.6512214169004])
(density = 11.884146149481431, flux = [-1.7275506f8, 1.7312958f8, -1.5844965f8], velocity = [-1.4536598071670318e7, 1.4568112998808464e7, -1.3332859256944934e7], eflux = [-2.4009843f11, 3.0133528f11, -2.2460958f11], qflux = [-2.219403745675805e10, 6.354473311389741e10, -1.4439082964062197e10], mftens = [6691.572, 7337.467, 6152.387, -3083.1658, 2842.0344, -3604.5042], ptens = [4066.414832011539, 4700.914983314504, 3943.994537010809, -452.3175612874106, 434.2600665170198, -1191.5098074225157], ttens = [342.17139211040234 -38.06058555642617 36.54112470974357; -38.06058555642617 395.56186234882597 -100.26044719035264; 36.54112470974357 -100.26044719035264 331.87024859862623], avgtemp = 356.53450101928485, vthermal = 2.6117699274083722e7, t3 = [257.82953068705604, 324.0463150541189, 487.7276573166795])
(density = 11.239946661253722, flux = [-1.623526f8, 1.6979738f8, -1.490206f8], velocity = [-1.4444250750731848e7, 1.5106599801342877e7, -1.3258124125597764e7], eflux = [-2.4281498f11, 2.9058967f11, -2.1018555f11], qflux = [-2.8590281854262314e10, 5.261846612683357e10, -8.147684011067245e9], mftens = [6519.617, 7196.988, 5889.3374, -3120.1392, 2680.5232, -3395.3074], ptens = [4068.2068557903035, 4515.60126977156, 3824.004160090233, -556.3180614302223, 430.4166962166828, -1042.0210067731614], ttens = [361.9418292983722 -49.494724325334985 38.2934820945737; -49.494724325334985 401.74579167156674 -92.7069351997203; 38.2934820945737 -92.7069351997203 340.2155077187615], avgtemp = 367.96770956290015, vthermal = 2.6533160909561478e7, t3 = [273.2390459718311, 333.14760276248734, 497.51647995438225])
(density = 10.335411212941793, flux = [-1.492028f8, 1.660615f8, -1.4654322f8], velocity = [-1.4436077764682578e7, 1.606723724664783e7, -1.4178750412610728e7], eflux = [-2.2941103f11, 2.8391768f11, -2.2891651f11], qflux = [-1.6117563698977104e10, 3.670692923286242e10, -1.4037544526257719e10], mftens = [6263.641, 7178.85, 5989.569, -2976.916, 2757.5413, -3441.7336], ptens = [4012.058378586763, 4389.699931795644, 3817.5409476467944, -470.92272794005385, 546.0936526684063, -980.4104257767972], ttens = [388.18565569630596 -45.56400497644196 52.837148074437415; -45.56400497644196 424.7242650876775 -94.85935349617702; 52.837148074437415 -94.85935349617702 369.36517270513116], avgtemp = 394.09169782970486, vthermal = 2.7458877460031148e7, t3 = [295.0434033666888, 358.1726796678496, 529.0590104545759])
(density = 9.881139797788501, flux = [-1.453526f8, 1.612835f8, -1.3837386f8], velocity = [-1.471010541036282e7, 1.6322358280579826e7, -1.4003835471588962e7], eflux = [-2.2421543f11, 2.8069383f11, -2.1246244f11], qflux = [-1.8151775721261578e10, 3.8745233333109924e10, -5.127263806345597e9], mftens = [6019.1855, 6988.7236, 5821.39, -2837.3237, 2575.7666, -3362.0388], ptens = [3784.0681599181794, 4236.811390112618, 3795.7477939911587, -357.233631089729, 447.96294051047835, -1001.0242139396291], ttens = [382.9586704931644 -36.153079341077785 45.33514854336308; -36.153079341077785 428.77759821400963 -101.30655313303718; 45.33514854336308 -101.30655313303718 384.14068332892987], avgtemp = 398.6256506787013, vthermal = 2.7616380424399566e7, t3 = [300.3331144128137, 363.7393312249395, 531.8045063983502])
(density = 10.152942668537921, flux = [-1.5118416f8, 1.633927f8, -1.3807296f8], velocity = [-1.4890674057334289e7, 1.6093137658141572e7, -1.3599304606324863e7], eflux = [-2.2535142f11, 2.8873612f11, -2.1523574f11], qflux = [-9.304616091558256e9, 4.1975677911362404e10, -7.390922124652669e9], mftens = [6328.579, 7166.719, 5988.969, -2952.674, 2545.2603, -3275.062], ptens = [3975.251588239772, 4417.970077524679, 4026.1194728178525, -409.3087765931382, 396.02123565256215, -952.2659282218051], ttens = [391.53688915808976 -40.31429999713382 39.00556208987156; -40.31429999713382 435.1418324477637 -93.7921112440337; 39.00556208987156 -93.7921112440337 396.54705086576], avgtemp = 407.7419241572045, vthermal = 2.793037843328337e7, t3 = [319.6800436402404, 369.93884123147876, 533.6068875998939])
(density = 11.564629912413922, flux = [-1.7892878f8, 1.6906075f8, -1.3640842f8], velocity = [-1.547207177014207e7, 1.4618777538096886e7, -1.179531182866249e7], eflux = [-2.4551308f11, 2.7958496f11, -2.0003848f11], qflux = [-2.3084548092747498e10, 5.418680058992743e10, -1.4571771148042362e10], mftens = [6870.394, 6982.5596, 5909.7017, -3050.1128, 2519.865, -3096.2898], ptens = [3976.4481610801236, 4399.017266291752, 4227.754623326539, -315.7697984989818, 313.6320694419851, -1011.7319706406911], ttens = [343.845690799984 -27.304790632342005 27.119940008224585; -27.304790632342005 380.3854770630988 -87.48502790864572; 27.119940008224585 -87.48502790864572 365.5763007848875], avgtemp = 363.2691562159901, vthermal = 2.636321664879944e7, t3 = [285.13869834593567, 332.37598542268717, 472.29278487934783])
(density = 12.267195621675798, flux = [-1.9335222f8, 1.7367029f8, -1.3450306f8], velocity = [-1.5761729898425352e7, 1.415729343168942e7, -1.0964450241776269e7], eflux = [-2.4298575f11, 2.8741317f11, -1.9092793f11], qflux = [-1.1045209772434513e10, 6.358243695213641e10, -1.4129211062936296e10], mftens = [7237.975, 7140.8564, 6012.6772, -3199.9448, 2478.14, -2870.1257], ptens = [4052.2024709252796, 4570.653117059646, 4471.045175072647, -338.4620952335172, 261.9970153363156, -879.5710660336899], ttens = [330.3283485399996 -27.590828879867534 21.357531371992966; -27.590828879867534 372.5915244217209 -71.70107114616417; 21.357531371992966 -71.70107114616417 364.4716618990271], avgtemp = 355.7971782869159, vthermal = 2.6090679252556656e7, t3 = [296.258703469356, 320.73742442832275, 450.3954069630686])
(density = 13.871224187967394, flux = [-2.219061f8, 1.8668504f8, -1.389989f8], velocity = [-1.599758557665679e7, 1.3458440110999007e7, -1.0020665380102118e7], eflux = [-2.4565817f11, 2.863176f11, -1.9924232f11], qflux = [-1.7711092295852656e9, 6.59849881575123e10, -2.8003165686918903e10], mftens = [7868.2695, 7309.9233, 6115.686, -3409.1062, 2672.1562, -2916.0652], ptens = [4157.317004658542, 4683.492513712959, 4659.658344511996, -287.1580737764589, 347.66713680040857, -960.5202460458427], ttens = [299.70801050600926 -20.701710958255177 25.06391159779486; -20.701710958255177 337.64089241493616 -69.24552822663243; 25.06391159779486 -69.24552822663243 335.9226468673198], avgtemp = 324.42384992942175, vthermal = 2.4913831503800925e7, t3 = [267.1005616281484, 291.06834504000005, 415.10264312011645])
⋮
(density = 11.69721403364783, flux = [-1.6708534f8, 1.2857864f8, -3.830963f7], velocity = [-1.428419994020522e7, 1.099224478838592e7, -3.2751073793981834e6], eflux = [-1.7030547f11, 1.7252182f11, -6.945384f10], qflux = [-2.053426062969559e10, 5.323628412469424e10, -3.156720935003776e10], mftens = [5789.7656, 4930.1895, 3143.8464, -2225.743, 734.47815, -737.02216], ptens = [3294.849205329932, 3452.7253340826483, 3012.688296095248, -305.80815799059155, 162.4391684947194, -296.8160165949281], ttens = [281.6781154770764 -26.143674648588426 13.88699634181713; -26.143674648588426 295.1750155336689 -25.374932504536268; 13.88699634181713 -25.374932504536268 257.5560545809494], avgtemp = 278.1363951972316, vthermal = 2.3068164879810963e7, t3 = [244.7613017997507, 262.4509695368144, 327.19691425512974])
(density = 11.626303687593055, flux = [-1.6510486f8, 1.32840104f8, -4.036213f7], velocity = [-1.4200976375336792e7, 1.1425824369421864e7, -3.4716216851510787e6], eflux = [-1.8507303f11, 2.0338591f11, -7.047833f10], qflux = [-2.875050399216501e10, 7.463087023330396e10, -2.7954176902983315e10], mftens = [5957.9097, 5210.905, 3338.9814, -2233.648, 828.0629, -768.8025], ptens = [3506.929504965691, 3624.2645085539953, 3192.5048720282043, -261.63784686789927, 228.88751431222454, -286.7178184685684], ttens = [301.6375280742143 -22.503957740851433 19.68704073647075; -22.503957740851433 311.7297299245339 -24.66113273598192; 19.68704073647075 -24.66113273598192 274.59328070322715], avgtemp = 295.9868462339918, vthermal = 2.379689759343533e7, t3 = [260.2625427164128, 283.62092531923224, 344.0770706663304])
(density = 12.159425024674347, flux = [-1.720444f8, 1.3029724f8, -4.2151936f7], velocity = [-1.4149057184108727e7, 1.0715740237354653e7, -3.4666060207998124e6], eflux = [-1.7971397f11, 1.8500187f11, -7.701602f10], qflux = [-2.8191350888989197e10, 6.552353058481877e10, -3.618022185907138e10], mftens = [5900.1475, 5049.313, 3289.493, -2205.728, 793.2675, -768.9892], ptens = [3355.487441591737, 3589.7625178280828, 3136.7420343609438, -278.53843408119974, 169.81016377162268, -296.8158950304166], ttens = [275.9577393489133 -22.907204371586605 13.965311963932319; -22.907204371586605 295.22469282417603 -24.410356117012686; 13.965311963932319 -24.410356117012686 257.96795720157434], avgtemp = 276.3834631248879, vthermal = 2.2995357363525532e7, t3 = [245.59399164884738, 260.927043476704, 322.62935424911217])
(density = 11.9926368172869, flux = [-1.6553915f8, 1.27674136f8, -4.0501704f7], velocity = [-1.380339907912345e7, 1.06460437304299e7, -3.3772142538010017e6], eflux = [-1.774584f11, 1.8622764f11, -7.235632f10], qflux = [-2.9387636554329105e10, 6.6355870820073456e10, -3.1971975408189507e10], mftens = [5756.5166, 5117.8335, 3328.8242, -2141.3467, 780.6983, -751.29895], ptens = [3367.888738222021, 3696.9682328610716, 3185.8381807294113, -299.0876431212034, 196.28369484548807, -300.5618931978638], ttens = [280.82971155829097 -24.939272962062912 16.367017348724602; -24.939272962062912 308.269840001495 -25.06220256454494; 16.367017348724602 -25.06220256454494 265.64951722186356], avgtemp = 284.9163562605499, vthermal = 2.334763132274736e7, t3 = [252.7831542232907, 266.19499869531876, 335.7709158630398])
(density = 11.497465235872822, flux = [-1.5661768f8, 1.22101896f8, -4.491143f7], velocity = [-1.362193116369188e7, 1.0619896950767403e7, -3.9062028959107855e6], eflux = [-1.635152f11, 1.8075692f11, -8.3954385f10], qflux = [-1.9335128505403355e10, 6.387248667363552e10, -3.985387871600261e10], mftens = [5627.915, 4978.9976, 3253.6875, -2026.8306, 815.66394, -778.1966], ptens = [3397.728494226815, 3623.4822273512773, 3070.298440195886, -288.13793886811914, 176.1392625280431, -279.6119152251578], ttens = [295.51978845090883 -25.0609967464055 15.319834321262169; -25.0609967464055 315.1548757064977 -24.319439936443633; 15.319834321262169 -24.319439936443633 267.0413327814517], avgtemp = 292.5719989796194, vthermal = 2.365922506048651e7, t3 = [256.1506731636097, 278.46321480069315, 343.10210897455573])
(density = 11.033526364101721, flux = [-1.4835411f8, 1.19918936f8, -4.1737764f7], velocity = [-1.3445756787483603e7, 1.086859559153852e7, -3.7828127311859666e6], eflux = [-1.771091f11, 1.8322278f11, -7.287375f10], qflux = [-3.2725226982774803e10, 6.530415242806472e10, -2.8571304990115265e10], mftens = [5651.813, 4900.4097, 3193.1895, -1975.5575, 880.79913, -764.3412], ptens = [3566.6185243713367, 3537.9523073086357, 3028.1431714174346, -290.03426900554973, 294.1530791032509, -290.13814840363005], ttens = [323.2528211447934 -26.286633976712526 26.659933496900557; -26.286633976712526 320.65472003761084 -26.296048863182396; 26.659933496900557 -26.296048863182396 274.449262320131], avgtemp = 306.1189345008451, vthermal = 2.4200772693426628e7, t3 = [258.77440235384637, 295.6443638701595, 363.9380372785293])
(density = 11.384579678089812, flux = [-1.5610928f8, 1.2530426f8, -4.5914344f7], velocity = [-1.3712344628799958e7, 1.1006489439496325e7, -4.0330293518314455e6], eflux = [-1.654902f11, 1.8002934f11, -7.362496f10], qflux = [-1.7022023102882557e10, 5.952451413808246e10, -2.6828240836048542e10], mftens = [5741.303, 4950.3223, 3247.1265, -2135.341, 993.9019, -713.6981], ptens = [3503.6016659358093, 3508.617390579963, 3053.5549315917124, -339.2048660484136, 335.75655163771864, -185.42449484387794], ttens = [307.7497602022729 -29.795115466689573 29.492222034678957; -29.795115466689573 308.19033199200766 -16.287337792605253; 29.492222034678957 -16.287337792605253 268.21850414630853], avgtemp = 294.71953211352974, vthermal = 2.374589786873603e7, t3 = [252.47804493424195, 281.0360101942851, 350.644541212062])
(density = 11.871380074925847, flux = [-1.5668619f8, 1.3194775f8, -4.6054016f7], velocity = [-1.319865011574728e7, 1.1114777824247548e7, -3.8794155110300155e6], eflux = [-1.6373254f11, 1.905194f11, -7.8558675f10], qflux = [-1.8716319957927715e10, 6.6149524155066185e10, -3.3104323713693764e10], mftens = [5721.5933, 5145.08, 3329.897, -2160.1396, 857.728, -812.24524], ptens = [3559.761139184832, 3612.0011830993226, 3143.131956827517, -339.6289504065012, 222.31114797705345, -277.1513184400113], ttens = [299.8607673848794 -28.609053729468993 18.726647329454835; -28.609053729468993 304.2612704085194 -23.34617514482557; 18.726647329454835 -23.34617514482557 264.765506368235], avgtemp = 289.62918138721125, vthermal = 2.3539936903691605e7, t3 = [253.07100568287004, 273.5523837236453, 342.2641547551184])
(density = 11.262347659107654, flux = [-1.4976802f8, 1.233407f8, -4.2790316f7], velocity = [-1.3298116923151929e7, 1.0951597991228467e7, -3.79941352328937e6], eflux = [-1.5694958f11, 1.8128991f11, -7.126275f10], qflux = [-1.6259257403847466e10, 6.4816048043203835e10, -2.837643396302413e10], mftens = [5590.962, 4846.4404, 3110.7988, -2009.1389, 848.2836, -751.56494], ptens = [3509.0087880749284, 3434.4048500148983, 2940.847805774498, -294.5567835107265, 253.44746616500584, -261.6905795943229], ttens = [311.56992256736606 -26.15411923219435 22.503963990140857; -26.15411923219435 304.94573191740875 -23.23588185298991; 22.503963990140857 -23.23588185298991 261.1220941484867], avgtemp = 292.54591621108716, vthermal = 2.3658170428041797e7, t3 = [248.8079213480498, 282.054817415981, 346.7750098692308])