Transform spherical coordinates as it is done in KIT's CORSIKA.
Project description
A python package to transform the representations of pointings. It adopts the naming and definitions of KIT’s CORSIKA. The transformations support both scalar and array-like in- and outputs, as in numpy. Only free floating functions. No custom classes or structures.
Install
pip install spherical_coordinates
Transformations
CORSIKA uses mainly two representations for directions in three dimensional space. First, the azimuth-zenith representation, and second cartesian direction vectors of length 1.
The azimuth-zenith representation uses two floats (azimuth_rad and zenith_rad). The cartesian vector uses three floats (cx, cy, and cz).
In equations within CORSIKA’s documents, the azimuth angle is represented by greek letter Phi and the zenith angle is represented by greek letter Theta. Here, we use CORSIKA’s explicit names ‘azimuth’ and ‘zenith’ as they are used in the text body of e.g. CORSIKA’s manual.
import spherical_coordinates
cx, cy, cz = spherical_coordinates.az_zd_to_cx_cy_cz(
azimuth_rad=0.2,
zenith_rad=0.3,
)
print(cx, cy, cz)
0.28962947762551555 0.058710801693826566 0.955336489125606
az, zd = spherical_coordinates.cx_cy_cz_to_az_zd(cx=cx, cy=cy, cz=cz)
print(az, zd)
0.20000000000000015 0.30000000000000016
Hemisphere in positive Z
Often, CORSIKA assumes that all directions point above the x-y plane in what case it neglects the Z-component. For example this is the case in the output files for particles or Cherenkov photons where only (cx and cy) are given. To not always restore the missing cz component manually, there are transformations for this limited, but unfortunately common case. I suspect CORSIKA omitted the cz to reduce storage space. For new projects, I would not recommand this.
import spherical_coordinates
cx, cy = spherical_coordinates.az_zd_to_cx_cy(
azimuth_rad=0.2,
zenith_rad=0.3,
)
print(cx, cy, cz)
0.28962947762551555 0.058710801693826566
az, zd = spherical_coordinates.cx_cy_to_az_zd(cx=cx, cy=cy)
print(az, zd)
0.20000000000000015 0.30000000000000016
However, for pointings below the x-y plane this will fail:
import spherical_coordinates
zenith_below_xy_plane_rad = 2.0
cx, cy = spherical_coordinates.az_zd_to_cx_cy(
azimuth_rad=0.2,
zenith_rad=zenith_below_xy_plane_rad,
)
az, zd = spherical_coordinates.cx_cy_to_az_zd(cx=cx, cy=cy)
print(zd)
1.1415926535897933
# zd is now the projection into the upper hemisphere
To restore cz there is:
import spherical_coordinates
cz = spherical_coordinates.restore_cz(cx=0.1, cy=0.2)
print(cz)
what assumes the lengths is 1.0:
Angles Between
Quickly estimate the angle between two pointings.
import spherical_coordinates
delta = spherical_coordinates.angle_between_cx_cy_cz(
cx1=0.5, cy1=0.5, cz1=0.7071, cx2=0.7071, cy2=0.0, cz2=0.7071
)
print(delta*180/3.14159, "DEG")
31.399818557245204 DEG
delta = spherical_coordinates.angle_between_cx_cy(
cx1=0.5, cy1=0.5, cx2=0.7071, cy2=0.0
)
print(delta*180/3.14159, "DEG")
31.399818557245204 DEG
delta = spherical_coordinates.angle_between_az_zd(
azimuth1_rad=1.2, zenith1_rad=0.2, azimuth2_rad=-0.5, zenith2_rad=0.7
)
print(delta*180/3.14159, "DEG")
42.852624700439804 DEG
Azimuth Range
From my experience, some parts in CORSIKA expect the azimuth angle to be in the so called ‘least absolute residue’. This is:
For this spherical_coordinates has a range limiter:
import spherical_coordinates
az = spherical_coordinates.azimuth_range(azimuth_rad=123.4)
print(az*180/3.1415, "DEG")
-129.7046334064967 DEG
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for spherical_coordinates-0.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8d0499f1ad733840d531d63ab3a303ea64e6c227449ec4cd1a5838e284c7cc1 |
|
MD5 | 24785b9861a379a9c13d5002c8380820 |
|
BLAKE2b-256 | 625d71c954a77cf9a95fe0dd2889504b977cd8ad204a89257b0e6b6ea259910f |
Hashes for spherical_coordinates-0.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0bb0c714e14bfc6bc203f61558348a70aec8ff041f539e7e7888dfb2e839470 |
|
MD5 | eec5591635eb24bfe072850c0d1dd88a |
|
BLAKE2b-256 | bf472a567da1cc042f9c1a69a1550e5e34709e258a4be38dfceddfa545862fb3 |