-
Notifications
You must be signed in to change notification settings - Fork 1
LightCurve Refactor Proposal
We all knew this day was coming, LightCurve cannot escape the spotlight any longer. LightCurve moves away from conditional dispatch to a Factory based creation system so that it behaves like Map.
This proposal makes an API change, which will move LightCurve to follow the API of the Map submodule. This will provide end users a consistent interface submodules and allow for cleaner and easier to read code for developers, much like the map refactor did for the map submodule.
PR #729 The update to the base factory class, currently used for Map.
A factory instance (as proposed in #729) called LightCurve will be available in the top level of the sunpy.lightcurve
which will allow creation of all registered LightCurve subclasses with the following API:
def LightCurve(filename=None, source=None, dates=None, *kwargs):
"""
Parameters
----------------
filename: string or File
A file to read.
source: string or iterable of strings
A string identifier for a registered subclass, matched by that subclasses `_is_source_for` method.
dates: DateTime instance or iterable of.
The time range to create the lightcurve in between.
All other keywords are passed to subclass
"""
- my_lc = LightCurve(source=’goes’, dates=[datemin,datemax])
- my_lc = LIghtCurve(source=’goes’, dates=datetime)#Downloads a standard amount of time?
- my_lc = LightCurve(source=’goes’, filename.csv)
- my_lc = LightCurve(filename.fits)
- my_lc = LightCurve(url) # autodetect
- my_lc = LightCurve(source=’goes’, url)
- my_lc = LightCurve(source=’lyra’, dates=[min,max], events=[x,y,z])
- my_goes, my_lyra = LightCurve(source=[‘goes’,’lyra’], dates=[min,max])
- URL -> resolve to file
- Filename:
- Attempt to read with
sunpy.io
: (LikeMap()
)- Parse metadata to
_is_source_for
and find relevant subclass - Create that LightCurve.
- Parse metadata to
- Match ‘source’ flag to subclass and get subclass to read file:
- return data, meta pair, create instance.
- fail.
- Attempt to read with
- Filename:
- Daterange:
- Match ‘source’ flag to subclass and get URI
- Download data (support multiple files)
- Attempt read with
sunpy.io
, parse (data, meta) to subclass__init__
. - Attempt to read with subclass.
- fail
- Other kwargs are processed and passed to subclass class method for returning
(data, meta)
.
- parse specific data files that cannot be read by the
sunpy.io
module, i.e. CSV or ASCII files. - Parse input to the LightCurve factory such as date range and return a file download URI.
- Provide a
_is_source_for
which if possible auto detects the data type from a (data, meta) pair, and also matches string names for the subclass i.e. 'goes' or 'lyra', which will be passed into the factory to specify type for download etc.
None, due to the current implementation of LightCurve it will be very hard to maintain backwards compatibility. It may be possible to implement a .create()
method that calls the Factory, however I would not recommend it.
#Notes:
- Make a check that the index column of the LightCurve is actually a time.
- Since there is no standard for storing time-series data (FITS files have a standard) then we can expect that each instrument subclass will be highly tailored to however the data is stored.
- Do we still want to use pandas time-series to store the data?