Skip to content

Commit f6b4a88

Browse files
authored
Fix typo in coordinate lookup for grid shadowing (#156)
* Fix typo in coordiante lookup for grid shadowing * Switch grid shadowing to use SkyCoords
1 parent 55f895c commit f6b4a88

File tree

5 files changed

+29
-17
lines changed

5 files changed

+29
-17
lines changed

changelog/156.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix typo in `~stixpy.calibration.visibility.create_meta_pixels` which cased error if grid shadow correction was enabled. Also update grid calculations to use `Skycoord` objects.

stixpy/calibration/grid.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
__all__ = ["get_grid_transmission", "_calculate_grid_transmission"]
1212

13+
from stixpy.coordinates.frames import STIXImaging
1314

14-
def get_grid_transmission(xy_flare):
15+
16+
def get_grid_transmission(flare_location: STIXImaging):
1517
r"""
1618
Return the grid transmission for the 32 sub-collimators corrected for internal shadowing.
1719
@@ -20,11 +22,8 @@ def get_grid_transmission(xy_flare):
2022
2123
Parameters
2224
----------
23-
xy_flare
24-
25-
Returns
26-
-------
27-
25+
flare_location :
26+
Location of the flare
2827
"""
2928
column_names = ["sc", "p", "o", "phase", "slit", "grad", "rms", "thick", "bwidth", "bpitch"]
3029

@@ -33,10 +32,8 @@ def get_grid_transmission(xy_flare):
3332
front = Table.read(grid_info / "grid_param_front.txt", format="ascii", names=column_names)
3433
rear = Table.read(grid_info / "grid_param_rear.txt", format="ascii", names=column_names)
3534

36-
xy_flare_stix = np.array([xy_flare[0].value, xy_flare[1].value]) * u.arcsec
37-
38-
transmission_front = _calculate_grid_transmission(front, xy_flare_stix)
39-
transmission_rear = _calculate_grid_transmission(rear, xy_flare_stix)
35+
transmission_front = _calculate_grid_transmission(front, flare_location)
36+
transmission_rear = _calculate_grid_transmission(rear, flare_location)
4037
total_transmission = transmission_front * transmission_rear
4138

4239
# The finest grids are made from multiple layers for the moment remove these and set 1
@@ -49,15 +46,15 @@ def get_grid_transmission(xy_flare):
4946
return final_transmission
5047

5148

52-
def _calculate_grid_transmission(grid_params, xy_flare_stix):
49+
def _calculate_grid_transmission(grid_params, flare_location):
5350
r"""
5451
Calculate grid transmission accounting for internal shadowing.
5552
5653
Parameters
5754
----------
5855
grid_params
5956
Grid parameter tables
60-
xy_flare_stix
57+
flare_location
6158
Position of flare in stix imaging frame
6259
6360
Returns
@@ -68,7 +65,7 @@ def _calculate_grid_transmission(grid_params, xy_flare_stix):
6865
pitch = grid_params["p"]
6966
slit = grid_params["slit"]
7067
thick = grid_params["thick"]
71-
flare_dist = np.abs(xy_flare_stix[0] * np.cos(orient)) + xy_flare_stix[1] * np.sin(orient)
68+
flare_dist = np.abs(flare_location.Tx * np.cos(orient)) + flare_location.Ty * np.sin(orient)
7269
shadow_width = thick * np.tan(flare_dist)
7370
transmission = (slit - shadow_width) / pitch
7471
return transmission

stixpy/calibration/tests/test_grid.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import astropy.units as u
22
import numpy as np
33
import pytest
4+
from astropy.coordinates import SkyCoord
45

56
from stixpy.calibration.grid import get_grid_transmission
7+
from stixpy.coordinates.frames import STIXImaging
68

79

810
# Output values taken from IDL routine
911
@pytest.mark.parametrize(
1012
"input,out",
1113
[
1214
(
13-
[0, 0] * u.arcsec,
15+
SkyCoord(*[0, 0] * u.arcsec, frame=STIXImaging),
1416
[
1517
[
1618
0.38359416,
@@ -49,7 +51,7 @@
4951
],
5052
),
5153
(
52-
[0, 500.0] * u.arcsec,
54+
SkyCoord(*[0, 500.0] * u.arcsec, frame=STIXImaging),
5355
[
5456
0.38119361,
5557
0.23916472,

stixpy/calibration/tests/test_visibility.py

+12
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ def test_create_meta_pixels_timebins(flare_cpd):
137137
assert_quantity_allclose(np.sum(flare_cpd.duration[0:3]), meta_pixels["time_range"].dt.to(u.s))
138138

139139

140+
def test_create_meta_pixels_shadow(flare_cpd):
141+
energy_range = [6, 12] * u.keV
142+
time_range = [flare_cpd.times[0], flare_cpd.times[2]]
143+
create_meta_pixels(
144+
flare_cpd,
145+
time_range=time_range,
146+
energy_range=energy_range,
147+
flare_location=STIXImaging(0 * u.arcsec, 0 * u.arcsec),
148+
no_shadowing=False,
149+
)
150+
151+
140152
@pytest.mark.parametrize(
141153
"pix_set, real_comp",
142154
[

stixpy/calibration/visibility.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ def create_meta_pixels(
196196

197197
if not no_shadowing:
198198
if not isinstance(flare_location, STIXImaging) and flare_location.obstime != time_range.center:
199-
roll, solo_heeq, stix_pointing = get_hpc_info(time_range.start, time_range.stop)
199+
roll, solo_heeq, stix_pointing = get_hpc_info(time_range.start, time_range.end)
200200
flare_location = flare_location.transform_to(STIXImaging(obstime=time_range.center, observer=solo_heeq))
201-
grid_shadowing = get_grid_transmission(flare_location.xyz[::-1])
201+
grid_shadowing = get_grid_transmission(flare_location)
202202
ct_summed = ct_summed / grid_shadowing.reshape(-1, 1) / 4 # transmission grid ~ 0.5*0.5 = .25
203203
ct_error_summed = ct_error_summed / grid_shadowing.reshape(-1, 1) / 4
204204

0 commit comments

Comments
 (0)