Skip to content

Commit

Permalink
Get new SpaceWeatherData structure working
Browse files Browse the repository at this point in the history
  • Loading branch information
duncaneddy committed May 28, 2024
1 parent aac2168 commit fc1890d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 48,796 deletions.
18,815 changes: 0 additions & 18,815 deletions data/FINALS.ALL_IAU2000.txt

This file was deleted.

21,426 changes: 0 additions & 21,426 deletions data/fluxtable.txt

This file was deleted.

8,521 changes: 0 additions & 8,521 deletions data/kpall.wdc

This file was deleted.

55 changes: 29 additions & 26 deletions src/earth_environment/space_weather.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
function get_kp_decimal(number::String, digit::String)
if isempty(strip(string(number)))
number = 0.0
else
number = parse(Int, number)
function get_kp_decimal(str)

# Parse number
number = 0.0
if length(str) >= 2
number = parse(Int, str[1:end-1])
end

# Parse decimal
decimal = 0.0
if parse(Int, digit) == 3
if parse(Int, str[end]) == 3
decimal = 1.0/3.0
elseif parse(Int, digit) == 7
elseif parse(Int, str[end]) == 7
decimal = 2.0/3.0
end

Expand Down Expand Up @@ -64,10 +67,10 @@ function SpaceWeatherData(filepath::String)

kp_data = Float64[]
for i in 6:13
push!(kp_data, get_kp_decimal(split_line[1], split_line[2]))
push!(kp_data, get_kp_decimal(split_line[i]))
end

kp_sum = get_kp_decimal(split_line[14][1:2], split_line[14][3])
kp_sum = get_kp_decimal(split_line[14])

ap_data = Float64[]

Expand Down Expand Up @@ -118,10 +121,10 @@ function SpaceWeatherData(filepath::String)

kp_data = Float64[]
for i in 6:13
push!(kp_data, get_kp_decimal(split_line[1], split_line[2]))
push!(kp_data, get_kp_decimal(split_line[i]))
end

kp_sum = get_kp_decimal(split_line[14][1:2], split_line[14][3])
kp_sum = get_kp_decimal(split_line[14])

ap_data = Float64[]

Expand All @@ -135,9 +138,9 @@ function SpaceWeatherData(filepath::String)

# Parse Solar Flux Data
f107_adj = parse(Float64, split_line[27])
f107_obs = parse(Float64, split_line[31])
f107_adj_avg = parse(Float64, split_line[30])
f107_obs_avg = parse(Float64, split_line[33])
f107_obs = parse(Float64, split_line[30])
f107_adj_avg = parse(Float64, split_line[29])
f107_obs_avg = parse(Float64, split_line[32])

solarflux_data[mjd] = (f107_obs, f107_adj, f107_obs_avg, f107_adj_avg)

Expand Down Expand Up @@ -189,8 +192,8 @@ function KpIndices(swdata::SpaceWeatherData, mjd::Real)
return swdata.geomagnetic_data[floor(Int, mjd)][1]
end

KpIndices(mjd::Real) = KpIndices(SpaceWeatherData, mjd)
KpIndices(epc::Epoch) = KpIndices(SpaceWeatherData, mjd(epc, tsys="UT1"))
KpIndices(mjd::Real) = KpIndices(SPACE_WEATHER_DATA, mjd)
KpIndices(epc::Epoch) = KpIndices(SPACE_WEATHER_DATA, mjd(epc, tsys="UT1"))

export KpIndex
"""
Expand All @@ -209,8 +212,8 @@ function KpIndex(swdata::SpaceWeatherData, mjd::Real)
return swdata.geomagnetic_data[mjd_ut1][1][hour_idx+1]
end

KpIndex(mjd::Real) = KpIndex(SpaceWeatherData, mjd)
KpIndex(epc::Epoch) = KpIndex(SpaceWeatherData, mjd(epc, tsys="UT1"))
KpIndex(mjd::Real) = KpIndex(SPACE_WEATHER_DATA, mjd)
KpIndex(epc::Epoch) = KpIndex(SPACE_WEATHER_DATA, mjd(epc, tsys="UT1"))

export KpDailyIndex
"""
Expand All @@ -224,8 +227,8 @@ function KpDailyIndex(swdata::SpaceWeatherData, mjd::Real)
return swdata.geomagnetic_data[floor(Int, mjd)][2]
end

KpDailyIndex(mjd::Real) = KpDailyIndex(SpaceWeatherData, mjd)
KpDailyIndex(epc::Epoch) = KpDailyIndex(SpaceWeatherData, mjd(epc, tsys="UT1"))
KpDailyIndex(mjd::Real) = KpDailyIndex(SPACE_WEATHER_DATA, mjd)
KpDailyIndex(epc::Epoch) = KpDailyIndex(SPACE_WEATHER_DATA, mjd(epc, tsys="UT1"))

export ApIndices
"""
Expand All @@ -239,8 +242,8 @@ function ApIndices(swdata::SpaceWeatherData, mjd::Real)
return swdata.geomagnetic_data[floor(Int, mjd)][3]
end

ApIndices(mjd::Real) = ApIndices(SpaceWeatherData, mjd)
ApIndices(epc::Epoch) = ApIndices(SpaceWeatherData, mjd(epc, tsys="UT1"))
ApIndices(mjd::Real) = ApIndices(SPACE_WEATHER_DATA, mjd)
ApIndices(epc::Epoch) = ApIndices(SPACE_WEATHER_DATA, mjd(epc, tsys="UT1"))

export ApIndex
"""
Expand All @@ -259,8 +262,8 @@ function ApIndex(swdata::SpaceWeatherData, mjd::Real)
return swdata.geomagnetic_data[mjd_ut1][3][hour_idx+1]
end

ApIndex(mjd::Real) = ApIndex(SpaceWeatherData, mjd)
ApIndex(epc::Epoch) = ApIndex(SpaceWeatherData, mjd(epc, tsys="UT1"))
ApIndex(mjd::Real) = ApIndex(SPACE_WEATHER_DATA, mjd)
ApIndex(epc::Epoch) = ApIndex(SPACE_WEATHER_DATA, mjd(epc, tsys="UT1"))

export ApDailyIndex
"""
Expand All @@ -274,8 +277,8 @@ function ApDailyIndex(swdata::SpaceWeatherData, mjd::Real)
return swdata.geomagnetic_data[floor(Int, mjd)][4]
end

ApDailyIndex(mjd::Real) = ApDailyIndex(SpaceWeatherData, mjd)
ApDailyIndex(epc::Epoch) = ApDailyIndex(SpaceWeatherData, mjd(epc, tsys="UT1"))
ApDailyIndex(mjd::Real) = ApDailyIndex(SPACE_WEATHER_DATA, mjd)
ApDailyIndex(epc::Epoch) = ApDailyIndex(SPACE_WEATHER_DATA, mjd(epc, tsys="UT1"))

export f107Data
"""
Expand Down
21 changes: 13 additions & 8 deletions test/earth_environment/test_spaceweather.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@


let
load_space_weather_data(TEST_SW_DATA)
end

##########################
# Geomagnetic Index Data #
##########################
Expand All @@ -15,14 +20,14 @@ end
###################

let
@test f107Observed(53941) == 75.9
@test f107Adjusted(53941) == 78.3
@test isapprox(f107ObservedAvg(53941), 72.2951, atol=1e-4)
@test isapprox(f107AdjustedAvg(53941), 74.5593, atol=1e-4)
@test f107Observed(53941) == 75.5
@test f107Adjusted(53941) == 77.9
@test isapprox(f107ObservedAvg(53941), 77.3, atol=1e-4)
@test isapprox(f107AdjustedAvg(53941), 79.6, atol=1e-4)

data = f107Data(53941)
@test data[1] == 75.9
@test data[2] == 78.3
@test isapprox(data[3], 72.2951, atol=1e-4)
@test isapprox(data[4], 74.5593, atol=1e-4)
@test data[1] == 75.5
@test data[2] == 77.9
@test isapprox(data[3], 77.3, atol=1e-4)
@test isapprox(data[4], 79.6, atol=1e-4)
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Random.seed!(0)
# Define paths for test data
const TEST_C04_EOP_DATA = abspath(joinpath(@__DIR__, "./data/EOP_20_C04_one_file_1962-now.txt"))
const TEST_FINALS_EOP_DATA = abspath(joinpath(@__DIR__, "./data/FINALS.ALL_IAU2000.txt"))
const TEST_SW_DATA = abspath(joinpath(@__DIR__, "./data/sw19571001.txt"))

# Check equality of two arrays
@inline function array_isapprox(x::AbstractArray{F},
Expand Down

0 comments on commit fc1890d

Please sign in to comment.