def index(self): """ The time index of the data. """ warn_deprecated( '.index is deprecatd. Use .time instead to get an astropy.time.Time object, ' 'or ts.to_dataframe().index to get a pandas DateTimeIndex.') return self.to_dataframe().index
def _get_transform_method(method, use_scipy): # This is re-used in affine_transform and GenericMap.rotate supported_methods = {'scipy', 'skimage'} if method not in supported_methods: raise ValueError(f'Method {method} not in supported methods: {supported_methods}') if use_scipy is not None: warn_deprecated("The 'use_scipy' argument is deprecated. " "Specify the rotation method to the 'method' " "keyword argument instead.") if use_scipy is True and method != 'scipy': warn_user(f"Using scipy instead of {method} for rotation.") method = 'scipy' if method == 'skimage': try: import skimage # NoQA except ImportError: warn_user("scikit-image could not be imported. Image rotation will use scipy.") method = 'scipy' return method
def _get_transform_method(method, use_scipy): # This is re-used in affine_transform and GenericMap.rotate if method not in _rotation_registry: raise ValueError(f'Method {method} not in supported methods: ' f'{_rotation_registry.keys()}') if use_scipy is not None: warn_deprecated("The 'use_scipy' argument is deprecated. " "Specify the rotation method to the 'method' " "keyword argument instead.") if use_scipy is True and method != 'scipy': warn_user(f"Using scipy instead of {method} for rotation.") method = 'scipy' if method == 'scikit-image': try: import skimage # NoQA except ImportError: raise ImportError( "scikit-image must be installed to be usable for rotation.") return method
from sunpy.util.exceptions import warn_deprecated from . import _fits from ._fits import * # NoQA __doc__ = _fits.__doc__ __all__ = _fits.__all__ warn_deprecated("The `sunpy.io.fits` module is deprecated, as it was designed " "for internal use. Use the `astropy.fits.io` module instead " "for more generic functionality to read FITS files.")
def resample(orig, dimensions, method='linear', center=False, minusone=False): """ Returns a new `numpy.ndarray` that has been resampled up or down. Arbitrary resampling of source array to new dimension sizes. Currently only supports maintaining the same number of dimensions. To use 1-D arrays, first promote them to shape (x,1). Uses the same parameters and creates the same co-ordinate lookup points as IDL's ``congrid`` routine (which apparently originally came from a VAX/VMS routine of the same name.) Parameters ---------- orig : `numpy.ndarray` Original input array. dimensions : `tuple` Dimensions that new `numpy.ndarray` should have. method : {``"neighbor"``, ``"nearest"``, ``"linear"``, ``"spline"``}, optional Method to use for resampling interpolation. * nearest and linear - Uses "n x 1D" interpolations calculated by `scipy.interpolate.interp1d`. * spline - Uses `scipy.ndimage.map_coordinates` center : `bool`, optional If `False` (default) the interpolation points are at the front edge of the bin. If `True`, interpolation points are at the centers of the bins minusone : `bool`, optional For ``orig.shape = (i,j)`` & new dimensions ``= (x,y)``, if set to `False` (default) ``orig`` is resampled by factors of ``(i/x) * (j/y)``, otherwise ``orig`` is resampled by ``(i-1)/(x-1) * (j-1)/(y-1)``. This prevents extrapolation one element beyond bounds of input array. Returns ------- out : `numpy.ndarray` A new `numpy.ndarray` which has been resampled to the desired dimensions. References ---------- https://scipy-cookbook.readthedocs.io/items/Rebinning.html """ # Verify that number dimensions requested matches original shape if len(dimensions) != orig.ndim: raise UnequalNumDimensions("Number of dimensions must remain the same " "when calling resample.") # TODO: Will this be okay for integer (e.g. JPEG 2000) data? if orig.dtype not in [np.float64, np.float32]: orig = orig.astype(np.float64) dimensions = np.asarray(dimensions, dtype=np.float64) m1 = np.array(minusone, dtype=np.int64) # array(0) or array(1) offset = np.float64(center * 0.5) # float64(0.) or float64(0.5) # Resample data if method == 'neighbor': warn_deprecated( 'Using "neighbor" as a method for resampling is deprecated. ' 'Use "nearest" instead.') data = _resample_neighbor(orig, dimensions, offset, m1) elif method in ['nearest', 'linear']: data = _resample_nearest_linear(orig, dimensions, method, offset, m1) elif method == 'spline': data = _resample_spline(orig, dimensions, offset, m1) else: raise UnrecognizedInterpolationMethod("Unrecognized interpolation " "method requested.") return data
def search(self, *args, **kwargs): """ The simple interface to query the wsdl service. Used to utilize the service's TimeQuery() method, this is a simple interface between the sunpy module library and the web-service's API. .. note:: By default the maximum records returned by the service are limited to 500. To obtain more results ``a.helio.MaxRecords`` must be set to a higher value. Examples -------- >>> from sunpy.net.helio import attrs as ha >>> from sunpy.net import attrs as a, Fido >>> timerange = a.Time('2005/01/03', '2005/12/03') >>> res = Fido.search(timerange, ha.MaxRecords(10), ... ha.TableName('rhessi_hxr_flare')) # doctest: +REMOTE_DATA >>> res #doctest: +REMOTE_DATA <sunpy.net.fido_factory.UnifiedResponse object at ...> Results from 1 Provider: <BLANKLINE> 10 Results from the HECClient: hec_id time_start time_peak ... energy_kev flare_number ------ ------------------- ------------------- ... ---------- ------------ 31463 2005-01-03T01:37:36 2005-01-03T01:37:54 ... 6 5010320 31464 2005-01-03T01:51:36 2005-01-03T01:59:18 ... 12 5010301 31465 2005-01-03T03:26:28 2005-01-03T03:42:50 ... 6 5010332 31466 2005-01-03T03:46:04 2005-01-03T04:07:10 ... 12 5010302 31467 2005-01-03T05:00:24 2005-01-03T05:00:30 ... 6 5010313 31468 2005-01-03T06:40:48 2005-01-03T06:42:46 ... 6 5010314 31469 2005-01-03T08:27:56 2005-01-03T08:28:26 ... 6 5010334 31470 2005-01-03T09:31:00 2005-01-03T09:33:34 ... 6 5010322 31471 2005-01-03T09:34:52 2005-01-03T09:59:46 ... 6 5010336 31472 2005-01-03T11:06:48 2005-01-03T11:07:18 ... 12 5010304 <BLANKLINE> <BLANKLINE> """ qrdict = {} for elem in args: if isinstance(elem, a.Time): qrdict['Time'] = elem elif isinstance(elem, ha.MaxRecords): qrdict['max_records'] = elem.value elif isinstance(elem, ha.TableName): qrdict['table_name'] = elem.value else: raise ValueError( f"{elem.__class__.__name__} should be a ``attrs.Time``, ``attrs.hek.MaxRecords`` or ``attrs.hek.TableName`` attribute." ) qrdict.update(kwargs) table = qrdict.get('table_name', None) if table: if isinstance(table, bytes): warn_deprecated( 'type `bytes` for table_name is deprecated, use `str` instead.' ) table = str.encode(table) start_time = qrdict['Time'].start end_time = qrdict['Time'].end max_records = qrdict.get('max_records', 500) while table is None: table = self.select_table() start_time = parse_time(start_time) end_time = parse_time(end_time) results = self.hec_client.service.TimeQuery(STARTTIME=start_time.isot, ENDTIME=end_time.isot, FROM=table, MAXRECORDS=max_records) results = votable_handler(etree.tostring(results)) table = HECResponse(results.to_table(), client=self) if len(table) == max_records == 500: warn_user( "Number of results is the same as the default `max_records` of 500. " "It is possible your query has been truncated. " "If you want to change this, set `a.helio.MaxRecords` to a higher value." ) return table
def test_warnings(): # Ensure that our warning trickery dosen't stop pytest.warns working with pytest.warns(SunpyDeprecationWarning): warn_deprecated("Hello")