Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Astropy Time #2691

Merged
merged 218 commits into from Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 198 commits
Commits
Show all changes
218 commits
Select commit Hold shift + click to select a range
96488ce
subclass astropy Time to add strftime and strptime
vn-ki May 1, 2018
5080aad
Return astropy time for strings and utime
vn-ki May 1, 2018
0729839
parse_time: astropy Time and tuple
vn-ki May 2, 2018
9d0863e
parse_time changes
vn-ki May 2, 2018
55b6ec9
parse_time changes: np.array, np.datetime64
vn-ki May 2, 2018
64d5ae6
Support out format and scale in parse_time
vn-ki May 2, 2018
27eb887
Fix time.day_of_year
vn-ki May 4, 2018
bfb3a95
Make requested changes
vn-ki May 6, 2018
81af04c
Introduce format keyword for parse_time
vn-ki May 9, 2018
40f3433
Pass kwargs to Time
vn-ki May 9, 2018
7440ea1
Clean up parse_time
vn-ki May 9, 2018
d1903cf
Write some tests for the new parse_time
vn-ki May 10, 2018
53539bb
Make parse_time support all kinds of tuples
vn-ki May 10, 2018
c9098a0
Fix date and datetime tests
vn-ki May 11, 2018
6ca4b65
Some more tests
vn-ki May 11, 2018
b25d1bb
Tests tests and tests
vn-ki May 11, 2018
5d03ed3
Test for leap second
vn-ki May 11, 2018
695ad06
Fix doc strings of parse_time
vn-ki May 12, 2018
d213079
More doc strings and remove unnecessery imports
vn-ki May 12, 2018
5fc72b0
Add a parse_time example
vn-ki May 12, 2018
572b018
Remove an old comment
vn-ki May 13, 2018
e364a8f
Make the example more sensible
vn-ki May 13, 2018
01ad55b
Add test job for things that have been ported to astropy Time
Cadair May 14, 2018
46c84b4
Format example better
vn-ki May 14, 2018
9f1de89
get that right
Cadair May 14, 2018
c1b8872
Minor example tweaks
vn-ki May 14, 2018
36942f6
Merge branch 'astropy-time' of https://github.com/vn-ki/sunpy into as…
vn-ki May 14, 2018
ecc024c
More example tweaks
vn-ki May 14, 2018
94d3ce9
Fix the whole of TimeRange(?)
vn-ki May 14, 2018
ff0182f
Fix julian
vn-ki May 14, 2018
ab1653f
Make sure we don't accidently pass unwanted keyword arguments to Time
vn-ki May 14, 2018
a313616
Some tweaks to test_time
vn-ki May 14, 2018
f4d7400
Make a relative import absolute
vn-ki May 16, 2018
b698c00
Update parse_time example
vn-ki May 16, 2018
cb760ed
Remove _time_string_parse_format
vn-ki May 16, 2018
4ad6f44
Take only keyword arguments for parse_time
vn-ki May 16, 2018
503dccd
Make a few changes
vn-ki May 17, 2018
1d4b5b2
Fix a doctest failure
vn-ki May 17, 2018
4e93519
docstring changes
vn-ki May 17, 2018
5885639
TimeRange is datetime free!!
vn-ki May 17, 2018
aedc778
Fix a mistake in split
vn-ki May 19, 2018
ae8d102
Add datetime timedelta support for timerange
vn-ki May 19, 2018
a33c228
Merge pull request #2611 from vn-ki/astropy-time
Cadair May 22, 2018
54394fb
Some stylistic fixes
vn-ki May 22, 2018
b9efe0f
Add tests and fix TimeDatetimeDelta.value
vn-ki May 23, 2018
b1795bf
Merge pull request #2638 from vn-ki/timerange-astropy-time
Cadair May 23, 2018
86b7aa0
datetime to Time: coordinates
vn-ki May 25, 2018
5c10f18
Fix one place in mapbase so that tests in coordinates pass
vn-ki May 25, 2018
a2e1085
Fix doctests
vn-ki May 25, 2018
ab21161
Merge remote-tracking branch 'upstream/master' into time
Cadair May 29, 2018
f591964
Merge remote-tracking branch 'upstream/master' into time
Cadair May 30, 2018
a4bab44
Fix attrs
vn-ki May 19, 2018
282bf4e
Continue fixing stuff in net
vn-ki May 19, 2018
6a119a0
Fix stuff inside net.dataretriever
vn-ki May 19, 2018
b40f89a
Fix util/scraper while I'm at it
vn-ki May 19, 2018
1d2e06e
Fixed instr/rhessi (?)
vn-ki May 19, 2018
148f5b1
Let's see how much this commit fixes
vn-ki May 19, 2018
6ebd952
Some more datetime to Time in scraper
vn-ki May 20, 2018
595f3ac
Some more test fixes
vn-ki May 20, 2018
4592221
Various datetime to astropy Time
vn-ki May 22, 2018
9e5f6e1
Fix a syntax error
vn-ki May 22, 2018
5b7d458
Fix tests
vn-ki May 22, 2018
8f48af5
Fix strategies
vn-ki May 25, 2018
616a2ac
Fix noaa.SRSClient
vn-ki May 25, 2018
96172e7
Add an import in net/vso/attrs
vn-ki May 25, 2018
589b18c
Make requested changes
vn-ki May 26, 2018
d6f221f
doctests
vn-ki May 30, 2018
ae5227f
Remove jsoc.Time because vsoTime does the same thing now
vn-ki May 31, 2018
5a723e4
Add leap second tests for vso
vn-ki May 31, 2018
695bc2f
Chenges to jsoc to use Time
vn-ki May 31, 2018
d9dc9b5
Transition physics to astropy Time
vn-ki Jun 1, 2018
8216744
doctests
vn-ki Jun 1, 2018
d5e3e21
Clean up convert input in framattributes
vn-ki Jun 1, 2018
5fabc78
Merge branch 'master' of github.com:sunpy/sunpy into time
nabobalis Jun 1, 2018
0e10a0a
updated circle.yml to fix merge issue
nabobalis Jun 1, 2018
9b18c3d
remove physics from astropy-time test on circle
vn-ki Jun 3, 2018
45558b3
Merge pull request #2648 from vn-ki/patch
Cadair Jun 3, 2018
830766c
Merge remote-tracking branch 'upstream/time' into net-astropy-time
vn-ki Jun 5, 2018
37aad52
Remove a use of datetime and fix tests
vn-ki Jun 5, 2018
4249a77
Make Times test leap seconds too
vn-ki Jun 5, 2018
fc400de
Merge branch 'time' into coordinates-time
vn-ki Jun 6, 2018
b4f42b0
Merge branch 'time' into physics-aptime
vn-ki Jun 6, 2018
9e9c1ed
Merge pull request #2641 from vn-ki/coordinates-time
Cadair Jun 6, 2018
f6e665d
Merge branch 'time' into physics-aptime
Cadair Jun 6, 2018
e0ed6ae
Merge pull request #2647 from vn-ki/physics-aptime
Cadair Jun 6, 2018
0ec5862
Trivial requested changes
vn-ki Jun 8, 2018
94fad86
Timeseries fixes.
vn-ki Jun 8, 2018
51e34f9
Fix a bug in metadata
vn-ki Jun 8, 2018
4c72677
Fix a bug in goes
vn-ki Jun 9, 2018
9846a01
Fix empty dataframe not handling in timeseries
vn-ki Jun 13, 2018
9e8fa8a
Fix up all tests (?)
vn-ki Jun 13, 2018
88c74c9
Merge branch 'time' into net-astropy-time
vn-ki Jun 13, 2018
626a70c
Let's fix the tests!!
vn-ki Jun 13, 2018
f2ff273
Merge pull request #2639 from vn-ki/net-astropy-time
Cadair Jun 13, 2018
3f104c3
Merge branch 'time' into timeserires
vn-ki Jun 13, 2018
9279fc2
Patch up instr/fermi
vn-ki Jun 13, 2018
dc2f055
Disable net in circle for now
vn-ki Jun 15, 2018
420e2c7
doctest fix
vn-ki Jun 19, 2018
5fbcdd2
Tests: datetime to astropy Time
vn-ki Jun 19, 2018
67367cc
Merge branch 'master' of github.com:sunpy/sunpy into HEAD
nabobalis Jun 20, 2018
707f1ae
added temp fix for sample data download to circle
nabobalis Jun 20, 2018
18ddc89
Merge pull request #2662 from nabobalis/time
nabobalis Jun 20, 2018
1fba4d2
Fix database stuff (astropy Time)
vn-ki May 17, 2018
1f58b55
Run online tests too
vn-ki May 18, 2018
c2dffc8
Fix the errors
vn-ki May 18, 2018
4cfe033
Disable net tests for now
vn-ki Jun 14, 2018
2223194
No Time in database
vn-ki Jun 15, 2018
9a13fe1
Fido datetime hack
vn-ki Jun 15, 2018
60aa1fb
Fix doctest failure on circle
vn-ki Jun 15, 2018
04cf32e
Remove useless function
vn-ki Jun 19, 2018
63c3301
update docs
vn-ki Jun 20, 2018
11bc83f
Fix up util scraper tests
vn-ki Jun 20, 2018
4438607
Some small changes
vn-ki Jun 20, 2018
4682687
Seperate circleci online tests
vn-ki Jun 20, 2018
f38857f
Merge pull request #2652 from vn-ki/database
Cadair Jun 20, 2018
9685d47
Merge remote-tracking branch 'upstream/time' into astropytime-util
vn-ki Jun 20, 2018
0b35ccc
util tests on circle
vn-ki Jun 20, 2018
970613b
Merge remote-tracking branch 'upstream/time' into timeserires
vn-ki Jun 20, 2018
652d6bb
Name return type correctly
vn-ki Jun 20, 2018
1c04a30
Most tests pass mysteriously!
vn-ki Jun 22, 2018
2b7cf63
Fix some .format s
vn-ki Jun 22, 2018
5be212f
fix a stupid doctest fail
vn-ki Jun 22, 2018
846deb0
datetime removals
vn-ki Jun 23, 2018
c307622
Merge pull request #2650 from vn-ki/timeserires
Cadair Jun 23, 2018
e2aa8cb
Merge branch 'time' into astropy-time-map
Cadair Jun 23, 2018
758dd0f
update sunpy.time function
vn-ki Jun 23, 2018
e9469a5
Merge branch 'astropy-time-map' of https://github.com/vn-ki/sunpy int…
vn-ki Jun 23, 2018
9dd6db6
roi tests on circle
vn-ki Jun 23, 2018
9785c44
Merge branch 'time' into datetime-removal
vn-ki Jun 23, 2018
a581ffd
Merge branch 'time' into astropytime-util
nabobalis Jun 25, 2018
55a0966
Update docs
vn-ki Jun 25, 2018
b3e6e10
Merge branch 'datetime-removal' of https://github.com/vn-ki/sunpy int…
vn-ki Jun 25, 2018
605adf0
Update circle config
vn-ki Jun 25, 2018
8a60318
DataFrame should not contain Time
vn-ki Jun 25, 2018
fdf58a4
Merge pull request #2664 from vn-ki/astropytime-util
Cadair Jun 27, 2018
677df3a
Merge pull request #2669 from vn-ki/astropy-time-map
Cadair Jun 27, 2018
48fe934
Merge remote-tracking branch 'upstream/master' into time
Cadair Jun 27, 2018
0d0f819
Merge branch 'removalmk2' into time
Cadair Jun 27, 2018
506f4f2
update circle config
vn-ki Jun 27, 2018
8b27338
Primary changes to instr
vn-ki Jun 20, 2018
2e0024f
Merge branch 'time' into datetime-removal
vn-ki Jun 27, 2018
c597001
minute goes and iris fix
vn-ki Jun 27, 2018
daea2eb
instr/goes obstime to Time
vn-ki Jun 27, 2018
35fb1fe
Merge pull request #2670 from vn-ki/datetime-removal
Cadair Jun 27, 2018
92aab3d
Merge branch 'time' into timeserires
Cadair Jun 27, 2018
46a80a0
Some pep8 cleaning in time.py
Cadair Jun 27, 2018
08b43b6
yapf test_goes
vn-ki Jun 27, 2018
0303867
Merge pull request #2675 from Cadair/time
Cadair Jun 27, 2018
0651b19
Merge pull request #2674 from vn-ki/timeserires
Cadair Jun 27, 2018
39e0f8f
instr/lyra Time changes
vn-ki Jun 27, 2018
dbcf533
Update circle config
vn-ki Jun 27, 2018
c327e53
instr/rhessi Time :)
vn-ki Jun 27, 2018
135c874
Conserve precision in goes and lyra timeseries
vn-ki Jun 27, 2018
68cbe49
Merge branch 'time' into astropy-time-instr
vn-ki Jun 27, 2018
eed7850
Requested changes
vn-ki Jun 28, 2018
cb0396a
More docstrings
vn-ki Jun 29, 2018
02b0665
More datetime to Time
vn-ki Jun 29, 2018
2d03a58
Make sure _prep_columns can handle both np.array and Time
vn-ki Jun 29, 2018
96f93b4
instr/lyra things doctest + lytaf Time fix
vn-ki Jun 29, 2018
68f62ab
tests and doctests fixed!!
vn-ki Jun 29, 2018
b816b9b
sun sun sun
vn-ki Jun 29, 2018
a354713
clean up
vn-ki Jun 29, 2018
0b9d0bc
Fix an should-not-happen goes bug and revert TimeDelta to_value on fermi
vn-ki Jun 29, 2018
ff3e2df
It's probably better to use datetime anyway
vn-ki Jun 30, 2018
81e984a
Fix _parse_hdus in rhessi
vn-ki Jun 30, 2018
2551dd3
norh dataframe should not contain Time
vn-ki Jun 30, 2018
bfc2e3d
Get those last two commits correctly
vn-ki Jun 30, 2018
d1523b0
All timeseries except eve are max precision
vn-ki Jul 4, 2018
add84a2
Merge pull request #2676 from vn-ki/astropy-time-instr
Cadair Jul 4, 2018
51db781
Merge branch 'master' of github.com:sunpy/sunpy into time
Cadair Jul 4, 2018
5143953
Merge remote-tracking branch 'upstream/master' into time
Cadair Jul 4, 2018
a38c0a9
datetime to astropy Time: examples
vn-ki Jul 1, 2018
797edbe
jsoc.attrs.Time from __all__
vn-ki Jul 4, 2018
61f38c1
Maybe fix a figure test
vn-ki Jul 4, 2018
5b258e6
Test for met_to_utc
vn-ki Jul 4, 2018
14ac139
More datetime to Time in docs
vn-ki Jul 6, 2018
9af3223
Time.plot_date in examples
vn-ki Jul 11, 2018
1a11e4d
update figure hash
vn-ki Jul 13, 2018
1b5fd15
Merge pull request #2679 from vn-ki/docs
nabobalis Jul 14, 2018
4e4ad00
Less datetime
vn-ki Jul 9, 2018
0804e5c
yapf noaa
vn-ki Jul 9, 2018
a3e8b96
more datetime removals
vn-ki Jul 18, 2018
aec23ef
Merge branch 'master' of github.com:sunpy/sunpy into time
Cadair Jul 19, 2018
04e7eb3
Abolish jsoc Time from sunpy land
vn-ki Jul 19, 2018
33cc2a0
add changelogs
vn-ki Jul 19, 2018
cbf123b
revert circle config
vn-ki Jul 19, 2018
f1ce634
one more changelog
vn-ki Jul 19, 2018
c8b8685
Merge pull request #2694 from vn-ki/changelogs-and-stuff
Cadair Jul 19, 2018
8f5c984
just correct a small error
vn-ki Jul 18, 2018
ed64333
Merge pull request #2692 from vn-ki/datetime-removal-mk2
Cadair Jul 25, 2018
55793e0
Merge branch 'master' of github.com:sunpy/sunpy into time
Cadair Jul 30, 2018
4f266e4
more docs
vn-ki Jul 30, 2018
0405d64
Merge pull request #2705 from vn-ki/docs
nabobalis Aug 11, 2018
4efc2ab
Merge branch 'master' of github.com:sunpy/sunpy into time
Cadair Aug 14, 2018
33d97e2
Merge branch 'master' of github.com:sunpy/sunpy into time
Cadair Sep 10, 2018
132f2dc
post merge test fixes
Cadair Sep 10, 2018
479c6af
Add the astropy dev tests
Cadair Sep 10, 2018
e87d599
comments from @vn-ki
Cadair Sep 10, 2018
7e7539a
Merge remote-tracking branch 'upstream/master' into fixes
vn-ki Oct 11, 2018
3a88f02
request changes: round 1
vn-ki Oct 11, 2018
bb90d40
request changes: round 2
vn-ki Oct 11, 2018
2b8b9b6
Merge pull request #2789 from vn-ki/fixes
Cadair Oct 11, 2018
0e9f691
depracate `julian_day`
vn-ki Oct 11, 2018
dd540fd
Merge pull request #2790 from vn-ki/fixes
Cadair Oct 11, 2018
01675c0
Merged in master.
nabobalis Nov 16, 2018
d8d24dd
doc tests
nabobalis Nov 16, 2018
ba3d457
all bar lyra tests
nabobalis Nov 16, 2018
44a9e49
vectorize some lines
nabobalis Nov 16, 2018
e4f4b35
doc updates
nabobalis Nov 20, 2018
5fed7bc
fix bugs in add_common_docstring
Cadair Nov 21, 2018
710c84b
do some serious auto formatting magic with parse_time
Cadair Nov 21, 2018
0445ba1
tidy up
Cadair Nov 21, 2018
ed30931
Merge pull request #2852 from Cadair/parse_time
nabobalis Nov 22, 2018
af08e2f
Merge branch 'master' into time
Cadair Dec 5, 2018
9760a8e
Remove astropy Time compatibility layer
Cadair Dec 12, 2018
97c1aea
update figure hashes to astropy 3.1
Cadair Dec 12, 2018
282b772
test try for 32bit
nabobalis Dec 12, 2018
e706cab
tidy up ci again
nabobalis Dec 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -209,3 +209,5 @@ docs/generated
docs/api/
# This is incase you run the figure tests
figure_test_images*

tags
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -80,7 +80,7 @@ matrix:
env: PYTHON_VERSION=3.6

- python: 3.6
stage: Cron tests
stage: Comprehensive tests
env: ASTROPY_VERSION='dev'

- python: 3.6
Expand Down
1 change: 1 addition & 0 deletions changelog/2611.breaking.rst
@@ -0,0 +1 @@
Make ``sunpy.time.parse_time`` return ``astropy.time.Time`` instead of ``datetime.datetime``.
1 change: 1 addition & 0 deletions changelog/2638.breaking.rst
@@ -0,0 +1 @@
The properties and methods of ``sunpy.time.TimeRange`` returns ``astropy.time.Time`` and ``astropy.time.TimeDelta`` instead of ``datetime.datetime`` and ``datetime.timedelta`` respectively.
1 change: 1 addition & 0 deletions changelog/2676.breaking.rst
@@ -0,0 +1 @@
`obstime` keyword param of ``sunpy.instr.goes._goes_lx`` takes a non-scalar ``astropy.time.Time`` object instead of ``np.array``. The precision of times contained in sunpy `timeseries` has been increased to 9 from 6.
1 change: 1 addition & 0 deletions changelog/2679.bugfix.rst
@@ -0,0 +1 @@
``sunpy.instr.fermi.met_to_utc`` now returns the correct utc time which takes into account the leap seconds that have passed.
1 change: 1 addition & 0 deletions changelog/2694.breaking.rst
@@ -0,0 +1 @@
Removed ``sunpy.net.jsoc.attrs.Time`` because it served the same purpose as ``sunpy.net.attrs.Time`` after the switch to ``astropy.time.Time``.
9 changes: 4 additions & 5 deletions docs/code_ref/coordinates.rst
Expand Up @@ -127,11 +127,10 @@ coordinates is::

>>> c = SkyCoord(0*u.arcsec, 0*u.arcsec, frame=frames.Helioprojective, obstime="2017-07-26")
>>> c
<SkyCoord (Helioprojective: obstime=2017-07-26 00:00:00, rsun=695508.0 km, observer=<HeliographicStonyhurst Coordinate (obstime=2017-07-26 00:00:00): (lon, lat, radius) in (deg, deg, AU)
(0., 5.31701821, 1.01567428)>): (Tx, Ty) in arcsec
<SkyCoord (Helioprojective: obstime=2017-07-26T00:00:00.000, rsun=695508.0 km, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty) in arcsec
(0., 0.)>
>>> c.transform_to(frames.HeliographicCarrington)
<SkyCoord (HeliographicCarrington: obstime=2017-07-26 00:00:00): (lon, lat, radius) in (deg, deg, km)
<SkyCoord (HeliographicCarrington: obstime=2017-07-26T00:00:00.000): (lon, lat, radius) in (deg, deg, km)
(283.99298362, 5.31701821, 695508.00000058)>

It is also possible to transform to any coordinate system implemented in Astropy. This can be used to find the position of the solar limb in AltAz equatorial coordinates::
Expand Down Expand Up @@ -258,14 +257,14 @@ If you want to obtain a un-realized coordinate frame corresponding to a
>>> from sunpy.data.sample import AIA_171_IMAGE # doctest: +REMOTE_DATA
>>> amap = sunpy.map.Map(AIA_171_IMAGE) # doctest: +REMOTE_DATA
>>> amap.observer_coordinate # doctest: +REMOTE_DATA
<SkyCoord (HeliographicStonyhurst: obstime=2011-06-07 06:33:02.770000): (lon, lat, radius) in (deg, deg, m)
<SkyCoord (HeliographicStonyhurst: obstime=2011-06-07T06:33:02.770000): (lon, lat, radius) in (deg, deg, m)
(0., 0.048591, 1.51846026e+11)>

which is equivalent to::

>>> from astropy.wcs.utils import wcs_to_celestial_frame # doctest: +REMOTE_DATA
>>> wcs_to_celestial_frame(amap.wcs) # doctest: +REMOTE_DATA
<Helioprojective Frame (obstime=2011-06-07 06:33:02.770000, rsun=696000000.0 m, observer=<HeliographicStonyhurst Coordinate (obstime=2011-06-07 06:33:02.770000): (lon, lat, radius) in (deg, deg, m)
<Helioprojective Frame (obstime=2011-06-07T06:33:02.770000, rsun=696000000.0 m, observer=<HeliographicStonyhurst Coordinate (obstime=2011-06-07 06:33:02.770000): (lon, lat, radius) in (deg, deg, m)
(0., 0.048591, 1.51846026e+11)>)>


Expand Down
2 changes: 1 addition & 1 deletion docs/code_ref/time.rst
Expand Up @@ -2,7 +2,7 @@ SunPy time
==========

The time submodule contains helpers for converting strings to Python
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
`datetime.datetime` objects and handling common operations on these objects. As
`astropy.time.Time` objects and handling common operations on these objects. As
well as this a `~sunpy.time.TimeRange` object is provided for representing a
period of time and performing operations on that range.

Expand Down
2 changes: 1 addition & 1 deletion docs/dev_guide/documentation.rst
Expand Up @@ -224,7 +224,7 @@ Example (:class:`sunpy.map.Map`) ::
----------
header : dict
A dictionary representation of the image header
date : datetime
date : `astropy.time.Time`
Image observation time
det : str
Detector name
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/acquiring_data/hek.rst
Expand Up @@ -336,7 +336,7 @@ HEK results and create the corresponding VSO query attributes.

>>> vso_query = hek2vso.translate_results_to_query(result[10:11]) # doctest: +REMOTE_DATA
>>> vso_query[0] # doctest: +REMOTE_DATA
[<Time(datetime.datetime(2011, 8, 9, 7, 22, 44), datetime.datetime(2011, 8, 9, 7, 28, 56), None)>, <Source('SDO')>, <Instrument('AIA')>, <Wavelength(193.0, 193.0, 'Angstrom')>]
[<Time(<Time object: scale='utc' format='isot' value=2011-08-09T07:22:44.000>, <Time object: scale='utc' format='isot' value=2011-08-09T07:28:56.000>, None)>, <Source('SDO')>, <Instrument('AIA')>, <Wavelength(193.0, 193.0, 'Angstrom')>]

This function allows users finer-grained control of VSO queries
generated from HEK results.
Expand Down
8 changes: 4 additions & 4 deletions docs/guide/roi.rst
Expand Up @@ -19,9 +19,9 @@ This creates an roi called result for the specific time range. Querying the newl
>>> result
SunPy Region-of-interest (ROI) object
-------------------------------------
Source: LYRA LYTAF
Start time: 2011-02-15T04:34:09
End time: 2011-02-15T04:48:21
Event description: UV occult.
Source: LYRA LYTAF
Start time: 2011-02-15 04:34:09.000
End time: 2011-02-15 04:48:21.000
Event description: UV occult.

Check out the code reference for the time range object for more information.
41 changes: 27 additions & 14 deletions docs/guide/time.rst
Expand Up @@ -16,29 +16,36 @@ SunPy builds upon its functionality.

Solar data is associated with a number of different time formats. SunPy provides a simple
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
parsing function which can deal with most every format that a user may encounter. Called
`sunpy.time.parse_time()`, this function takes a string as input and returns a datetime object.
`sunpy.time.parse_time()`, this function takes a string as input and returns a `~astropy.time.Time` object.
nabobalis marked this conversation as resolved.
Show resolved Hide resolved

Here are few examples of formats which `sunpy.time.parse_time()` accepts::

>>> from sunpy.time import parse_time
>>> parse_time('2007-05-04T21:08:12')
datetime.datetime(2007, 5, 4, 21, 8, 12)
<Time object: scale='utc' format='isot' value=2007-05-04T21:08:12.000>
>>> parse_time('2007/05/04T21:08:12')
datetime.datetime(2007, 5, 4, 21, 8, 12)
<Time object: scale='utc' format='isot' value=2007-05-04T21:08:12.000>
>>> parse_time('20070504T210812')
datetime.datetime(2007, 5, 4, 21, 8, 12)
<Time object: scale='utc' format='isot' value=2007-05-04T21:08:12.000>
>>> parse_time('2007-May-04 21:08:12')
datetime.datetime(2007, 5, 4, 21, 8, 12)
<Time object: scale='utc' format='isot' value=2007-05-04T21:08:12.000>
>>> parse_time('20070504_210812')
datetime.datetime(2007, 5, 4, 21, 8, 12)
<Time object: scale='utc' format='isot' value=2007-05-04T21:08:12.000>

Each of the above returns the same datetime object ``datetime.datetime(2007,
5, 4, 21, 8, 12)``. One of the most standard time formats used in solar
physics is the number of seconds since 1979 January 01. The parse_time
Each of the above returns the same `~astropy.time.Time` object ``<Time object: scale='utc' format='isot' value=2007-05-04T21:08:12.000>``. One of the most standard time formats used in solar
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
physics is the number of seconds since 1979 January 01 called ``utime``. The parse_time
function also accepts this as input, e.g.::

>>> parse_time(894316092.00000000)
datetime.datetime(2007, 5, 4, 21, 8, 12)
>>> parse_time(894316092.00000000, format='utime')
<Time object: scale='utc' format='utime' value=894316092.0>

`sunpy.time.parse_time` is a wrapper around `astropy.time.Time`. It supports a few more formats
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
than `~astropy.time.Time`, but the API is mostly the same. You can specify the format, scale, precision,
location and other arguments just as you would do with `~astropy.time.Time`. An example::

>>> times = ['1999-01-01T00:00:00.123456789', '2010-01-01T00:00:00']
>>> parse_time(times, format='isot', scale='tai')
<Time object: scale='tai' format='isot' value=['1999-01-01T00:00:00.123' '2010-01-01T00:00:00.000']>

All SunPy functions which require
time as an input sanitize the input using parse_time.
Expand All @@ -60,13 +67,19 @@ You can also pass the start and end times as a tuple: ::

This object makes use of parse_time() so it can accept a wide variety of time formats.
A time range object can also be created by providing a start time and a duration.
The duration must be provided as a `datetime.timedelta` object or
time-equivalent `astropy.units.Quantity`
The duration must be provided as a `~astropy.time.TimeDelta` or
time-equivalent `astropy.units.Quantity` or `datetime.timedelta` object
example: ::

>>> import astropy.units as u
>>> time_range = TimeRange('2010/03/04 00:10', 400 * u.second)

or: ::

>>> import astropy.units as u
>>> from astropy.time import TimeDelta
>>> time_range = TimeRange('2010/03/04 00:10', TimeDelta(400 * u.second))

or: ::

>>> from datetime import timedelta
Expand All @@ -77,7 +90,7 @@ get the time at the center of your interval or the length of your interval in mi
or days or seconds: ::

>>> time_range.center
datetime.datetime(2010, 3, 4, 0, 13, 20)
<Time object: scale='utc' format='isot' value=2010-03-04T00:13:20.000>
>>> time_range.minutes
<Quantity 6.66666667 min>
>>> time_range.days
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/tour.rst
Expand Up @@ -264,9 +264,9 @@ and times. Here is a short example: ::

# parsing a standard time strings
>>> sunpy.time.parse_time('2004/02/05 12:00')
datetime.datetime(2004, 2, 5, 12, 0)
<Time object: scale='utc' format='isot' value=2004-02-05T12:00:00.000>

# This returns a datetime object. All SunPy functions which require
# This returns a astropy.time.Time object. All SunPy functions which require
# time as an input sanitize the input using parse_time.
>>> sunpy.time.day_of_year('2004-Jul-05 12:00:02')
187.50002314814816
Expand All @@ -278,7 +278,7 @@ and times. Here is a short example: ::
# TimeRange objects are useful for representing ranges of time
>>> time_range = sunpy.time.TimeRange('2010/03/04 00:10', '2010/03/04 00:20')
>>> time_range.center
datetime.datetime(2010, 3, 4, 0, 15)
<Time object: scale='utc' format='isot' value=2010-03-04T00:15:00.000>

For more information about working with time in SunPy checkout the :doc:`time guide <time>`.

Expand Down
13 changes: 5 additions & 8 deletions docs/guide/units-coordinates.rst
Expand Up @@ -149,15 +149,14 @@ A SkyCoord object to represent a point on the Sun can then be created::
>>> c = SkyCoord(70*u.deg, -30*u.deg, obstime="2017-08-01",
... frame=frames.HeliographicStonyhurst)
>>> c
<SkyCoord (HeliographicStonyhurst: obstime=2017-08-01 00:00:00): (lon, lat, radius) in (deg, deg, km)
<SkyCoord (HeliographicStonyhurst: obstime=2017-08-01T00:00:00.000): (lon, lat, radius) in (deg, deg, km)
(70., -30., 695508.)>

This `~astropy.coordinates.SkyCoord` object can then be transformed to any
other coordinate frame defined either in Astropy or SunPy, for example::

>>> c.transform_to(frames.Helioprojective)
<SkyCoord (Helioprojective: obstime=2017-08-01 00:00:00, rsun=695508.0 km, observer=<HeliographicStonyhurst Coordinate (obstime=2017-08-01 00:00:00): (lon, lat, radius) in (deg, deg, AU)
(0., 5.78339799, 1.01496923)>): (Tx, Ty, distance) in (arcsec, arcsec, km)
<SkyCoord (Helioprojective: obstime=2017-08-01T00:00:00.000, rsun=695508.0 km, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty, distance) in (arcsec, arcsec, km)
(769.74997696, -498.75932128, 1.51668819e+08)>


Expand Down Expand Up @@ -191,8 +190,7 @@ one observer to a coordinate seen by another::

>>> hpc1.transform_to(frames.Helioprojective(observer="venus",
... obstime="2017-07-26"))
<SkyCoord (Helioprojective: obstime=2017-07-26 00:00:00, rsun=695508.0 km, observer=<HeliographicStonyhurst Coordinate (obstime=2017-07-26 00:00:00): (lon, lat, radius) in (deg, deg, AU)
(77.03547231, 3.17032536, 0.72510629)>): (Tx, Ty, distance) in (arcsec, arcsec, km)
<SkyCoord (Helioprojective: obstime=2017-07-26T00:00:00.000, rsun=695508.0 km, observer=<HeliographicStonyhurst Coordinate for 'venus'>): (Tx, Ty, distance) in (arcsec, arcsec, km)
(-1285.11970265, 106.17983302, 1.08317783e+08)>


Expand All @@ -208,15 +206,14 @@ constructed from the header information. This can be accessed using
>>> from sunpy.data.sample import AIA_171_IMAGE # doctest: +REMOTE_DATA
>>> m = sunpy.map.Map(AIA_171_IMAGE) # doctest: +REMOTE_DATA
>>> m.coordinate_frame # doctest: +REMOTE_DATA
<Helioprojective Frame (obstime=2011-06-07 06:33:02.770000, rsun=696000000.0 m, observer=<HeliographicStonyhurst Coordinate (obstime=2011-06-07 06:33:02.770000): (lon, lat, radius) in (deg, deg, m)
<Helioprojective Frame (obstime=2011-06-07T06:33:02.000.770000, rsun=696000000.0 m, observer=<HeliographicStonyhurst Coordinate (obstime=2011-06-07T06:33:02.770000): (lon, lat, radius) in (deg, deg, m)
(0., 0.048591, 1.51846026e+11)>)>

This can be used when creating a `~astropy.coordinates.SkyCoord` object to set
the coordinate system to that image::

>>> SkyCoord(100 * u.arcsec, 10*u.arcsec, frame=m.coordinate_frame) # doctest: +REMOTE_DATA
<SkyCoord (Helioprojective: obstime=2011-06-07 06:33:02.770000, rsun=696000000.0 m, observer=<HeliographicStonyhurst Coordinate (obstime=2011-06-07 06:33:02.770000): (lon, lat, radius) in (deg, deg, m)
(0., 0.048591, 1.51846026e+11)>): (Tx, Ty) in arcsec
<SkyCoord (Helioprojective: obstime=2011-06-07T06:33:02.770000, rsun=696000000.0 m, observer=<HeliographicStonyhurst Coordinate for 'earth'>): (Tx, Ty) in arcsec
(100., 10.)>

This `~astropy.coordinates.SkyCoord` object could then be used to plot a point
Expand Down
95 changes: 95 additions & 0 deletions examples/parse_time.py
@@ -0,0 +1,95 @@
"""
========================================
Parsing times with sunpy.time.parse_time
========================================

This is an example to show some possible usage of ``parse_time``.
``parse_time`` is a function that can be useful to create `~astropy.time.Time`
objects from various other time objects and strings.
"""
##############################################################################
# Import the required modules.
from datetime import datetime, date
import time

import numpy as np
import pandas

from sunpy.time import parse_time


##############################################################################
# Suppose you want to parse some strings, ``parse_time`` can do that.
t1 = parse_time('1995-12-31 23:59:60')

##############################################################################
# Of course you could do the same with `~astropy.time.Time`.
# But SunPy ``parse_time`` can parse even more formats of time strings.
# And as you see from the examples, thanks to `~astropy.time.Time`, ``parse_time``
# can handle leap seconds too.
t2 = parse_time('1995-Dec-31 23:59:60')


##############################################################################
# You can mention the scale of the time as a keyword parameter if you need.
# Similar to scale you can pass in any astropy Time compatible keywords to
# ``parse_time``. See all arguments
# `here: <http://docs.astropy.org/en/stable/time/#creating-a-time-object>`__
t3 = parse_time('2012:124:21:08:12', scale='tai')


##############################################################################
# Now that you are done with strings, let's see other type ``parse_time`` handles,
# tuples. `~astropy.time.Time` doesnot handle tuples but ``parse_time`` does.
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
t4 = parse_time((1998, 11, 14))
t5 = parse_time((2001, 1, 1, 12, 12, 12, 8899))

##############################################################################
# This also means that you can parse a ``time.struct_time``.
t6 = parse_time(time.localtime())

##############################################################################
# ``parse_time`` also parses ``datetime`` and ``date`` objects.
t7 = parse_time(datetime.now())
t8 = parse_time(date.today())


##############################################################################
# ``parse_time`` can return ``Time`` objects for ``pandas.Timestamp``, ``pandas.Series``
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
# and ``pandas.DatetimeIndex``.
t9 = parse_time(pandas.Timestamp(datetime(1966, 2, 3)))

t10 = parse_time(
pandas.Series([[datetime(2012, 1, 1, 0, 0),
datetime(2012, 1, 2, 0, 0)],
[datetime(2012, 1, 3, 0, 0),
datetime(2012, 1, 4, 0, 0)]]))

t11 = parse_time(
pandas.DatetimeIndex([
datetime(2012, 1, 1, 0, 0),
datetime(2012, 1, 2, 0, 0),
datetime(2012, 1, 3, 0, 0),
datetime(2012, 1, 4, 0, 0)
]))


##############################################################################
# ``parse_time`` can parse ``numpy.datetime64`` objects.
t12 = parse_time(np.datetime64('2014-02-07T16:47:51.008288123-0500'))
t13 = parse_time(
np.array(
['2014-02-07T16:47:51.008288123', '2014-02-07T18:47:51.008288123'],
dtype='datetime64'))

##############################################################################
# Parse time returns `~astropy.time.Time object for every parsable input that
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
# you give to it.
# ``parse_time`` can handle all formats that `~astropy.time.Time` can handle.
# That is,
# ['jd', 'mjd', 'decimalyear', 'unix', 'cxcsec', 'gps', 'plot_date', 'datetime',
# 'iso', 'isot', 'yday', 'fits', 'byear', 'jyear', 'byear_str', 'jyear_str']
# at the time of writing. This can be used by passing format keyword argument
# to ``parse_time``.
parse_time(1234.0, format='jd')
parse_time('B1950.0', format='byear_str')
2 changes: 1 addition & 1 deletion examples/plotting/finegrained_plot.py
Expand Up @@ -27,7 +27,7 @@
top_right = SkyCoord(800*u.arcsec, 700*u.arcsec, frame=aiamap.coordinate_frame)
aiamap_sub = aiamap.submap(bottom_left, top_right)

title_obsdate = '{:%Y-%b-%d %H:%M:%S}'.format(aiamap_sub.date)
title_obsdate = aiamap_sub.date.strftime('%Y-%b-%d %H:%M:%S')

###############################################################################
# The SunPy map peek method shows a helioprojective grid by default.
Expand Down
6 changes: 3 additions & 3 deletions examples/plotting/overplot_hek_polygon.py
Expand Up @@ -11,13 +11,13 @@

from __future__ import print_function, division

from datetime import timedelta
import numpy as np

import matplotlib.pyplot as plt

import astropy.units as u
from astropy.coordinates import SkyCoord
from astropy.time import TimeDelta

import sunpy.map
import sunpy.data.sample
Expand All @@ -40,8 +40,8 @@
##############################################################################
# Look for coronal holes detected using the SPoCA feature recognition method:

start_time = aia_map.date - timedelta(hours=2)
end_time = aia_map.date + timedelta(hours=2)
start_time = aia_map.date - TimeDelta(2*u.hour)
end_time = aia_map.date + TimeDelta(2*u.hour)
responses = hek_client.search(hek.attrs.Time(start_time, end_time),
hek.attrs.CH, hek.attrs.FRM.Name == 'SPoCA')

Expand Down