pyampp.gxbox.boxutils

Functions

serialize_sav_index_header(→ str)

Convert an IDL FITSHEAD2STRUCT-like INDEX record into FITS header text.

compute_vertical_current(→ numpy.ndarray)

extract_sav_refmaps(→ list[tuple[int, str, ...)

Extract GX/IDL BOX.REFMAPS into ordered HDF5-style payloads.

remap_vertical_current_inputs(→ tuple[sunpy.map.Map, ...)

Remap Bx/By/Bz onto an IDL-like reference WCS before current-density evaluation.

map_from_data_header_compat(→ sunpy.map.Map)

Build a SunPy map while enforcing unit sanitation and GX-compatible RSUN_REF.

load_sunpy_map_compat(path_or_data[, header])

Load a SunPy map while tolerating IDL-style escaped FITS unit strings.

observer_ephemeris_from_map(→ tuple[dict[str, ...)

observer_ephemeris_from_fits_file(→ tuple[dict[str, ...)

observer_ephemeris_from_sav_file(→ tuple[dict[str, ...)

observer_ephemeris_from_reference_file(...)

observer_reference_details_from_file(→ dict[str, str])

normalize_observer_metadata(→ dict)

hmi_disambig(azimuth_map, disambig_map[, method])

Combine HMI disambiguation result with azimuth.

hmi_b2ptr(map_field, map_inclination, map_azimuth)

Converts the magnetic field components from SDO/HMI

validate_number(func)

Decorator to validate if the input in the widget is a number.

set_QLineEdit_text_pos(line_edit, text)

Sets the text of the QLineEdit and moves the cursor to the beginning.

read_gxsim_b3d_sav(savfile)

Read B3D data from a .sav file and save it as a .gxbox file.

read_b3d_h5(filename)

Read B3D data from an HDF5 file and populate a dictionary.

write_b3d_h5(filename, box_b3d)

Write B3D data to an HDF5 file from a dictionary.

update_line_seeds_h5(filename, line_seeds)

Update only the line_seeds group in an existing HDF5 model file.

Module Contents

pyampp.gxbox.boxutils.serialize_sav_index_header(index: Any) str[source]

Convert an IDL FITSHEAD2STRUCT-like INDEX record into FITS header text.

SAV entry boxes can carry INDEX as a restored IDL struct instead of a plain header string. Stringifying that struct produces an unusable Python tuple repr. This serializer reconstructs a standard FITS-style header payload so HDF5 outputs remain consumable by downstream FITS/WCS readers.

pyampp.gxbox.boxutils.compute_vertical_current(b0: numpy.ndarray, b1: numpy.ndarray, b2: numpy.ndarray, wcs_header: str, rsun_arcsec: float, crpix1: float | None = None, crpix2: float | None = None, cdelt1_arcsec: float | None = None, cdelt2_arcsec: float | None = None) numpy.ndarray[source]
pyampp.gxbox.boxutils.extract_sav_refmaps(box: Any) list[tuple[int, str, numpy.ndarray, str]][source]

Extract GX/IDL BOX.REFMAPS into ordered HDF5-style payloads.

pyampp.gxbox.boxutils.remap_vertical_current_inputs(map_bx: sunpy.map.Map, map_by: sunpy.map.Map, map_bz: sunpy.map.Map, *, pad_factor: float = 1.1, algorithm: str = 'exact') tuple[sunpy.map.Map, sunpy.map.Map, sunpy.map.Map][source]

Remap Bx/By/Bz onto an IDL-like reference WCS before current-density evaluation.

The legacy IDL path first remaps the vector-field cutout onto a dedicated reference WCS that is slightly larger than the selected box footprint, then runs the current-density kernel on that remapped patch. Using the same preconditioning here is safer than changing the kernel math itself.

pyampp.gxbox.boxutils.map_from_data_header_compat(data, header) sunpy.map.Map[source]

Build a SunPy map while enforcing unit sanitation and GX-compatible RSUN_REF.

pyampp.gxbox.boxutils.load_sunpy_map_compat(path_or_data, header=None)[source]

Load a SunPy map while tolerating IDL-style escaped FITS unit strings.

If a direct Map(path) fails due to unit parsing, this falls back to opening the FITS file, sanitizing unit-like header fields, and building the map from (data, header).

pyampp.gxbox.boxutils.observer_ephemeris_from_map(source_map) tuple[dict[str, float | str], tuple[str, Ellipsis]][source]
pyampp.gxbox.boxutils.observer_ephemeris_from_fits_file(path: str | bytes | os.PathLike[str]) tuple[dict[str, float | str], tuple[str, Ellipsis]][source]
pyampp.gxbox.boxutils.observer_ephemeris_from_sav_file(path: str | bytes | os.PathLike[str]) tuple[dict[str, float | str], tuple[str, Ellipsis]][source]
pyampp.gxbox.boxutils.observer_ephemeris_from_reference_file(path: str | bytes | os.PathLike[str]) tuple[dict[str, float | str], tuple[str, Ellipsis]][source]
pyampp.gxbox.boxutils.observer_reference_details_from_file(path: str | bytes | os.PathLike[str]) dict[str, str][source]
pyampp.gxbox.boxutils.normalize_observer_metadata(box_b3d: dict) dict[source]
pyampp.gxbox.boxutils.hmi_disambig(azimuth_map, disambig_map, method=2)[source]

Combine HMI disambiguation result with azimuth.

Parameters:
  • azimuth_map (sunpy.map.Map) – sunpy.map.Map, The azimuth map.

  • disambig_map (sunpy.map.Map) – sunpy.map.Map, The disambiguation map.

  • method (int, optional) – int, Method index (0: potential acute, 1: random, 2: radial acute). Default is 2.

Returns:

map_azimuth: sunpy.map.Map, The azimuth map with disambiguation applied.

Return type:

sunpy.map.Map

pyampp.gxbox.boxutils.hmi_b2ptr(map_field, map_inclination, map_azimuth)[source]

Converts the magnetic field components from SDO/HMI data from field strength, inclination, and azimuth into components of the magnetic field in the local heliographic coordinate system (B_phi, B_theta, B_r).

This function transforms the magnetic field vector in the local (xi, eta, zeta) system to the heliographic (phi, theta, r) system. The transformation accounts for the observer’s position and orientation relative to the Sun.

Parameters:
  • map_fieldsunpy.map.Map, The magnetic field strength map from HMI, given in Gauss.

  • map_inclinationsunpy.map.Map, The magnetic field inclination angle map from HMI, in degrees, where 0 degrees is parallel to the radial direction.

  • map_azimuthsunpy.map.Map, The magnetic field azimuth angle map from HMI, in degrees, measured counterclockwise from the north in the plane perpendicular to the radial direction.

Returns:

tuple, A tuple containing the three magnetic field component maps in the heliographic coordinate system:

  • map_bp (sunpy.map.Map): The magnetic field component in the phi direction (B_phi).

  • map_bt (sunpy.map.Map): The magnetic field component in the theta direction (B_theta).

  • map_br (sunpy.map.Map): The magnetic field component in the radial direction (B_r).

Example:

# Load the HMI field, inclination, and azimuth maps
map_field = sunpy.map.Map('hmi_field.fits')
map_inclination = sunpy.map.Map('hmi_inclination.fits')
map_azimuth = sunpy.map.Map('hmi_azimuth.fits')

# Convert to heliographic coordinates
map_bp, map_bt, map_br = hmi_b2ptr(map_field, map_inclination, map_azimuth)
pyampp.gxbox.boxutils.validate_number(func)[source]

Decorator to validate if the input in the widget is a number.

Parameters:

func – function, The function to wrap.

Returns:

function , The wrapped function.

pyampp.gxbox.boxutils.set_QLineEdit_text_pos(line_edit, text)[source]

Sets the text of the QLineEdit and moves the cursor to the beginning.

Parameters:
  • line_edit – QLineEdit, The QLineEdit widget.

  • text – str, The text to set.

pyampp.gxbox.boxutils.read_gxsim_b3d_sav(savfile)[source]

Read B3D data from a .sav file and save it as a .gxbox file.

Parameters:

savfile – str, The path to the .sav file.

pyampp.gxbox.boxutils.read_b3d_h5(filename)[source]

Read B3D data from an HDF5 file and populate a dictionary.

The resulting dictionary will contain keys corresponding to different magnetic field models (e.g., ‘corona’ for coronal fields and ‘chromo’ for chromospheric fields), and each model will have sub-keys for the magnetic field components (e.g., ‘bx’, ‘by’, ‘bz’).

Parameters:

filename – str, The path to the HDF5 file.

Returns:

dict, A dictionary containing the B3D data.

Example:

b3dbox = read_b3d_h5('path_to_file.h5')

# Get the coronal field components
bx_cor = b3dbox['corona']['bx']
by_cor = b3dbox['corona']['by']
bz_cor = b3dbox['corona']['bz']
pyampp.gxbox.boxutils.write_b3d_h5(filename, box_b3d)[source]

Write B3D data to an HDF5 file from a dictionary.

Parameters:
  • filename – str, The path to the HDF5 file.

  • box_b3d – dict, A dictionary containing the B3D data to be written.

pyampp.gxbox.boxutils.update_line_seeds_h5(filename, line_seeds)[source]

Update only the line_seeds group in an existing HDF5 model file.

Parameters:
  • filename (str) – Target .h5 model path.

  • line_seeds (dict | None) – Serialized line_seeds payload. If falsy/non-dict, any existing line_seeds group is removed.