Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-pipeline
csst_common
Commits
7fd23f1e
Commit
7fd23f1e
authored
Oct 27, 2025
by
BO ZHANG
🏀
Browse files
add add_meta_to_table
parent
a9d66645
Pipeline
#11000
failed with stage
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
csst_common/io.py
View file @
7fd23f1e
...
@@ -21,6 +21,7 @@ from copy import deepcopy
...
@@ -21,6 +21,7 @@ from copy import deepcopy
from
typing
import
Optional
from
typing
import
Optional
from
astropy.io
import
fits
from
astropy.io
import
fits
from
astropy
import
table
from
.time
import
now
from
.time
import
now
...
@@ -332,3 +333,27 @@ def get_proc_info(**kwargs):
...
@@ -332,3 +333,27 @@ def get_proc_info(**kwargs):
cards
.
append
((
k
,
v
,
""
))
cards
.
append
((
k
,
v
,
""
))
header
=
fits
.
Header
(
cards
=
cards
)
header
=
fits
.
Header
(
cards
=
cards
)
return
reformat_header
(
header
,
comment
=
"PROCESSING INFORMATION"
)
return
reformat_header
(
header
,
comment
=
"PROCESSING INFORMATION"
)
def
add_meta_to_table
(
t
:
table
.
Table
,
meta
:
dict
)
->
table
.
Table
:
"""Add meta information to a table.
Parameters
----------
t : Table
Table.
meta : dict
Meta information.
"""
# determine number of rows
n_rows
=
len
(
t
)
# extract subset of meta information
sub_meta
=
{
"healpix"
:
meta
[
"healpix"
],
"data_uuid"
:
meta
[
"data_uuid"
],
}
# create meta table
t_meta
=
table
.
Table
([
sub_meta
]
*
n_rows
,
dtype
=
(
"i4"
,
"U36"
))
# add meta columns to table
t
.
add_columns
(
t_meta
.
columns
)
return
t
tests/test_io.py
View file @
7fd23f1e
...
@@ -13,6 +13,7 @@ import os
...
@@ -13,6 +13,7 @@ import os
import
unittest
import
unittest
from
astropy.io
import
fits
from
astropy.io
import
fits
from
astropy
import
table
from
csst_common.io
import
(
from
csst_common.io
import
(
append_header
,
append_header
,
...
@@ -22,6 +23,7 @@ from csst_common.io import (
...
@@ -22,6 +23,7 @@ from csst_common.io import (
generate_meta
,
generate_meta
,
append_meta
,
append_meta
,
extract_meta
,
extract_meta
,
add_meta_to_table
,
)
)
...
@@ -143,3 +145,9 @@ class TestFitsHeaderOps(unittest.TestCase):
...
@@ -143,3 +145,9 @@ class TestFitsHeaderOps(unittest.TestCase):
self
.
assertIn
(
"META"
,
set
(
hdulist
[
0
].
header
.
keys
()))
self
.
assertIn
(
"META"
,
set
(
hdulist
[
0
].
header
.
keys
()))
meta
=
extract_meta
(
hdulist
)
meta
=
extract_meta
(
hdulist
)
self
.
assertEqual
(
meta
[
"obs_id"
],
"123456"
)
self
.
assertEqual
(
meta
[
"obs_id"
],
"123456"
)
def
test_add_meta_to_table
(
self
):
t
=
table
.
Table
([{
"a"
:
1
,
"b"
:
2
}]
*
5
)
meta
=
generate_meta
(
obs_id
=
"123456"
)
t
=
add_meta_to_table
(
t
,
meta
)
self
.
assertEqual
(
set
(
t
.
colnames
),
(
"a"
,
"b"
,
"healpix"
,
"data_uuid"
))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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