Commit 1e59baaa authored by Cecconi Baptiste's avatar Cecconi Baptiste
Browse files

add docstring

parent 418fe522
Pipeline #17479 passed with stages
in 3 minutes and 8 seconds
......@@ -70,6 +70,8 @@ class BaseData:
class Data(BaseData, dataset="default"):
"""Generic Data class"""
def __new__(
cls, filepath: Path, dataset: Union[None, str] = "__auto__", *args, **kwargs
) -> "Data":
......@@ -97,41 +99,50 @@ class Data(BaseData, dataset="default"):
def open(cls, filepath: Path, *args, **kwargs):
"""Generic open() method."""
return open(filepath, *args, **kwargs)
def close(cls, file):
"""Generic close() method."""
def file(self):
"""Generic open method (using the default open class)."""
if not self._file:
self._file =
return self._file
def sweeps(self):
"""Generic iterator method to access sweeps."""
for sweep in self._iter_sweep_class(data_instance=self):
yield sweep
def records(self):
"""Generic iterator method to access records."""
for record in self._iter_record_class(data_instance=self):
yield record
def meta(self) -> dict:
"""Generic method to metadata."""
return dict()
def times(self):
"""Generic method to get the time axis."""
return None
def frequencies(self):
"""Generic method to get the spectral axis."""
return None
def as_array(self) -> numpy.ndarray:
"""Generic method to get the data as a numpy.array."""
return numpy.ndarray(0)
def __enter__(self):
......@@ -153,6 +164,7 @@ class Data(BaseData, dataset="default"):
def get_dataset(cls, filepath):
"""Dataset selector method."""
filepath = Path(filepath)
if filepath.suffix.lower() == ".cdf":
dataset = BaseData._registry["cdf"].get_dataset(filepath)
......@@ -172,12 +184,14 @@ class CdfData(Data, dataset="cdf"):
def open(cls, filepath: Path, *args, **kwargs):
"""Open method for CDF formatted data products"""
from spacepy import pycdf
return pycdf.CDF(str(filepath))
def get_dataset(cls, filepath):
"""Dataset selector for CDF files (must be ISTP compliant)"""
with as c:
dataset = c.attrs["Logical_source"][...][0]
return dataset
......@@ -188,10 +202,12 @@ class FitsData(Data, dataset="fits"):
def open(cls, filepath: Path, *args, **kwargs):
"""Open method for FITS formatted data products"""
return, *args, **kwargs)
def get_dataset(cls, filepath):
"""Dataset selector for FITS files"""
with as f:
if f[0].header["INSTRUME"] == "NenuFar" and filepath.stem.endswith("_BST"):
dataset = "srn_nenufar_bst"
......@@ -210,6 +226,7 @@ class BinData(Data, dataset="bin"):
def get_dataset(cls, filepath):
"""Dataset selector for Binary files"""
filepath = Path(filepath)
if filepath.stem.lower().startswith("wi_wa_rad1_l2_60s"):
dataset = "cdpp_wi_wa_rad1_l2_60s_v2"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment