Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
5dc14555
Commit
5dc14555
authored
Jun 08, 2018
by
Chris Shallue
Committed by
Christopher Shallue
Jun 14, 2018
Browse files
Actually handle single-segment / multi-segment inputs correctly.
PiperOrigin-RevId: 199887920
parent
120bc915
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
30 deletions
+44
-30
research/astronet/light_curve_util/util.py
research/astronet/light_curve_util/util.py
+2
-8
research/astronet/light_curve_util/util_test.py
research/astronet/light_curve_util/util_test.py
+42
-22
No files found.
research/astronet/light_curve_util/util.py
View file @
5dc14555
...
@@ -59,11 +59,8 @@ def split(all_time, all_flux, gap_width=0.75):
...
@@ -59,11 +59,8 @@ def split(all_time, all_flux, gap_width=0.75):
out_time: List of numpy arrays; the split time arrays.
out_time: List of numpy arrays; the split time arrays.
out_flux: List of numpy arrays; the split flux arrays.
out_flux: List of numpy arrays; the split flux arrays.
"""
"""
all_time
=
np
.
array
(
all_time
)
all_flux
=
np
.
array
(
all_flux
)
# Handle single-segment inputs.
# Handle single-segment inputs.
if
all_time
.
ndim
==
1
:
if
isinstance
(
all_time
,
np
.
ndarray
)
and
all_time
.
ndim
==
1
:
all_time
=
[
all_time
]
all_time
=
[
all_time
]
all_flux
=
[
all_flux
]
all_flux
=
[
all_flux
]
...
@@ -101,11 +98,8 @@ def remove_events(all_time, all_flux, events, width_factor=1.0):
...
@@ -101,11 +98,8 @@ def remove_events(all_time, all_flux, events, width_factor=1.0):
output_flux: Numpy array or list of numpy arrays; the flux arrays with
output_flux: Numpy array or list of numpy arrays; the flux arrays with
events removed.
events removed.
"""
"""
all_time
=
np
.
array
(
all_time
)
all_flux
=
np
.
array
(
all_flux
)
# Handle single-segment inputs.
# Handle single-segment inputs.
if
all_time
.
ndim
==
1
:
if
isinstance
(
all_time
,
np
.
ndarray
)
and
all_time
.
ndim
==
1
:
all_time
=
[
all_time
]
all_time
=
[
all_time
]
all_flux
=
[
all_flux
]
all_flux
=
[
all_flux
]
single_segment
=
True
single_segment
=
True
...
...
research/astronet/light_curve_util/util_test.py
View file @
5dc14555
...
@@ -65,43 +65,63 @@ class LightCurveUtilTest(absltest.TestCase):
...
@@ -65,43 +65,63 @@ class LightCurveUtilTest(absltest.TestCase):
self
.
assertSequenceAlmostEqual
(
expected
,
tfold
)
self
.
assertSequenceAlmostEqual
(
expected
,
tfold
)
def
testSplit
(
self
):
def
testSplit
(
self
):
# Single segment.
all_time
=
np
.
concatenate
([
np
.
arange
(
0
,
1
,
0.1
),
np
.
arange
(
1.5
,
2
,
0.1
)])
all_flux
=
np
.
ones
(
15
)
# Gap width 0.5.
split_time
,
split_flux
=
util
.
split
(
all_time
,
all_flux
,
gap_width
=
0.5
)
self
.
assertLen
(
split_time
,
2
)
self
.
assertLen
(
split_flux
,
2
)
self
.
assertSequenceAlmostEqual
(
np
.
arange
(
0
,
1
,
0.1
),
split_time
[
0
])
self
.
assertSequenceAlmostEqual
(
np
.
ones
(
10
),
split_flux
[
0
])
self
.
assertSequenceAlmostEqual
(
np
.
arange
(
1.5
,
2
,
0.1
),
split_time
[
1
])
self
.
assertSequenceAlmostEqual
(
np
.
ones
(
5
),
split_flux
[
1
])
# Multi segment.
all_time
=
[
all_time
=
[
np
.
concatenate
([
np
.
concatenate
([
np
.
arange
(
0
,
1
,
0.1
),
np
.
arange
(
0
,
1
,
0.1
),
np
.
arange
(
1.5
,
2
,
0.1
),
np
.
arange
(
1.5
,
2
,
0.1
),
np
.
arange
(
3
,
4
,
0.1
)
np
.
arange
(
3
,
4
,
0.1
)
])
]),
np
.
arange
(
4
,
5
,
0.1
)
]
]
all_flux
=
[
np
.
array
([
1
]
*
25
)]
all_flux
=
[
np
.
ones
(
25
),
np
.
ones
(
10
)]
self
.
assertEqual
(
len
(
all_time
),
2
)
self
.
assertEqual
(
len
(
all_time
[
0
]),
25
)
self
.
assertEqual
(
len
(
all_time
[
1
]),
10
)
self
.
assertEqual
(
len
(
all_flux
),
2
)
self
.
assertEqual
(
len
(
all_flux
[
0
]),
25
)
self
.
assertEqual
(
len
(
all_flux
[
1
]),
10
)
# Gap width 0.5.
# Gap width 0.5.
split_time
,
split_flux
=
util
.
split
(
all_time
,
all_flux
,
gap_width
=
0.5
)
split_time
,
split_flux
=
util
.
split
(
all_time
,
all_flux
,
gap_width
=
0.5
)
self
.
assertLen
(
split_time
,
3
)
self
.
assertLen
(
split_time
,
4
)
self
.
assertLen
(
split_flux
,
3
)
self
.
assertLen
(
split_flux
,
4
)
self
.
assertSequenceAlmostEqual
(
self
.
assertSequenceAlmostEqual
(
np
.
arange
(
0
,
1
,
0.1
),
split_time
[
0
])
[
0.
,
0.1
,
0.2
,
0.3
,
0.4
,
0.5
,
0.6
,
0.7
,
0.8
,
0.9
],
split_time
[
0
])
self
.
assertSequenceAlmostEqual
(
np
.
ones
(
10
),
split_flux
[
0
])
self
.
assertSequenceAlmostEqual
([
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
],
self
.
assertSequenceAlmostEqual
(
np
.
arange
(
1.5
,
2
,
0.1
),
split_time
[
1
])
split_flux
[
0
])
self
.
assertSequenceAlmostEqual
(
np
.
ones
(
5
),
split_flux
[
1
])
self
.
assertSequenceAlmostEqual
([
1.5
,
1.6
,
1.7
,
1.8
,
1.9
],
split_time
[
1
])
self
.
assertSequenceAlmostEqual
(
np
.
arange
(
3
,
4
,
0.1
),
split_time
[
2
])
self
.
assertSequenceAlmostEqual
([
1
,
1
,
1
,
1
,
1
],
split_flux
[
1
])
self
.
assertSequenceAlmostEqual
(
np
.
ones
(
10
),
split_flux
[
2
])
self
.
assertSequenceAlmostEqual
(
self
.
assertSequenceAlmostEqual
(
np
.
arange
(
4
,
5
,
0.1
),
split_time
[
3
])
[
3.
,
3.1
,
3.2
,
3.3
,
3.4
,
3.5
,
3.6
,
3.7
,
3.8
,
3.9
],
split_time
[
2
])
self
.
assertSequenceAlmostEqual
(
np
.
ones
(
10
),
split_flux
[
3
])
self
.
assertSequenceAlmostEqual
([
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
],
split_flux
[
2
])
# Gap width 1.0.
# Gap width 1.0.
split_time
,
split_flux
=
util
.
split
(
all_time
,
all_flux
,
gap_width
=
1
)
split_time
,
split_flux
=
util
.
split
(
all_time
,
all_flux
,
gap_width
=
1
)
self
.
assertLen
(
split_time
,
2
)
self
.
assertLen
(
split_time
,
3
)
self
.
assertLen
(
split_flux
,
2
)
self
.
assertLen
(
split_flux
,
3
)
self
.
assertSequenceAlmostEqual
([
self
.
assertSequenceAlmostEqual
([
0.
,
0.1
,
0.2
,
0.3
,
0.4
,
0.5
,
0.6
,
0.7
,
0.8
,
0.9
,
1.5
,
1.6
,
1.7
,
1.8
,
1.9
0.
,
0.1
,
0.2
,
0.3
,
0.4
,
0.5
,
0.6
,
0.7
,
0.8
,
0.9
,
1.5
,
1.6
,
1.7
,
1.8
,
1.9
],
split_time
[
0
])
],
split_time
[
0
])
self
.
assertSequenceAlmostEqual
(
self
.
assertSequenceAlmostEqual
(
np
.
ones
(
15
),
split_flux
[
0
])
[
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
],
split_flux
[
0
])
self
.
assertSequenceAlmostEqual
(
np
.
arange
(
3
,
4
,
0.1
),
split_time
[
1
])
self
.
assertSequenceAlmostEqual
(
self
.
assertSequenceAlmostEqual
(
np
.
ones
(
10
),
split_flux
[
1
])
[
3.
,
3.1
,
3.2
,
3.3
,
3.4
,
3.5
,
3.6
,
3.7
,
3.8
,
3.9
],
split_time
[
1
])
self
.
assertSequenceAlmostEqual
(
np
.
arange
(
4
,
5
,
0.1
),
split_time
[
2
])
self
.
assertSequenceAlmostEqual
([
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
],
self
.
assertSequenceAlmostEqual
(
np
.
ones
(
10
),
split_flux
[
2
])
split_flux
[
1
])
def
testRemoveEvents
(
self
):
def
testRemoveEvents
(
self
):
time
=
np
.
arange
(
20
,
dtype
=
np
.
float
)
time
=
np
.
arange
(
20
,
dtype
=
np
.
float
)
...
...
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