forked from MAVENSDC/PyTplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
125 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,54 @@ | ||
# Copyright 2018 Regents of the University of Colorado. All Rights Reserved. | ||
# Released under the MIT license. | ||
# This software was developed at the University of Colorado's Laboratory for Atmospheric and Space Physics. | ||
# Verify current version before use at: https://github.com/MAVENSDC/PyTplot | ||
|
||
from . import time_double | ||
from .xlim import xlim | ||
import logging | ||
|
||
def timespan(t1, dt, keyword='days'): | ||
|
||
def timespan(t1, dt, keyword="days"): | ||
""" | ||
This function will set the time range for all time series plots. This is a wrapper for the function "xlim" to | ||
better handle time axes. | ||
Parameters: | ||
t1 : flt/str | ||
The time to start all time series plots. Can be given in seconds since epoch, or as a string | ||
in the format "YYYY-MM-DD HH:MM:SS" | ||
dt : flt | ||
The time duration of the plots. Default is number of days. | ||
keyword : str | ||
Sets the units of the "dt" variable. Days, hours, minutes, and seconds are all accepted. | ||
Returns: | ||
None | ||
Examples: | ||
>>> # Set the timespan to be 2017-07-17 00:00:00 plus 1 day | ||
>>> import pytplot | ||
>>> pytplot.timespan(1500249600, 1) | ||
>>> # The same as above, but using different inputs | ||
>>> pytplot.timespan("2017-07-17 00:00:00", 24, keyword='hours') | ||
This function will set the time range for all time series plots. This is a wrapper for the function "xlim" to | ||
better handle time axes. | ||
Parameters | ||
---------- | ||
t1 : float or str | ||
The time to start all time series plots. Can be given in seconds since epoch, or as a string | ||
in the format "YYYY-MM-DD HH:MM:SS". | ||
dt : float | ||
The time duration of the plots. Default is number of days. | ||
keyword : str, optional | ||
Sets the units of the "dt" variable. Days, hours, minutes, and seconds are all accepted. Default is 'days'. | ||
Returns | ||
------- | ||
None | ||
Examples | ||
-------- | ||
>>> # Set the timespan to be 2017-07-17 00:00:00 plus 1 day | ||
>>> import pytplot | ||
>>> pytplot.timespan(1500249600, 1) | ||
>>> # The same as above, but using different inputs | ||
>>> pytplot.timespan("2017-07-17 00:00:00", 24, keyword='hours') | ||
""" | ||
if keyword == 'days': | ||
|
||
if keyword == "days": | ||
dt *= 86400 | ||
elif keyword == 'hours': | ||
elif keyword == "hours": | ||
dt *= 3600 | ||
elif keyword == 'minutes': | ||
elif keyword == "minutes": | ||
dt *= 60 | ||
elif keyword == 'seconds': | ||
elif keyword == "seconds": | ||
dt *= 1 | ||
else: | ||
logging.warning("Invalid 'keyword' option %s.\nEnum(None, 'hours', 'minutes', 'seconds', 'days')",keyword) | ||
|
||
logging.warning( | ||
"Invalid 'keyword' option %s.\nEnum(None, 'hours', 'minutes', 'seconds', 'days')", | ||
keyword, | ||
) | ||
|
||
if not isinstance(t1, (int, float, complex)): | ||
t1 = time_double.time_double(t1) | ||
t2 = t1+dt | ||
t2 = t1 + dt | ||
xlim(t1, t2) | ||
return | ||
|
||
return |