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
c68c1b0e
Commit
c68c1b0e
authored
Oct 11, 2021
by
Carl Schaffer
Browse files
improving wavelength retrieval from filename, adding test
parent
ce2c3409
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
kis_tools/bbi/bbi_header.py
View file @
c68c1b0e
...
...
@@ -10,12 +10,12 @@ import yaml
from
astropy.io
import
fits
from
sunpy.coordinates.sun
import
earth_distance
from
kis_tools.bbi.util
import
get_bbi_wl
from
kis_tools.generic.settings
import
settings
from
kis_tools.
bbi.util
import
get_
wl
from
kis_tools.
generic.settings.settings
import
get_
settings
from
kis_tools.interface
import
BasicArgParser
from
kis_tools.util.util
import
setup_outdir
from
.bbi_sort_observations
import
get_obs_info
from
kis_tools.generic.settings.settings
import
get_settings
from
..util.util
import
add_history
,
date_from_fn
from
..util.util
import
get_filter
...
...
@@ -412,7 +412,7 @@ def run_bbi_header_conversion(args):
new_header
=
convert_bbi_header
(
infile
,
)
wl
=
get_wl
(
new_header
[
"FILENAME"
])
wl
=
get_
bbi_
wl
(
new_header
[
"FILENAME"
])
out_dir
=
join
(
out_folder
,
new_header
[
"POINT_ID"
]
+
f
"_WL
{
wl
}
"
)
setup_outdir
(
out_dir
)
...
...
kis_tools/bbi/plot_utils.py
View file @
c68c1b0e
...
...
@@ -4,7 +4,7 @@ from itertools import groupby
from
os.path
import
join
,
basename
from
pprint
import
pprint
from
kis_tools.bbi.util
import
get_wl
from
kis_tools.bbi.util
import
get_
bbi_
wl
from
kis_tools.util.util
import
merge_to_gif
,
gif_to_mp4
...
...
@@ -18,8 +18,8 @@ def bbi_gen_gif(folder):
if
not
files
:
continue
files
.
sort
(
key
=
get_wl
)
grouped
=
groupby
(
files
,
get_wl
)
files
.
sort
(
key
=
get_
bbi_
wl
)
grouped
=
groupby
(
files
,
get_
bbi_
wl
)
for
group
,
grouped_files
in
grouped
:
grouped_files
=
list
(
grouped_files
)
...
...
kis_tools/bbi/util.py
View file @
c68c1b0e
import
re
def
get_wl
(
fn
):
"""Extract wavelength from string"""
return
int
(
re
.
search
(
r
"WL(\d+)"
,
fn
).
group
(
1
))
class
NoWavelengthError
(
Exception
):
pass
def
get_bbi_wl
(
fn
):
"""Extract wavelength from string formatted as WL656 indicating 656nm wavelenght.
Returns: wavelength in nm
"""
match
=
re
.
search
(
r
"WL(\d+)"
,
fn
)
if
not
match
:
raise
NoWavelengthError
(
f
"Could not determine wavelength from
{
fn
}
, expeced a wavelength format like 'WLXXX'"
)
return
int
(
match
.
group
(
1
))
kis_tools/tests/test_bbi.py
View file @
c68c1b0e
...
...
@@ -9,6 +9,7 @@ from pprint import pprint
from
unittest
import
TestCase
from
kis_tools.bbi.bbi_header
import
get_generic_header
from
kis_tools.bbi.util
import
get_bbi_wl
,
NoWavelengthError
from
kis_tools.generic.settings.settings
import
get_settings
...
...
@@ -21,3 +22,11 @@ class TestBBI(TestCase):
def
test_bbi_header
(
self
):
header
=
get_generic_header
()
pprint
(
header
)
def
test_get_wl
(
self
):
working_teststrings
=
[
"20170522_003_WL854"
,
"bbi_20170523-092204_001_WL589_location_preview.png"
,
]
for
ts
in
working_teststrings
:
self
.
assertIsInstance
(
get_bbi_wl
(
ts
),
int
)
error_teststrings
=
[
"20170522_003_WLABC"
,
"bbi_20170523-092204_001_location_preview.png"
,
]
for
ts
in
error_teststrings
:
self
.
assertRaises
(
NoWavelengthError
,
get_bbi_wl
,
ts
)
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