本文整理汇总了Python中sunpy.time.TimeRange类的典型用法代码示例。如果您正苦于以下问题:Python TimeRange类的具体用法?Python TimeRange怎么用?Python TimeRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TimeRange类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _multi_request
def _multi_request(self, **kwargs):
"""
Make a series of requests to avoid the 100GB limit
"""
start_time = kwargs.pop('start_time', None)
end_time = kwargs.pop('end_time', None)
series = kwargs.pop('series', None)
if any(x is None for x in (start_time, end_time, series)):
return []
start_time = self._process_time(start_time)
end_time = self._process_time(end_time)
tr = TimeRange(start_time, end_time)
returns = []
response, json_response = self._send_jsoc_request(start_time, end_time,
series, **kwargs)
# We skip these lines because a massive request is not a practical test.
error_response = 'Request exceeds max byte limit of 100000MB'
if (json_response['status'] == 3 and
json_response['error'] == error_response): # pragma: no cover
returns.append(self._multi_request(tr.start(), tr.center(), series, **kwargs)[0])
# pragma: no cover
returns.append(self._multi_request(tr.center(), tr.end(), series, **kwargs)[0])
# pragma: no cover
else:
returns.append(response)
return returns
示例2: truncate
def truncate(self, a, b=None):
"""Returns a truncated version of the timeseries object"""
if isinstance(a, TimeRange):
time_range = a
else:
time_range = TimeRange(a,b)
truncated = self.data.truncate(time_range.start(), time_range.end())
return LightCurve(truncated, self.header.copy())
示例3: truncate
def truncate(self, a, b=None):
"""Returns a truncated version of the timeseries object"""
if isinstance(a, TimeRange):
time_range = a
else:
time_range = TimeRange(a, b)
truncated = self.data.truncate(time_range.start(), time_range.end())
return self.__class__.create(truncated, self.meta.copy())
示例4: _multi_request
def _multi_request(self, start_time, end_time, series, **kwargs):
"""
Make a series of requests to avoid the 100GB limit
"""
tr = TimeRange(start_time, end_time)
returns = []
response, json_response = self._send_jsoc_request(start_time, end_time, series, **kwargs)
if json_response['status'] == 3 and json_response['error'] == 'Request exceeds max byte limit of 100000MB':
returns.append(self._multi_request(tr.start(), tr.center(), series, **kwargs)[0])
returns.append(self._multi_request(tr.center(), tr.end(), series, **kwargs)[0])
else:
returns.append(response)
return returns
示例5: _get_url_for_date_range
def _get_url_for_date_range(*args, **kwargs):
"""Returns a URL to the RHESSI data for the specified date range.
Parameters
----------
args : TimeRange, datetimes, date strings
Date range should be specified using a TimeRange, or start
and end dates at datetime instances or date strings.
"""
if len(args) == 1 and isinstance(args[0], TimeRange):
time_range = args[0]
elif len(args) == 2:
time_range = TimeRange(parse_time(args[0]), parse_time(args[1]))
if time_range.end() < time_range.start():
raise ValueError('start time > end time')
url = rhessi.get_obssum_filename(time_range)
return url
示例6: backprojection
def backprojection(calibrated_event_list, pixel_size=(1.,1.), image_dim=(64,64)):
"""Given a stacked calibrated event list fits file create a back
projection image.
.. warning:: The image is not in the right orientation!
Parameters
----------
calibrated_event_list : string
filename of a RHESSI calibrated event list
detector : int
the detector number
pixel_size : 2-tuple
the size of the pixels in arcseconds. Default is (1,1).
image_dim : 2-tuple
the size of the output image in number of pixels
Returns
-------
out : RHESSImap
Return a backprojection map.
Examples
--------
>>> import sunpy.instr.rhessi as rhessi
>>> map = rhessi.backprojection(sunpy.RHESSI_EVENT_LIST)
>>> map.show()
"""
calibrated_event_list = sunpy.RHESSI_EVENT_LIST
fits = pyfits.open(calibrated_event_list)
info_parameters = fits[2]
xyoffset = info_parameters.data.field('USED_XYOFFSET')[0]
time_range = TimeRange(info_parameters.data.field('ABSOLUTE_TIME_RANGE')[0])
image = np.zeros(image_dim)
#find out what detectors were used
det_index_mask = fits[1].data.field('det_index_mask')[0]
detector_list = (np.arange(9)+1) * np.array(det_index_mask)
for detector in detector_list:
if detector > 0:
image = image + _backproject(calibrated_event_list, detector=detector, pixel_size=pixel_size, image_dim=image_dim)
dict_header = {
"DATE-OBS": time_range.center().strftime("%Y-%m-%d %H:%M:%S"),
"CDELT1": pixel_size[0],
"NAXIS1": image_dim[0],
"CRVAL1": xyoffset[0],
"CRPIX1": image_dim[0]/2 + 0.5,
"CUNIT1": "arcsec",
"CTYPE1": "HPLN-TAN",
"CDELT2": pixel_size[1],
"NAXIS2": image_dim[1],
"CRVAL2": xyoffset[1],
"CRPIX2": image_dim[0]/2 + 0.5,
"CUNIT2": "arcsec",
"CTYPE2": "HPLT-TAN",
"HGLT_OBS": 0,
"HGLN_OBS": 0,
"RSUN_OBS": solar_semidiameter_angular_size(time_range.center()),
"RSUN_REF": sun.radius,
"DSUN_OBS": sunearth_distance(time_range.center()) * sunpy.sun.constants.au
}
header = sunpy.map.MapHeader(dict_header)
result_map = sunpy.map.Map(image, header)
return result_map
示例7: backprojection
def backprojection(calibrated_event_list, pixel_size=(1.,1.) * u.arcsec, image_dim=(64,64) * u.pix):
"""
Given a stacked calibrated event list fits file create a back
projection image.
.. warning:: The image is not in the right orientation!
Parameters
----------
calibrated_event_list : string
filename of a RHESSI calibrated event list
detector : int
the detector number
pixel_size : `~astropy.units.Quantity` instance
the size of the pixels in arcseconds. Default is (1,1).
image_dim : `~astropy.units.Quantity` instance
the size of the output image in number of pixels
Returns
-------
out : RHESSImap
Return a backprojection map.
Examples
--------
>>> import sunpy.instr.rhessi as rhessi
>>> map = rhessi.backprojection(sunpy.RHESSI_EVENT_LIST)
>>> map.peek()
"""
if not isinstance(pixel_size, u.Quantity):
raise ValueError("Must be astropy Quantity in arcseconds")
try:
pixel_size = pixel_size.to(u.arcsec)
except:
raise ValueError("'{0}' is not a valid pixel_size unit".format(pixel_size.unit))
if not (isinstance(image_dim, u.Quantity) and image_dim.unit == 'pix'):
raise ValueError("Must be astropy Quantity in pixels")
calibrated_event_list = sunpy.RHESSI_EVENT_LIST
afits = fits.open(calibrated_event_list)
info_parameters = afits[2]
xyoffset = info_parameters.data.field('USED_XYOFFSET')[0]
time_range = TimeRange(info_parameters.data.field('ABSOLUTE_TIME_RANGE')[0])
image = np.zeros(image_dim.value)
#find out what detectors were used
det_index_mask = afits[1].data.field('det_index_mask')[0]
detector_list = (np.arange(9)+1) * np.array(det_index_mask)
for detector in detector_list:
if detector > 0:
image = image + _backproject(calibrated_event_list, detector=detector, pixel_size=pixel_size.value
, image_dim=image_dim.value)
dict_header = {
"DATE-OBS": time_range.center().strftime("%Y-%m-%d %H:%M:%S"),
"CDELT1": pixel_size[0],
"NAXIS1": image_dim[0],
"CRVAL1": xyoffset[0],
"CRPIX1": image_dim[0].value/2 + 0.5,
"CUNIT1": "arcsec",
"CTYPE1": "HPLN-TAN",
"CDELT2": pixel_size[1],
"NAXIS2": image_dim[1],
"CRVAL2": xyoffset[1],
"CRPIX2": image_dim[0].value/2 + 0.5,
"CUNIT2": "arcsec",
"CTYPE2": "HPLT-TAN",
"HGLT_OBS": 0,
"HGLN_OBS": 0,
"RSUN_OBS": solar_semidiameter_angular_size(time_range.center()).value,
"RSUN_REF": sunpy.sun.constants.radius.value,
"DSUN_OBS": sunearth_distance(time_range.center()) * sunpy.sun.constants.au.value
}
header = sunpy.map.MapMeta(dict_header)
result_map = sunpy.map.Map(image, header)
return result_map
示例8: TimeRange
from sunpy.time import TimeRange
from sunpy.lightcurve import GOESLightCurve
dt = TimeRange('1981/01/10 00:00', '2014/04/18 23:00')
tr_not_found = []
time_ranges = dt.window(60*60*24, 60*60*24)
total_days = len(time_ranges)
total_fails = 0
# missing files http://umbra.nascom.nasa.gov/goes/fits/2005/go1220051116.fits
# http://umbra.nascom.nasa.gov/goes/fits/2005/go1220051116.fits
for time_range in time_ranges:
print(time_range.start())
try:
goes = GOESLightCurve.create(time_range)
print(goes.data['xrsa'].max())
print(goes.data['xrsb'].max())
except:
print("File Not Found!")
tr_not_found.append(time_range)
total_fails = total_fails + 1
print('Number of fails:%i' % total_fails)
print('Number of tries:%i' % total_days)
print('Percent Fail: %d' % (float(total_fails)/total_days * 100))
for tr in tr_not_found:
print(tr.start())