Skip to main content

Field-Aligned Current Python toolkit for SWARM satellite analysis

Project description

facpy: Field-Aligned Current Python Toolkit

PyPI version License: MIT

facpy is a research-grade Python package designed for standardized, fast, and reproducible analysis of Swarm satellite Field-Aligned Currents (FAC). It is optimized for quiet-time studies, regional analysis (e.g., Africa), and interhemispheric comparisons.

🚀 Key Features

  • Data Loading: Efficient loading of Swarm Level 2 FAC data (CDF and NetCDF formats) into Polars DataFrames.
  • Quiet Time Selection: Automatic selection of quietest days based on Kp (sum/max) or Dst (min) geomagnetic indices.
  • Geospacial Tools:
    • Region-based filtering (presets for Africa, Europe, Polar Caps, etc.).
    • Solar Local Time (SLT) calculation.
    • Hemisphere separation.
  • Gridding: Fast aggregation of point data into regular 2D (Lat/Lon) or 3D (Lat/Lon/LT) grids using vectorization.
  • Interhemispheric Analysis (IHFAC): Tools to compare Northern and Southern hemisphere currents (Difference, Ratio) with automatic coordinate alignment.
  • Visualization: Publication-ready map generation using cartopy.

📦 Installation

facpy requires Python 3.9+.

# Install from PyPI
pip install facpy

# Or install from source
git clone https://github.com/madvirus-ops/facpy
cd facpy
pip install .

# Install with development dependencies
pip install ".[dev]"

⚡ Quick Start

Here is a complete workflow example demonstrating loading, filtering, gridding, and mapping.

import facpy
from facpy import io, quiet, geo, grid, plot
import polars as pl

# 1. Load Data
# Supports single file or list of files (CDF/NetCDF)
df = io.load_swarm_fac("SW_OPER_FAC_A_20210101.cdf")

# 2. Select Quiet Days
# Get the 5 quietest days in Jan 2021 based on Kp index
quiet_dates = quiet.quiet_days(
    start_date="2021-01-01", 
    end_date="2021-01-31", 
    method="kp", 
    top_n=5,
    index_file="kp_index.txt" # Path to your index file
)

# Filter dataframe
df = df.filter(pl.col("timestamp").dt.date().is_in(quiet_dates))

# 3. Filter Region & Add Local Time
# Focus on Africa and calculate Solar Local Time
df_africa = geo.filter_region(df, region="africa")
df_africa = geo.add_local_time(df_africa)

# 4. Grid the Data
# Create a 2°x2° grid of Mean FAC values
ds_grid = grid.grid_fac(
    df_africa, 
    resolution=(2.0, 2.0), 
    statistic="mean"
)

# 5. Plot
# Generate a map using built-in Cartopy plotter
plot.fac_map(
    ds_grid, 
    title="Quiet Time Mean FAC - Africa", 
    projection="platecarree"
)

📚 Module Overview

facpy.io

Handles file I/O.

  • load_swarm_fac(): Reads data, handles fill values, and normalizes column names.

facpy.quiet

Geomagnetic activity selection.

  • quiet_days(): Returns dates of low activity defined by Kp or Dst.

facpy.geo

Coordinate and spatial tools.

  • filter_region(): Spatial subsetting.
  • add_local_time(): Computes SLT from UTC and Longitude.

facpy.grid

Aggregation logic.

  • grid_fac(): Converts track data to xarray.Dataset grids. Supports multiple statistics (mean, median, std, count).

facpy.ihfac

Interhemispheric analysis.

  • compare(): Aligns South hemisphere data to North coordinates and computes difference or ratio maps.

facpy.plot

Visualization.

  • fac_map(): Wrapper around Cartopy for quick, consistent FAC maps.

🧪 Testing

Run the test suite to ensure everything is working correctly:

pytest tests/

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

facpy-0.1.1.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

facpy-0.1.1-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file facpy-0.1.1.tar.gz.

File metadata

  • Download URL: facpy-0.1.1.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for facpy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3f8412155ab5877e141b79ef5cdd99454a2f8cda952df9003c9dc51c58062d66
MD5 bca423d636bcbf41dd2df02412c5c33e
BLAKE2b-256 70d71d32ff5f5fcc0fdd80161f9656dfbdd078f08156af0ecdcf1084af114385

See more details on using hashes here.

File details

Details for the file facpy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: facpy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for facpy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df4c01b0bbd3fa11502ebd02ac733d0422d6ce539bf042df87562ecb7ac1018d
MD5 8ac8d50b47e62a397cd51a49246ec6c4
BLAKE2b-256 79353fca59baeab5523eb5114d1b18f459e2b32478ae119b75923515ca9ab7c7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page