src/pys5p/s5p_msm.py
def __from_h5_dset(self, h5_dset, data_sel, datapoint):
        """
        initialize S5Pmsm object from h5py dataset
        """
        self.name = PurePath(h5_dset.name).name

        # copy dataset values (and error) to object
        if data_sel is None:
            if datapoint:
                self.value = h5_dset['value']
                self.error = h5_dset['error']
            else:
                self.value = h5_dset[...]
        else:
            # we need to keep all dimensions to get the dimensions
            # of the output data right
            if datapoint:
                self.value = h5_dset['value'][data_sel]
                self.error = h5_dset['error'][data_sel]
                if isinstance(data_sel, tuple):
                    for ii, elmnt in enumerate(data_sel):
                        if isinstance(elmnt, (int, np.int64)):
                            self.value = np.expand_dims(self.value, axis=ii)
                            self.error = np.expand_dims(self.error, axis=ii)
            else:
                self.value = h5_dset[data_sel]
                if isinstance(data_sel, tuple):
                    for ii, elmnt in enumerate(data_sel):
                        if isinstance(elmnt, (int, np.int64)):
                            self.value = np.expand_dims(self.value, axis=ii)

        # set default dimension names
        if h5_dset.ndim == 1:
            keys_default = ['column']
        elif h5_dset.ndim == 2:
            keys_default = ['row', 'column']
        elif h5_dset.ndim == 3:
            keys_default = ['time', 'row', 'column']
        else:
            raise ValueError('not implemented for ndim > 3')

        # copy all dimensions with size longer then 1
        keys = []
        dims = []
        for ii in range(h5_dset.ndim):
            if self.value.shape[ii] == 1:
                continue

            if len(h5_dset.dims[ii]) != 1:   # bug in some KMNI HDF5 files
                keys.append(keys_default[ii])
                dims.append(np.arange(self.value.shape[ii]))
            elif self.value.shape[ii] == h5_dset.shape[ii]:
                buff = PurePath(h5_dset.dims[ii][0].name).name
                if len(buff.split()) > 1:
                    buff = buff.split()[0]
                keys.append(buff)
                if h5_dset.dims[ii][0][:].size == h5_dset.shape[ii]:
                    buff = h5_dset.dims[ii][0][:]
                    if np.all(buff == 0):
                        buff = np.arange(buff.size)
                else:                          # bug in some KMNI HDF5 files
                    buff = np.arange(h5_dset.shape[ii])
                dims.append(buff)
            else:
                buff = PurePath(h5_dset.dims[ii][0].name).name
                if len(buff.split()) > 1:
                    buff = buff.split()[0]
                keys.append(buff)
                if h5_dset.dims[ii][0][:].size == h5_dset.shape[ii]:
                    buff = h5_dset.dims[ii][0][:]
                    if np.all(buff == 0):
                        buff = np.arange(buff.size)
                else:                          # bug in some KMNI HDF5 files
                    buff = np.arange(h5_dset.shape[ii])

                if isinstance(data_sel, slice):
                    dims.append(buff[data_sel])
                elif len(data_sel) == h5_dset.ndim:
                    dims.append(buff[data_sel[ii]])
                elif not isinstance(data_sel, tuple):
                    dims.append(buff[data_sel])
                elif ii > len(data_sel):
                    dims.append(buff[data_sel[-1]])
                else:
                    dims.append(buff[data_sel[ii]])

        # add dimensions as a namedtuple
        coords_namedtuple = namedtuple('Coords', keys)
        self.coords = coords_namedtuple._make(dims)

        # remove all dimensions with size equal 1 from value (and error)
        self.value = np.squeeze(self.value)
        if datapoint:
            self.error = np.squeeze(self.error)

        # copy FillValue (same for value/error in a datapoint)
        if datapoint:
            self.fillvalue = h5_dset.fillvalue[0]
        else:
            self.fillvalue = h5_dset.fillvalue

        # copy its units
        if 'units' in h5_dset.attrs:
            if isinstance(h5_dset.attrs['units'], np.ndarray):
                if h5_dset.attrs['units'].size == 1:
                    self.units = h5_dset.attrs['units'][0]
                    if isinstance(self.units, bytes):
                        self.units = self.units.decode('ascii')
                else:
                    self.units = h5_dset.attrs['units']
                    if isinstance(self.units[0], bytes):
                        self.units = self.units.astype(str)
            else:
                self.units = h5_dset.attrs['units']
                if isinstance(self.units, bytes):
                    self.units = self.units.decode('ascii')

        # copy its long_name
        if 'long_name' in h5_dset.attrs:
            if isinstance(h5_dset.attrs['long_name'], bytes):
                self.long_name = h5_dset.attrs['long_name'].decode('ascii')
            else:
                self.long_name = h5_dset.attrs['long_name']

        initialize S5Pmsm object from h5py dataset
        
initialize S5Pmsm object from h5py dataset
initialize S5Pmsm object from h5py dataset
def __from_h5_dset(self, h5_dset, data_sel, datapoint):
        self.name = PurePath(h5_dset.name).name
        if data_sel is None:
            if datapoint:
                self.value = h5_dset['value']
                self.error = h5_dset['error']
            else:
                self.value = h5_dset[...]
        else:
            if datapoint:
                self.value = h5_dset['value'][data_sel]
                self.error = h5_dset['error'][data_sel]
                if isinstance(data_sel, tuple):
                    for ii, elmnt in enumerate(data_sel):
                        if isinstance(elmnt, (int, np.int64)):
                            self.value = np.expand_dims(self.value, axis=ii)
                            self.error = np.expand_dims(self.error, axis=ii)
            else:
                self.value = h5_dset[data_sel]
                if isinstance(data_sel, tuple):
                    for ii, elmnt in enumerate(data_sel):
                        if isinstance(elmnt, (int, np.int64)):
                            self.value = np.expand_dims(self.value, axis=ii)
        if h5_dset.ndim == 1:
            keys_default = ['column']
        elif h5_dset.ndim == 2:
            keys_default = ['row', 'column']
        elif h5_dset.ndim == 3:
            keys_default = ['time', 'row', 'column']
        else:
            raise ValueError('not implemented for ndim > 3')
        keys = []
        dims = []
        for ii in range(h5_dset.ndim):
            if self.value.shape[ii] == 1:
                continue
            if len(h5_dset.dims[ii]) != 1:   
                keys.append(keys_default[ii])
                dims.append(np.arange(self.value.shape[ii]))
            elif self.value.shape[ii] == h5_dset.shape[ii]:
                buff = PurePath(h5_dset.dims[ii][0].name).name
                if len(buff.split()) > 1:
                    buff = buff.split()[0]
                keys.append(buff)
                if h5_dset.dims[ii][0][:].size == h5_dset.shape[ii]:
                    buff = h5_dset.dims[ii][0][:]
                    if np.all(buff == 0):
                        buff = np.arange(buff.size)
                else:                          
                    buff = np.arange(h5_dset.shape[ii])
                dims.append(buff)
            else:
                buff = PurePath(h5_dset.dims[ii][0].name).name
                if len(buff.split()) > 1:
                    buff = buff.split()[0]
                keys.append(buff)
                if h5_dset.dims[ii][0][:].size == h5_dset.shape[ii]:
                    buff = h5_dset.dims[ii][0][:]
                    if np.all(buff == 0):
                        buff = np.arange(buff.size)
                else:                          
                    buff = np.arange(h5_dset.shape[ii])
                if isinstance(data_sel, slice):
                    dims.append(buff[data_sel])
                elif len(data_sel) == h5_dset.ndim:
                    dims.append(buff[data_sel[ii]])
                elif not isinstance(data_sel, tuple):
                    dims.append(buff[data_sel])
                elif ii > len(data_sel):
                    dims.append(buff[data_sel[-1]])
                else:
                    dims.append(buff[data_sel[ii]])
        coords_namedtuple = namedtuple('Coords', keys)
        self.coords = coords_namedtuple._make(dims)
        self.value = np.squeeze(self.value)
        if datapoint:
            self.error = np.squeeze(self.error)
        if datapoint:
            self.fillvalue = h5_dset.fillvalue[0]
        else:
            self.fillvalue = h5_dset.fillvalue
        if 'units' in h5_dset.attrs:
            if isinstance(h5_dset.attrs['units'], np.ndarray):
                if h5_dset.attrs['units'].size == 1:
                    self.units = h5_dset.attrs['units'][0]
                    if isinstance(self.units, bytes):
                        self.units = self.units.decode('ascii')
                else:
                    self.units = h5_dset.attrs['units']
                    if isinstance(self.units[0], bytes):
                        self.units = self.units.astype(str)
            else:
                self.units = h5_dset.attrs['units']
                if isinstance(self.units, bytes):
                    self.units = self.units.decode('ascii')
        if 'long_name' in h5_dset.attrs:
            if isinstance(h5_dset.attrs['long_name'], bytes):
                self.long_name = h5_dset.attrs['long_name'].decode('ascii')
            else:
                self.long_name = h5_dset.attrs['long_name']
def __from_h5_dset ( self , h5_dset , data_sel , datapoint ) : self . name = PurePath ( h5_dset . name ) . name if data_sel is None : if datapoint : self . value = h5_dset [ 'value' ] self . error = h5_dset [ 'error' ] else : self . value = h5_dset [ ... ] else : if datapoint : self . value = h5_dset [ 'value' ] [ data_sel ] self . error = h5_dset [ 'error' ] [ data_sel ] if isinstance ( data_sel , tuple ) : for ii , elmnt in enumerate ( data_sel ) : if isinstance ( elmnt , ( int , np . int64 ) ) : self . value = np . expand_dims ( self . value , axis = ii ) self . error = np . expand_dims ( self . error , axis = ii ) else : self . value = h5_dset [ data_sel ] if isinstance ( data_sel , tuple ) : for ii , elmnt in enumerate ( data_sel ) : if isinstance ( elmnt , ( int , np . int64 ) ) : self . value = np . expand_dims ( self . value , axis = ii ) if h5_dset . ndim == 1 : keys_default = [ 'column' ] elif h5_dset . ndim == 2 : keys_default = [ 'row' , 'column' ] elif h5_dset . ndim == 3 : keys_default = [ 'time' , 'row' , 'column' ] else : raise ValueError ( 'not implemented for ndim > 3' ) keys = [ ] dims = [ ] for ii in range ( h5_dset . ndim ) : if self . value . shape [ ii ] == 1 : continue if len ( h5_dset . dims [ ii ] ) != 1 : keys . append ( keys_default [ ii ] ) dims . append ( np . arange ( self . value . shape [ ii ] ) ) elif self . value . shape [ ii ] == h5_dset . shape [ ii ] : buff = PurePath ( h5_dset . dims [ ii ] [ 0 ] . name ) . name if len ( buff . split ( ) ) > 1 : buff = buff . split ( ) [ 0 ] keys . append ( buff ) if h5_dset . dims [ ii ] [ 0 ] [ : ] . size == h5_dset . shape [ ii ] : buff = h5_dset . dims [ ii ] [ 0 ] [ : ] if np . all ( buff == 0 ) : buff = np . arange ( buff . size ) else : buff = np . arange ( h5_dset . shape [ ii ] ) dims . append ( buff ) else : buff = PurePath ( h5_dset . dims [ ii ] [ 0 ] . name ) . name if len ( buff . split ( ) ) > 1 : buff = buff . split ( ) [ 0 ] keys . append ( buff ) if h5_dset . dims [ ii ] [ 0 ] [ : ] . size == h5_dset . shape [ ii ] : buff = h5_dset . dims [ ii ] [ 0 ] [ : ] if np . all ( buff == 0 ) : buff = np . arange ( buff . size ) else : buff = np . arange ( h5_dset . shape [ ii ] ) if isinstance ( data_sel , slice ) : dims . append ( buff [ data_sel ] ) elif len ( data_sel ) == h5_dset . ndim : dims . append ( buff [ data_sel [ ii ] ] ) elif not isinstance ( data_sel , tuple ) : dims . append ( buff [ data_sel ] ) elif ii > len ( data_sel ) : dims . append ( buff [ data_sel [ - 1 ] ] ) else : dims . append ( buff [ data_sel [ ii ] ] ) coords_namedtuple = namedtuple ( 'Coords' , keys ) self . coords = coords_namedtuple . _make ( dims ) self . value = np . squeeze ( self . value ) if datapoint : self . error = np . squeeze ( self . error ) if datapoint : self . fillvalue = h5_dset . fillvalue [ 0 ] else : self . fillvalue = h5_dset . fillvalue if 'units' in h5_dset . attrs : if isinstance ( h5_dset . attrs [ 'units' ] , np . ndarray ) : if h5_dset . attrs [ 'units' ] . size == 1 : self . units = h5_dset . attrs [ 'units' ] [ 0 ] if isinstance ( self . units , bytes ) : self . units = self . units . decode ( 'ascii' ) else : self . units = h5_dset . attrs [ 'units' ] if isinstance ( self . units [ 0 ] , bytes ) : self . units = self . units . astype ( str ) else : self . units = h5_dset . attrs [ 'units' ] if isinstance ( self . units , bytes ) : self . units = self . units . decode ( 'ascii' ) if 'long_name' in h5_dset . attrs : if isinstance ( h5_dset . attrs [ 'long_name' ] , bytes ) : self . long_name = h5_dset . attrs [ 'long_name' ] . decode ( 'ascii' ) else : self . long_name = h5_dset . attrs [ 'long_name' ]
initialize S5Pmsm object from h5py dataset
initialize S5Pmsm object from h5py dataset
"""
        initialize S5Pmsm object from h5py dataset
        """ # copy dataset values (and error) to object # we need to keep all dimensions to get the dimensions # of the output data right # set default dimension names # copy all dimensions with size longer then 1 # bug in some KMNI HDF5 files # bug in some KMNI HDF5 files # bug in some KMNI HDF5 files # add dimensions as a namedtuple # remove all dimensions with size equal 1 from value (and error) # copy FillValue (same for value/error in a datapoint) # copy its units # copy its long_name
self
h5_dset
data_sel
datapoint