예제 #1
0
 def generate_times(self, exposuretime: u.s):
     if callable(self.flux):
         return self.flux(exposuretime, self.geomarea)
     elif hasattr(self.flux, 'isscalar') and self.flux.isscalar:
         return np.arange(0, exposuretime.to(u.s).value,
                          1. / (self.flux * self.geomarea * u.s).decompose()) * u.s
     else:
         raise SourceSpecificationError('`flux` must be a quantity or a callable.')
예제 #2
0
 def dt_input(self, dt: u.s):
     if dt is None:
         self._dt_input = None
     elif isinstance(dt, u.Quantity):
         try:
             dt = dt.to(u.s)
             if dt > 0 * u.s:
                 self._dt_input = dt
         except (AttributeError, u.UnitConversionError):
             raise NEIError("Invalid dt.")
예제 #3
0
 def __init__(self,
              observing_time: u.s,
              observer,
              assumed_cross_section=1e14 * u.cm**2,
              pad_fov=None):
     self.observing_time = np.arange(*observing_time.to('s').value,
                                     self.cadence.to('s').value) * u.s
     self.observer = observer.transform_to(HeliographicStonyhurst)
     self.assumed_cross_section = assumed_cross_section
     self.pad_fov = (0, 0) * u.arcsec if pad_fov is None else pad_fov
예제 #4
0
 def dt_max(self, value: u.s):
     if not isinstance(value, u.Quantity):
         raise TypeError("dt_max must be a Quantity.")
     try:
         value = value.to(u.s)
     except u.UnitConversionError as exc:
         raise u.UnitConversionError("Invalid units for dt_max.") from exc
     if (hasattr(self, "_dt_input") and self.dt_input is not None
             and self.dt_input > value):
         raise ValueError("dt_max cannot be less the inputted time step.")
     if hasattr(self, "_dt_min") and self.dt_min > value:
         raise ValueError("dt_min cannot exceed dt_max.")
     self._dt_max = value
예제 #5
0
    def generate_photons(self, exposuretime: u.s):
        '''Central function to generate photons.

        Calling this function generates a photon table according to
        the `flux`, `energy`, and `polarization` of this source. The
        number of photons depends on the total exposure time, which is
        a parameter of this function. Depending on the setting for
        `flux` the photons could be distributed equally over the
        interval 0..exposuretime or follow some other distribution.

        Parameters
        ----------
        exposuretime : `astropy.quantity.Quantity`
            Total exposure time.

        Returns
        -------
        photons : `astropy.table.Table`
            Table with photon properties.

        '''
        times = self.generate_times(exposuretime)
        energies = self.generate_energies(times)
        pol = self.generate_polarization(times, energies)
        n = len(times)
        photons = Table([times.to(u.s).value,
                         energies.to(u.keV).value,
                         pol.to(u.rad).value,
                         np.ones(n)],
                        names=['time', 'energy', 'polangle', 'probability'])
        photons.meta['EXTNAME'] = 'EVENTS'
        photons.meta['EXPOSURE'] = (exposuretime.to(u.s).value,
                                    'total exposure time [s]')

        #photons.meta['DATE-OBS'] =
        photons.meta['CREATOR'] = 'MARXS - Version {0}'.format(marxsversion)
        photons.meta["LONGSTRN"] = ("OGIP 1.0", "The OGIP long string convention may be used.")
        photons.meta['MARXSVER'] = (marxsversion, 'MARXS version')
        now = datetime.now()
        photons.meta['SIMDATE'] = (str(now.date()), 'Date simulation was run')
        photons.meta['SIMTIME'] = (str(now.time())[:10], 'Time simulation was started')
        photons.meta['SIMUSER'] = (os.environ.get('USER', 'unknown user'),
                                   'User running simulation')
        photons.meta['SIMHOST'] = (os.environ.get('HOST', 'unknown host'),
                                   'Host system running simulation')
        photons['time'].unit = u.s
        photons['energy'].unit = u.keV
        photons['polangle'].unit = u.rad
        return photons
예제 #6
0
 def time_input(self, times: u.s):
     if times is None:
         self._time_input = None
     elif isinstance(times, u.Quantity):
         if times.isscalar:
             raise ValueError("time_input must be an array.")
         try:
             times = times.to(u.s)
         except u.UnitConversionError:
             raise u.UnitsError(
                 "time_input must have units of seconds.") from None
         if not np.all(times[1:] > times[:-1]):
             raise ValueError("time_input must monotonically increase.")
         self._time_input = times
     else:
         raise TypeError("Invalid time_input.")
예제 #7
0
 def time_max(self, time: u.s):
     if time is None:
         self._time_max = (self.time_input[-1]
                           if self.time_input is not None else np.inf * u.s)
     elif isinstance(time, u.Quantity):
         if not time.isscalar:
             raise ValueError("time_max must be a scalar")
         try:
             time = time.to(u.s)
         except u.UnitConversionError:
             raise u.UnitsError(
                 "time_max must have units of seconds") from None
         if (hasattr(self, "_time_start") and self._time_start is not None
                 and self._time_start >= time):
             raise ValueError("time_max must be greater than time_start")
         self._time_max = time
     else:
         raise TypeError("Invalid time_max.") from None
예제 #8
0
 def time_start(self, time: u.s):
     if time is None:
         self._time_start = 0.0 * u.s
     elif isinstance(time, u.Quantity):
         if not time.isscalar:
             raise ValueError("time_start must be a scalar")
         try:
             time = time.to(u.s)
         except u.UnitConversionError:
             raise u.UnitsError(
                 "time_start must have units of seconds") from None
         if (hasattr(self, "_time_max") and self._time_max is not None
                 and self._time_max <= time):
             raise ValueError("Need time_start < time_max.")
         if self.time_input is not None and self.time_input.min() > time:
             raise ValueError(
                 "time_start must be less than min(time_input)")
         self._time_start = time
     else:
         raise TypeError("Invalid time_start.") from None
예제 #9
0
 def __init__(self, value: u.s):
     super().__init__(value)
     self.value = value.to_value(u.s)
예제 #10
0
파일: attrs.py 프로젝트: ravindra1307/sunpy
 def __init__(self, value: u.s):
     super(Sample, self).__init__(value)
     self.value = value.to(u.s).value
예제 #11
0
 def __init__(self, value: u.s):
     super(Sample, self).__init__(value)
     self.value = value.to(u.s).value
예제 #12
0
 def __init__(self, duration: u.s, stress):
     self.duration = duration.to(u.s).value
     self.stress = stress