def _encodeCollectionId(self, key, scope=None, collection=None): if not self.is_collections_supported(): raise exceptions.RuntimeError("Collections are not enabled") if type(collection) == str: # expect scope.collection for name API try: collection = self.collection_map[scope][collection] except KeyError as e: self.log.info( "Error: cannot map collection \"{}\" to an ID".format( collection)) self.log.info( "name API expects \"scope and collection\" as the key") raise e output = array.array('B', [0]) while collection > 0: byte = collection & 0xFF collection >>= 7 # collection has more bits? if collection > 0: # Set the 'continue' bit of this byte byte |= 0x80 output[-1] = byte output.append(0) else: output[-1] = byte return output.tostring() + key
def __get_V(self): r""" Return relative angular frequency grid (THz) """ if not self._ready: raise exceptions.RuntimeError(self._not_ready_msg) else: VGRID = 2.0 * np.pi * np.transpose( np.arange(-self._n / 2, self._n / 2)) / ( self._n * self._dT) # Frequency grid (angular THz) return VGRID
def __get_T(self): r""" Return temporal grid (ps) """ if not self._ready: raise exceptions.RuntimeError(self._not_ready_msg) else: TGRID = np.linspace(-self._time_window / 2.0, self._time_window / 2.0, self._n, endpoint=False) # time grid return TGRID
def set_AW(self, AW_new): r""" Set the value of the frequency-domain electric field. Parameters ---------- AW_new : array_like New electric field values. """ if not self._ready: raise exceptions.RuntimeError(self._not_ready_msg) if self._AW is None: self._AW = np.zeros((self._n, ), dtype=np.complex128) self._AW[:] = AW_new
def set_time_window_s(self, T): r""" Set the total time window of the grid. This sets the grid dT, and implicitly changes the frequency span (~1/dT). Parameters ---------- T : float New grid time span [s] """ if self._n is None: raise exceptions.RuntimeError( 'Set number of points before setting time window.') self._set_time_window(T * 1e12)
def set_time_window_ps(self, T): r""" Set the total time window of the grid. This sets the grid dT, and implicitly changes the frequency span (~1/dT). Parameters ---------- T : float New grid time span [ps] """ if self._n is None: raise exceptions.RuntimeError( 'Set number of points before setting time window.') # frequency grid is 2 pi/ dT * [-1/2, 1/2] # dT is simply time_window / NPTS self._set_time_window(T)
def set_frequency_window_mks(self, DF): r""" Set the total frequency window of the grid. This sets the grid dF, and implicitly changes the temporal span (~1/dF). Parameters ---------- DF : float New grid time span [Hz] """ if self._n is None: raise exceptions.RuntimeError( 'Set number of points before setting frequency window.') # Internally, the time window is used to determine the grids. Calculate # the time window size as 1 / dF = 1 / (DF / N) T = self._n / float(DF) self._set_time_window(T * 1e12)
def __get_dT(self): r""" Return time grid spacing (ps) """ if not self._ready: raise exceptions.RuntimeError(self._not_ready_msg) else: return self._time_window / np.double(self._n)
def __get_W(self): r""" Return angular frequency grid (THz) """ if not self._ready: raise exceptions.RuntimeError(self._not_ready_msg) else: return self._V + self._w0
def _ext_units_mks(self): if self._external_units is None: exceptions.RuntimeError('Unit type has not been set.') return self._external_units == 'mks'
def _get_AW(self): if self._AW is not None: return self._AW.copy() else: raise exceptions.RuntimeError('Grids not yet set up.')