Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sdc
kis_tools
Commits
e881033b
Commit
e881033b
authored
Mar 25, 2021
by
Carl Schaffer
Browse files
Merge branch 'translation_fixes' into 'master'
Translation fixes See merge request
!187
parents
e167a900
b02ceaa7
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
kis_tools/gris/GrisFitsFile.py
View file @
e881033b
...
...
@@ -173,23 +173,32 @@ class GrisFitsFile(FitsFile):
raise
ValueError
(
f
'Cannot determine reference pixel for coordinates! SLITCNTR is
{
self
[
"SLITCNTR"
]
}
instead of scancntr'
)
#
Transform to HPC (shift by telescope centering, rotate by p0 angle)
#
Get telescope centering and associated uncertainties. Centering is the driving factor for uncertainties
delta_x
,
delta_y
,
std_delta_x
,
std_delta_y
=
self
.
telescope_centering
# If uncertainties are too large, use ML model to correct the coordinates
from
kis_tools.gris.coord_correction_ml
import
coord_model_stdx
,
coord_model_stdy
if
std_delta_x
>
coord_model_stdx
or
std_delta_y
>
coord_model_stdy
:
try
:
x_hpc
,
y_hpc
,
std_delta_x
,
std_delta_y
=
get_coords_ml
(
self
)
except
ValueError
as
e
:
logger
.
warning
(
f
"Error in finding ML coords for
{
self
.
__repr__
()
}
:
{
e
}
"
)
# Point to slitpos with 1 solar disk uncertainty if coord retrieval didn't work
x_hpc
,
y_hpc
,
std_delta_x
,
std_delta_y
=
x_slitcenter
,
y_slitcenter
,
\
gris_uncertainty_no_center_x
,
gris_uncertainty_no_center_y
try
:
p0_angle
=
self
.
p0_angle
except
ValueError
:
logger
.
warning
(
ValueError
)
p0_angle
=
None
if
p0_angle
is
not
None
:
from
kis_tools.gris.coord_correction_ml
import
coord_model_stdx
,
coord_model_stdy
if
std_delta_x
>
coord_model_stdx
or
std_delta_y
>
coord_model_stdy
:
try
:
x_hpc
,
y_hpc
,
std_delta_x
,
std_delta_y
=
get_coords_ml
(
self
)
except
ValueError
as
e
:
logger
.
warning
(
f
"Error in finding ML coords for
{
self
.
__repr__
()
}
:
{
e
}
"
)
# Point to slitpos with 1 solar disk uncertainty if coord retrieval didn't work
x_hpc
,
y_hpc
,
std_delta_x
,
std_delta_y
=
x_slitcenter
,
y_slitcenter
,
\
gris_uncertainty_no_center_x
,
gris_uncertainty_no_center_y
else
:
x_hpc
,
y_hpc
=
telescope_to_hpc
(
x_slitcenter
,
y_slitcenter
,
p0_angle
,
delta_x
,
delta_y
)
else
:
x_hpc
,
y_hpc
=
telescope_to_hpc
(
x_slitcenter
,
y_slitcenter
,
self
.
p0_angle
,
delta_x
,
delta_y
)
# if p0 is broken, only do centering correction
x_hpc
,
y_hpc
=
x_slitcenter
-
delta_x
,
y_slitcenter
-
delta_y
# Try determining orientation, use 0 if not possible
try
:
angle
=
self
.
slit_orientation
except
ValueError
as
e
:
...
...
@@ -233,11 +242,10 @@ class GrisFitsFile(FitsFile):
"""
Returns:array(float) shape (2,len(slit)) helioprojective coordinates in arcsecnd along slit
"""
try
:
coords
=
self
.
_coords_from_wcs
except
AssertionError
:
if
self
.
old_header
:
coords
=
self
.
_coords_from_simple_header
else
:
coords
=
self
.
_coords_from_wcs
return
coords
@
property
...
...
@@ -510,7 +518,7 @@ class GrisFitsFile(FitsFile):
assert
(
not
self
.
old_header
),
f
"Can't get coordinates from
{
self
.
path
}
! Run header conversion first!"
),
f
"Can't get coordinates from
{
self
.
path
}
using WCS-method
! Run header conversion first!"
wcs
=
WCS
(
self
.
header
)
pixel_shape
=
wcs
.
pixel_shape
...
...
kis_tools/tests/test_util.py
View file @
e881033b
...
...
@@ -7,6 +7,7 @@ from glob import glob
from
os
import
makedirs
from
os.path
import
join
,
exists
from
pathlib
import
Path
from
random
import
shuffle
from
shutil
import
rmtree
from
unittest.mock
import
patch
...
...
@@ -112,10 +113,14 @@ class TestUtil(unittest.TestCase):
self
.
assertTrue
(
exists
(
folder
))
def
test_groupby_function
(
self
):
testlist
=
range
(
20
)
result
=
util
.
groupby_function
(
testlist
,
lambda
x
:
x
%
3
)
testlist
=
list
(
range
(
20
))
sortfunc
=
lambda
x
:
x
%
3
result
=
util
.
groupby_function
(
testlist
,
sortfunc
)
self
.
assertEqual
(
len
(
result
),
3
,
"groupby function returned false length"
)
self
.
assertTrue
(
all
([
x
%
3
==
0
for
x
in
result
[
0
]]))
self
.
assertTrue
(
all
([
sortfunc
(
x
)
==
0
for
x
in
result
[
0
]]))
shuffle
(
testlist
)
result_shuffled
=
util
.
groupby_function
(
testlist
,
sortfunc
)
self
.
assertTrue
(
all
(
set
(
result
[
k
])
==
set
(
result_shuffled
[
k
])
for
k
in
result
),
"shuffled result differs!"
)
def
test_gris_run_number
(
self
):
gris_files
=
test_data
.
gris
...
...
kis_tools/util/util.py
View file @
e881033b
...
...
@@ -334,7 +334,8 @@ def groupby_function(list_in, function=lambda x: x):
characteristic as a key
"""
res
=
{}
for
k
,
g
in
groupby
(
list_in
,
function
):
sorted_input
=
sorted
(
list_in
,
key
=
function
)
for
k
,
g
in
groupby
(
sorted_input
,
function
):
res
[
k
]
=
list
(
g
)
# Store group iterator as a list
return
res
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment