Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if len(args.time_list) == 1 and isinstance(
args.time_list[0], string_types):
args.time_list = args.time_list[0].split()
args.time_list = [float(x) for x in args.time_list]
args.time_unit = 'phase'
else:
if any(['+' in x for x in args.time_list]):
args.time_unit = 'phase'
args.time_list = [float(x) for x in args.time_list]
if args.date_list:
if no_events:
prt.message('no_dates_gen', warning=True)
else:
args.time_list += [
str(astrotime(x.replace('/', '-')).mjd) for x in args.date_list
]
args.time_unit = 'mjd'
if args.mjd_list:
if no_events:
prt.message('no_dates_gen', warning=True)
else:
args.time_list += [float(x) for x in args.mjd_list]
args.time_unit = 'mjd'
if args.jd_list:
if no_events:
prt.message('no_dates_gen', warning=True)
else:
args.time_list += [
str(astrotime(float(x), format='jd').mjd) for x in args.jd_list
def update_count(self):
"""Return the time in step of 1h when the button ">>" is clicked."""
self.bttn_clicks += 1
dt = TimeDelta(3600.0, format='sec')
update_time = int(self.bttn_clicks) * dt
obs_time = Time(self.user.get_obs_time())
time_update = obs_time + update_time
return time_update
def format_date(date):
"""
Parameters
----------
date : ~astropy.time.core.Time
input date
Returns
-------
formatted_date : ~astropy.time.core.Time
ISO 8601 - compliant date
"""
return Time(date, format="isot")
Parameters
----------
periods : int, optional
Number of periods, default to 50.
spacing : Time or Quantity, optional
Spacing between periods, optional.
end : Time or equivalent, optional
End date.
Returns
-------
Time
Array of time values.
"""
start = Time(start, format=format, scale=scale)
if spacing is not None and end is None:
result = start + spacing * np.arange(0, periods)
elif end is not None and spacing is None:
end = Time(end, format=format, scale=scale)
result = start + (end - start) * np.linspace(0, 1, periods)
else:
raise ValueError("Either 'end' or 'spacing' must be specified")
return result
def _get_IERS_A_table(warn_update=14*u.day):
"""
Grab the locally cached copy of the IERS Bulletin A table. Check to see
if it's up to date, and warn the user if it is not.
This will fail and raise OSError if the file is not in the cache.
"""
if IERS_A_in_cache():
table = iers.IERS_Auto.open()
# Use polar motion flag to identify last observation before predictions
index_of_last_observation = ''.join(table['PolPMFlag_A']).index('IP')
time_of_last_observation = Time(table['MJD'][index_of_last_observation],
format='mjd')
time_since_last_update = Time.now() - time_of_last_observation
# If the IERS bulletin is more than `warn_update` days old, warn user
if warn_update < time_since_last_update:
warnmsg = ("Your version of the IERS Bulletin A is {:.1f} days "
"old. ".format(time_since_last_update.to(u.day).value) +
IERS_A_WARNING)
warnings.warn(warnmsg, OldEarthOrientationDataWarning)
return table
else:
raise OSError("No IERS A table has been downloaded.")
import matplotlib.pyplot as plt
plt.show()
"""
from ..catalog import fetch_fermi_catalog
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
ax = plt.gca() if ax is None else ax
if time_start is None:
time_start = Time('2008-08-02T00:33:19')
else:
time_start = Time(time_start)
if time_end is None:
time_end = Time('2012-07-31T22:45:47')
else:
time_end = Time(time_end)
fermi_met_start = (time_start - TIME_REF_FERMI).sec
fermi_met_end = (time_end - TIME_REF_FERMI).sec
fermi_cat = fetch_fermi_catalog('3FGL')
catalog_index = np.where(fermi_cat[1].data['Source_Name'] == source_name)[0][0]
hist_start = fermi_cat[3].data['Hist_Start']
time_index_start = np.where(hist_start >= fermi_met_start)[0][0]
# The final entry is the end of the last bin, so no off by one error
time_index_end = np.where(hist_start <= fermi_met_end)[0][-1] + 1
self.master_flat = {}
self.master_flat_nogrt = {}
# Creating dict. of flats. The key values are expected to be: GRATIN_ID and ''
# if there is flat taken w/o grating
df = image_collection.summary.to_pandas()
grtobj = df['grating'][(df['obstype'] != 'BIAS')]
grtobj = grtobj.unique()
grt_list = grtobj.tolist()
dic_all_flats = {}
for grt in sorted(grt_list):
start_night = (Time(twilight_evening) - TimeDelta(1800.0, format='sec')).isot
end_night = (Time(twilight_morning) + TimeDelta(1800.0, format='sec')).isot
day_condition = ((Time(df['date-obs'].tolist()).jd < Time(start_night).jd) |
(Time(df['date-obs'].tolist()).jd > Time(end_night).jd))
dfobj = df['file'][(df['obstype'] == 'FLAT') & (df['grating'] == grt) & day_condition]
dic_all_flats[str(grt)] = dfobj.tolist()
# Dict. for flats with grating and without grating
dic_flat = {grt: dic_all_flats[grt] for grt in dic_all_flats if grt != ""}
dic_flatnogrt = {grt: dic_all_flats[grt] for grt in dic_all_flats if grt == ""}
if np.size(dic_flat.values()) > 0:
for grt in dic_flat.keys():
flat_list = []
log.info('Combining and trimming flat frames:')
for filename in dic_flat[grt]:
bjdref : float
BJD reference date, for Kepler this is 2454833.
Returns
-------
time : `astropy.time.Time` object
Resulting time object.
"""
bkjd = np.atleast_1d(bkjd)
jd = bkjd + bjdref
# Some data products have missing time values;
# we need to set these to zero or `Time` cannot be instantiated.
jd[~np.isfinite(jd)] = 0
if isinstance(bkjd, float): # If user entered a float, return a float
jd = jd[0]
return Time(jd, format='jd', scale='tdb')
def set_lsts_from_time_array(self):
"""Set the lst_array based from the time_array."""
lsts = []
curtime = self.time_array[0]
self.lst_array = np.zeros(self.Nblts)
latitude, longitude, altitude = self.telescope_location_lat_lon_alt_degrees
for ind, jd in enumerate(np.unique(self.time_array)):
t = Time(jd, format='jd', location=(longitude, latitude))
self.lst_array[np.where(np.isclose(jd, self.time_array, atol=1e-6, rtol=1e-12))] = t.sidereal_time('apparent').radian
include_gps=include_gps,
include_bipm=include_bipm,
bipm_version=bipm_version,
)
loind, hiind = self.table.groups.indices[ii : ii + 2]
# First apply any TIME statements
for jj in range(loind, hiind):
if "to" in flags[jj]:
# TIME commands are in sec
# SUGGESTION(@paulray): These time correction units should
# be applied in the parser, not here. In the table the time
# correction should have units.
corr[jj] = flags[jj]["to"] * u.s
times[jj] += time.TimeDelta(corr[jj])
gcorr = site.clock_corrections(time.Time(grp["mjd"]))
for jj, cc in enumerate(gcorr):
grp["mjd"][jj] += time.TimeDelta(cc)
corr[loind:hiind] += gcorr
# Now update the flags with the clock correction used
for jj in range(loind, hiind):
if corr[jj] != 0:
flags[jj]["clkcorr"] = corr[jj]
# Update clock correction info
self.clock_corr_info.update(
{
"include_bipm": include_bipm,
"bipm_version": bipm_version,
"include_gps": include_gps,
}