Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
chaincodes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PRESAGE
chaincodes
Commits
04ef7e6d
Commit
04ef7e6d
authored
2 years ago
by
Jay Paul Morgan
Browse files
Options
Downloads
Patches
Plain Diff
Blacken code
parent
2e38c457
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
chaincodes/chaincodes.py
+68
-47
68 additions, 47 deletions
chaincodes/chaincodes.py
with
68 additions
and
47 deletions
chaincodes/chaincodes.py
+
68
−
47
View file @
04ef7e6d
...
...
@@ -37,9 +37,8 @@ def chaincode_to_skycoord(cc, smap):
def
feature_to_skycoord
(
x
,
y
,
cc
,
cdelt1
,
cdelt2
,
obs_time
):
return
chaincode_to_skycoord
(
feature_to_chaincode
(
x
,
y
,
cc
,
cdelt1
,
cdelt2
),
obs_time
)
feature_to_chaincode
(
x
,
y
,
cc
,
cdelt1
,
cdelt2
),
obs_time
)
def
feature_df_to_skycoords
(
feature_df
,
smap
)
->
tuple
[
SkyCoord
]:
...
...
@@ -58,22 +57,32 @@ def feature_df_to_skycoords(feature_df, smap) -> tuple[SkyCoord]:
cdelt2
=
[
1
]
*
len
(
feature_df
)
return
dfp
.
tmap
(
lambda
r
:
rotate_skycoord_to_map
(
chaincode_to_skycoord
(
r
[
0
],
r
[
1
]),
smap
),
zip
(
dfp
.
tmap
(
lambda
r
:
feature_to_chaincode
(
*
r
),
zip
(
x
,
y
,
c
,
cdelt1
,
cdelt2
)),
smaps
))
zip
(
dfp
.
tmap
(
lambda
r
:
feature_to_chaincode
(
*
r
),
zip
(
x
,
y
,
c
,
cdelt1
,
cdelt2
)),
smaps
,
),
)
def
rotate_skycoord_to_map
(
skycoord
:
Union
[
SkyCoord
,
List
[
SkyCoord
]],
smap
:
sunpy
.
map
.
Map
)
->
SkyCoord
:
def
rotate_skycoord_to_map
(
skycoord
:
Union
[
SkyCoord
,
List
[
SkyCoord
]],
smap
:
sunpy
.
map
.
Map
)
->
SkyCoord
:
if
isinstance
(
skycoord
,
(
tuple
,
list
)):
if
len
(
skycoord
)
==
0
:
return
[]
return
[
rotate_skycoord_to_map
(
dfp
.
first
(
skycoord
),
smap
)]
+
rotate_skycoord_to_map
(
dfp
.
rest
(
skycoord
),
smap
)
return
[
rotate_skycoord_to_map
(
dfp
.
first
(
skycoord
),
smap
)
]
+
rotate_skycoord_to_map
(
dfp
.
rest
(
skycoord
),
smap
)
return
rotate_skycoord_to_time
(
skycoord
,
timestamp
=
smap
.
date
)
def
rotate_skycoord_to_time
(
skycoord
:
SkyCoord
,
timestamp
:
astropy
.
time
.
Time
)
->
SkyCoord
:
def
rotate_skycoord_to_time
(
skycoord
:
SkyCoord
,
timestamp
:
astropy
.
time
.
Time
)
->
SkyCoord
:
warnings
.
resetwarnings
()
with
warnings
.
catch_warnings
():
warnings
.
simplefilter
(
'
ignore
'
)
warnings
.
simplefilter
(
"
ignore
"
)
sk
=
solar_rotate_coordinate
(
skycoord
,
time
=
timestamp
)
return
sk
...
...
@@ -134,7 +143,9 @@ def infill_outline(outline: np.ndarray) -> np.ndarray:
def
diff
(
a
,
which
=
"
horizontal
"
):
if
which
==
"
both
"
:
return
((
diff
(
a
,
which
=
"
horizontal
"
)
+
diff
(
a
,
which
=
"
vertical
"
))
>
0.0
).
astype
(
np
.
float64
)
return
((
diff
(
a
,
which
=
"
horizontal
"
)
+
diff
(
a
,
which
=
"
vertical
"
))
>
0.0
).
astype
(
np
.
float64
)
out
=
np
.
zeros_like
(
a
)
for
row_idx
in
range
(
1
,
a
.
shape
[
0
]):
...
...
@@ -176,19 +187,20 @@ def skycoord_to_mask(skycoord: astropy.coordinates.SkyCoord, smap: sunpy.map.Map
def
skycoords_to_mask
(
skycoords
:
Union
[
tuple
[
SkyCoord
],
list
[
SkyCoord
]],
smap
:
sunpy
.
map
.
Map
skycoords
:
Union
[
tuple
[
SkyCoord
],
list
[
SkyCoord
]],
smap
:
sunpy
.
map
.
Map
)
->
np
.
ndarray
:
return
reduce
(
lambda
t
,
x
:
skycoord_to_mask
(
x
,
smap
)
+
t
,
dfp
.
rest
(
skycoords
),
skycoord_to_mask
(
dfp
.
first
(
skycoords
),
smap
))
skycoord_to_mask
(
dfp
.
first
(
skycoords
),
smap
),
)
def
feature_df_to_mask
(
feature_df
,
smap
):
pipeline
=
dfp
.
compose
(
lambda
df
:
feature_df_to_skycoords
(
df
,
smap
),
lambda
sk
:
skycoords_to_mask
(
sk
,
smap
))
lambda
sk
:
skycoords_to_mask
(
sk
,
smap
),
)
return
pipeline
(
feature_df
)
...
...
@@ -210,20 +222,30 @@ def build_chain(outline: np.ndarray) -> dict[str, Any]:
graph
.
add_edge
(
xy
,
n
)
code
=
[]
chain
=
reduce
(
lambda
t
,
x
:
x
if
len
(
x
)
>
len
(
t
)
else
t
,
chain
=
reduce
(
lambda
t
,
x
:
x
if
len
(
x
)
>
len
(
t
)
else
t
,
networkx
.
chain_decomposition
(
graph
),
next
(
iter
(
networkx
.
chain_decomposition
(
graph
))))
next
(
iter
(
networkx
.
chain_decomposition
(
graph
))),
)
for
link
in
chain
:
last_x
,
last_y
=
link
[
0
]
xi
,
yi
=
link
[
1
]
if
xi
-
last_x
==
1
and
yi
-
last_y
==
0
:
code
.
append
(
"
6
"
)
if
xi
-
last_x
==
1
and
yi
-
last_y
==
1
:
code
.
append
(
"
5
"
)
if
xi
-
last_x
==
0
and
yi
-
last_y
==
1
:
code
.
append
(
"
4
"
)
if
xi
-
last_x
==
-
1
and
yi
-
last_y
==
1
:
code
.
append
(
"
3
"
)
if
xi
-
last_x
==
-
1
and
yi
-
last_y
==
0
:
code
.
append
(
"
2
"
)
if
xi
-
last_x
==
-
1
and
yi
-
last_y
==
-
1
:
code
.
append
(
"
1
"
)
if
xi
-
last_x
==
0
and
yi
-
last_y
==
-
1
:
code
.
append
(
"
0
"
)
if
xi
-
last_x
==
1
and
yi
-
last_y
==
-
1
:
code
.
append
(
"
7
"
)
if
xi
-
last_x
==
1
and
yi
-
last_y
==
0
:
code
.
append
(
"
6
"
)
if
xi
-
last_x
==
1
and
yi
-
last_y
==
1
:
code
.
append
(
"
5
"
)
if
xi
-
last_x
==
0
and
yi
-
last_y
==
1
:
code
.
append
(
"
4
"
)
if
xi
-
last_x
==
-
1
and
yi
-
last_y
==
1
:
code
.
append
(
"
3
"
)
if
xi
-
last_x
==
-
1
and
yi
-
last_y
==
0
:
code
.
append
(
"
2
"
)
if
xi
-
last_x
==
-
1
and
yi
-
last_y
==
-
1
:
code
.
append
(
"
1
"
)
if
xi
-
last_x
==
0
and
yi
-
last_y
==
-
1
:
code
.
append
(
"
0
"
)
if
xi
-
last_x
==
1
and
yi
-
last_y
==
-
1
:
code
.
append
(
"
7
"
)
return
{
"
cc_x_pix
"
:
chain
[
0
][
1
][
0
],
...
...
@@ -258,4 +280,3 @@ def mask_to_chaincode(mask: np.ndarray, smap: sunpy.map.Map) -> pd.DataFrame:
df
.
loc
[
row_idx
,
"
cc_y_arcsec
"
]
=
y
df
[
"
date_obs
"
]
=
smap
.
date
.
strftime
(
"
%Y-%m-%dT%H:%M:%S
"
)
# isoformat
return
df
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment