Source code for showapi.level1.showl1collection
import datetime
from typing import List, Any, NamedTuple
from .l1_fileorganizer import L1_Netcdf_FileOrganizer
#------------------------------------------------------------------------------
# SHOWLevel1CollectionIterator
#------------------------------------------------------------------------------
[docs]class SHOWLevel1CollectionIterator:
def __init__(self, collection: List[Any]):
self.collection = collection
self.numpoints = collection.numrecords()
self.current = 0
def __next__(self):
if (self.current >= self.numpoints):
raise StopIteration
entry = self.collection[self.current]
self.current += 1
return entry
#------------------------------------------------------------------------------
# SHOWLevel1
#------------------------------------------------------------------------------
[docs]class SHOWLevel1Collection:
"""
A base class to load SHOW Level 1A and Level 1B. The class is a simple wrapper around the L1_Netcdf_FileOrganizer class and an xarray instance.
Interpretation o fthe fields within the xarray instance is left to derived classes, e.g. :class:`~showapi.level1.showlevel1a.SHOWLevel1ACollection` and
:class:`~showapi.level1.showlevel1a.SHOWLevel1BCollection`
"""
#------------------------------------------------------------------------------
# __init__
#------------------------------------------------------------------------------
def __init__(self, groupname:str, levelname : str, basedir : str , versionstr : str):
self.fileorganizer = L1_Netcdf_FileOrganizer(basedir, groupname, levelname, versionstr)
self.xarrayvar = None
#------------------------------------------------------------------------------
# load
#------------------------------------------------------------------------------
[docs] def load(self, tmin :datetime.datetime = None, tmax:datetime.datetime = None ):
self.close()
self.xarrayvar = self.fileorganizer.load( tmin, tmax )
#------------------------------------------------------------------------------
# numrecords
#------------------------------------------------------------------------------
[docs] def numrecords(self):
return self.xarrayvar.time.sizes['time'] if self.xarrayvar is not None else 0
#------------------------------------------------------------------------------
# close
#------------------------------------------------------------------------------
[docs] def close(self):
if (self.xarrayvar is not None):
self.xarrayvar.close()
self.xarrayvar = None