Skip to content

Space Weather Functions

Global space weather management and query functions.

Module: brahe.space_weather

Managing Global Provider

initialize_sw builtin

initialize_sw() -> Any

Initialize the global space weather provider with recommended default settings.

This convenience function creates a CachingSpaceWeatherProvider with sensible defaults and sets it as the global provider. The provider will:

  • Automatically download/update space weather files when older than 7 days
  • Use the default cache location (~/.cache/brahe/sw19571001.txt)
  • Hold the last known value when extrapolating beyond available data
  • NOT auto-refresh on every access (manual refresh required)

This is the recommended way to initialize space weather data for most applications.

Raises:

Type Description
Exception

If file download or loading failed

Example
import brahe as bh

# Initialize with recommended defaults
bh.initialize_sw()

# Now you can access space weather data
mjd = 60000.0
kp = bh.get_global_kp(mjd)
ap = bh.get_global_ap_daily(mjd)
f107 = bh.get_global_f107_observed(mjd)

set_global_space_weather_provider builtin

set_global_space_weather_provider(provider: StaticSpaceWeatherProvider | FileSpaceWeatherProvider | CachingSpaceWeatherProvider) -> Any

Set the global space weather provider using any supported provider type.

This function accepts any of the three space weather provider types.

Parameters:

Name Type Description Default
provider StaticSpaceWeatherProvider | FileSpaceWeatherProvider | CachingSpaceWeatherProvider

Space weather provider to set globally

required
Example
import brahe as bh

# Use with StaticSpaceWeatherProvider
provider = bh.StaticSpaceWeatherProvider.from_zero()
bh.set_global_space_weather_provider(provider)

# Use with FileSpaceWeatherProvider
provider = bh.FileSpaceWeatherProvider.from_default_file()
bh.set_global_space_weather_provider(provider)

# Use with CachingSpaceWeatherProvider
provider = bh.CachingSpaceWeatherProvider(7 * 86400, False, "Hold")
bh.set_global_space_weather_provider(provider)

get_global_sw_initialization builtin

get_global_sw_initialization() -> bool

Check if the global space weather provider is initialized.

Returns:

Name Type Description
bool bool

True if initialized

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
is_init = bh.get_global_sw_initialization()
print(f"Initialized: {is_init}")  # True

get_global_sw_len builtin

get_global_sw_len() -> int

Get the number of data points in the global provider.

Returns:

Name Type Description
int int

Number of data points

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
length = bh.get_global_sw_len()
print(f"Data points: {length}")

get_global_sw_type builtin

get_global_sw_type() -> str

Get the space weather data type of the global provider.

Returns:

Name Type Description
str str

Space weather type string

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
sw_type = bh.get_global_sw_type()
print(f"Type: {sw_type}")  # "CssiSpaceWeather"

get_global_sw_extrapolation builtin

get_global_sw_extrapolation() -> str

Get the extrapolation method of the global provider.

Returns:

Name Type Description
str str

Extrapolation method string

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
extrapolation = bh.get_global_sw_extrapolation()
print(f"Extrapolation: {extrapolation}")  # "Hold"

get_global_sw_mjd_min builtin

get_global_sw_mjd_min() -> float

Get the minimum MJD in the global provider.

Returns:

Name Type Description
float float

Minimum MJD

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
mjd_min = bh.get_global_sw_mjd_min()
print(f"Min MJD: {mjd_min}")

get_global_sw_mjd_max builtin

get_global_sw_mjd_max() -> float

Get the maximum MJD in the global provider.

Returns:

Name Type Description
float float

Maximum MJD

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
mjd_max = bh.get_global_sw_mjd_max()
print(f"Max MJD: {mjd_max}")

get_global_sw_mjd_last_observed builtin

get_global_sw_mjd_last_observed() -> float

Get the last MJD with observed data in the global provider.

Returns:

Name Type Description
float float

Last MJD with observed data

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
mjd_obs = bh.get_global_sw_mjd_last_observed()
print(f"Last observed MJD: {mjd_obs}")

get_global_sw_mjd_last_daily_predicted builtin

get_global_sw_mjd_last_daily_predicted() -> float

Get the last MJD with daily predicted data in the global provider.

Returns:

Name Type Description
float float

Last MJD with daily predicted data

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
mjd_daily = bh.get_global_sw_mjd_last_daily_predicted()
print(f"Last daily predicted MJD: {mjd_daily}")

get_global_sw_mjd_last_monthly_predicted builtin

get_global_sw_mjd_last_monthly_predicted() -> float

Get the last MJD with monthly predicted data in the global provider.

Returns:

Name Type Description
float float

Last MJD with monthly predicted data

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
mjd_monthly = bh.get_global_sw_mjd_last_monthly_predicted()
print(f"Last monthly predicted MJD: {mjd_monthly}")

Querying Kp Index

get_global_kp builtin

get_global_kp(mjd: float) -> float

Get Kp index from the global space weather provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date

required

Returns:

Name Type Description
float float

Kp index (0.0-9.0)

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
kp = bh.get_global_kp(60000.0)
print(f"Kp: {kp}")

get_global_kp_all builtin

get_global_kp_all(mjd: float) -> list[float]

Get all eight 3-hourly Kp indices from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date

required

Returns:

Type Description
list[float]

list[float]: Array of 8 Kp indices

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
kp_all = bh.get_global_kp_all(60000.0)
print(f"8 Kp indices: {kp_all}")

get_global_kp_daily builtin

get_global_kp_daily(mjd: float) -> float

Get daily average Kp from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date

required

Returns:

Name Type Description
float float

Daily average Kp

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
kp_daily = bh.get_global_kp_daily(60000.0)
print(f"Daily Kp: {kp_daily}")

Querying Ap Index

get_global_ap builtin

get_global_ap(mjd: float) -> float

Get Ap index from the global space weather provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date

required

Returns:

Name Type Description
float float

Ap index

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
ap = bh.get_global_ap(60000.0)
print(f"Ap: {ap}")

get_global_ap_all builtin

get_global_ap_all(mjd: float) -> list[float]

Get all eight 3-hourly Ap indices from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date

required

Returns:

Type Description
list[float]

list[float]: Array of 8 Ap indices

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
ap_all = bh.get_global_ap_all(60000.0)
print(f"8 Ap indices: {ap_all}")

get_global_ap_daily builtin

get_global_ap_daily(mjd: float) -> float

Get daily average Ap from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date

required

Returns:

Name Type Description
float float

Daily average Ap

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
ap_daily = bh.get_global_ap_daily(60000.0)
print(f"Daily Ap: {ap_daily}")

Querying F10.7 Solar Flux

get_global_f107_observed builtin

get_global_f107_observed(mjd: float) -> float

Get observed F10.7 flux from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date

required

Returns:

Name Type Description
float float

F10.7 flux in sfu

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
f107 = bh.get_global_f107_observed(60000.0)
print(f"F10.7: {f107} sfu")

get_global_f107_adjusted builtin

get_global_f107_adjusted(mjd: float) -> float

Get adjusted F10.7 flux from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date

required

Returns:

Name Type Description
float float

Adjusted F10.7 flux in sfu

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
f107_adj = bh.get_global_f107_adjusted(60000.0)
print(f"F10.7 adjusted: {f107_adj} sfu")

get_global_f107_obs_avg81 builtin

get_global_f107_obs_avg81(mjd: float) -> float

Get 81-day average observed F10.7 flux from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date

required

Returns:

Name Type Description
float float

81-day average F10.7 flux in sfu

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
f107_avg = bh.get_global_f107_obs_avg81(60000.0)
print(f"F10.7 81-day avg: {f107_avg} sfu")

get_global_f107_adj_avg81 builtin

get_global_f107_adj_avg81(mjd: float) -> float

Get 81-day average adjusted F10.7 flux from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date

required

Returns:

Name Type Description
float float

81-day average adjusted F10.7 flux in sfu

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
f107_adj_avg = bh.get_global_f107_adj_avg81(60000.0)
print(f"F10.7 adj 81-day avg: {f107_adj_avg} sfu")

Querying Sunspot Number

get_global_sunspot_number builtin

get_global_sunspot_number(mjd: float) -> int

Get International Sunspot Number from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date

required

Returns:

Name Type Description
int int

Sunspot number

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
ssn = bh.get_global_sunspot_number(60000.0)
print(f"Sunspot number: {ssn}")

Range Queries

get_global_last_kp builtin

get_global_last_kp(mjd: float, n: int) -> list[float]

Get the last N 3-hourly Kp values from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date (end point)

required
n int

Number of 3-hourly values to return

required

Returns:

Type Description
list[float]

list[float]: List of Kp indices (oldest first)

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
kp_last = bh.get_global_last_kp(60000.0, 8)
print(f"Last 8 Kp values: {kp_last}")

get_global_last_ap builtin

get_global_last_ap(mjd: float, n: int) -> list[float]

Get the last N 3-hourly Ap values from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date (end point)

required
n int

Number of 3-hourly values to return

required

Returns:

Type Description
list[float]

list[float]: List of Ap indices (oldest first)

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
ap_last = bh.get_global_last_ap(60000.0, 8)
print(f"Last 8 Ap values: {ap_last}")

get_global_last_daily_kp builtin

get_global_last_daily_kp(mjd: float, n: int) -> list[float]

Get the last N daily average Kp values from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date (end point)

required
n int

Number of daily values to return

required

Returns:

Type Description
list[float]

list[float]: List of daily average Kp indices (oldest first)

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
kp_daily_last = bh.get_global_last_daily_kp(60000.0, 7)
print(f"Last 7 daily Kp: {kp_daily_last}")

get_global_last_daily_ap builtin

get_global_last_daily_ap(mjd: float, n: int) -> list[float]

Get the last N daily average Ap values from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date (end point)

required
n int

Number of daily values to return

required

Returns:

Type Description
list[float]

list[float]: List of daily average Ap indices (oldest first)

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
ap_daily_last = bh.get_global_last_daily_ap(60000.0, 7)
print(f"Last 7 daily Ap: {ap_daily_last}")

get_global_last_f107 builtin

get_global_last_f107(mjd: float, n: int) -> list[float]

Get the last N daily observed F10.7 values from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date (end point)

required
n int

Number of daily values to return

required

Returns:

Type Description
list[float]

list[float]: List of F10.7 values in sfu (oldest first)

Example
1
2
3
4
5
import brahe as bh

bh.initialize_sw()
f107_last = bh.get_global_last_f107(60000.0, 7)
print(f"Last 7 F10.7 values: {f107_last}")

get_global_last_kpap_epochs builtin

get_global_last_kpap_epochs(mjd: float, n: int) -> list[Epoch]

Get epochs for the last N 3-hourly Kp/Ap intervals from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date (end point)

required
n int

Number of epochs to return

required

Returns:

Type Description
list[Epoch]

list[Epoch]: Epoch objects, oldest first

Example
1
2
3
4
5
6
import brahe as bh

bh.initialize_sw()
epochs = bh.get_global_last_kpap_epochs(60000.0, 8)
for epoch in epochs:
    print(f"Epoch: {epoch}")

get_global_last_daily_epochs builtin

get_global_last_daily_epochs(mjd: float, n: int) -> list[Epoch]

Get epochs for the last N daily values from the global provider.

Parameters:

Name Type Description Default
mjd float

Modified Julian Date (end point)

required
n int

Number of epochs to return

required

Returns:

Type Description
list[Epoch]

list[Epoch]: Epoch objects, oldest first

Example
1
2
3
4
5
6
import brahe as bh

bh.initialize_sw()
epochs = bh.get_global_last_daily_epochs(60000.0, 7)
for epoch in epochs:
    print(f"Epoch: {epoch}")

See Also