示例#1
0
    def thin(self, rel_err=1.e-4, preserve_range=False):
        """Thin out the internal wavelengths of a Bandpass that uses a LookupTable.

        If the bandpass was initialized with a LookupTable or from a file (which internally
        creates a LookupTable), this function removes tabulated values while keeping the integral
        over the set of tabulated values still accurate to the given relative error.

        That is, the integral of the bandpass function is preserved to a relative precision
        of `rel_err`, while eliminating as many internal wavelength values as possible.  This
        process will usually help speed up integrations using this bandpass.  You should weigh
        the speed improvements against your fidelity requirements for your particular use
        case.

        @param rel_err            The relative error allowed in the integral over the throughput
                                  function. [default: 1.e-4]
        @param preserve_range     Should the original range (`blue_limit` and `red_limit`) of the
                                  Bandpass be preserved? (True) Or should the ends be trimmed to
                                  include only the region where the integral is significant? (False)
                                  [default: False]

        @returns the thinned Bandpass.
        """
        if len(self.wave_list) > 0:
            x = self.wave_list
            f = self(x)
            newx, newf = utilities.thin_tabulated_values(
                x, f, rel_err=rel_err, preserve_range=preserve_range)
            tp = galsim.LookupTable(newx, newf, interpolant='linear')
            blue_limit = np.min(newx)
            red_limit = np.max(newx)
            wave_list = np.array(newx)
            return Bandpass(tp, blue_limit, red_limit, _wave_list=wave_list)
        else:
            return self
示例#2
0
文件: sed.py 项目: inonchiu/GalSim
    def thin(self, rel_err=1.e-4, preserve_range=False):
        """ If the SED was initialized with a LookupTable or from a file (which internally creates a
        LookupTable), then remove tabulated values while keeping the integral over the set of
        tabulated values still accurate to `rel_err`.

        @param rel_err            The relative error allowed in the integral over the SED
                                  [default: 1.e-4]
        @param preserve_range     Should the original range (`blue_limit` and `red_limit`) of the
                                  SED be preserved? (True) Or should the ends be trimmed to
                                  include only the region where the integral is significant? (False)
                                  [default: False]

        @returns the thinned SED.
        """
        if len(self.wave_list) > 0:
            wave_factor = 1.0 + self.redshift
            x = self.wave_list / wave_factor
            f = self._rest_photons(x)
            newx, newf = utilities.thin_tabulated_values(x, f, rel_err=rel_err,
                                                         preserve_range=preserve_range)
            spec = galsim.LookupTable(newx, newf, interpolant='linear')
            blue_limit = np.min(newx) * wave_factor
            red_limit = np.max(newx) * wave_factor
            wave_list = np.array(newx) * wave_factor
            return SED(spec, flux_type='fphotons', redshift=self.redshift,
                       _wave_list=wave_list, _blue_limit=blue_limit, _red_limit=red_limit)
        else:
            return self
示例#3
0
文件: bandpass.py 项目: mjuric/GalSim
    def thin(self, rel_err=1.e-4, preserve_range=False):
        """Thin out the internal wavelengths of a Bandpass that uses a LookupTable.

        If the bandpass was initialized with a LookupTable or from a file (which internally
        creates a LookupTable), this function removes tabulated values while keeping the integral
        over the set of tabulated values still accurate to the given relative error.

        That is, the integral of the bandpass function is preserved to a relative precision
        of `rel_err`, while eliminating as many internal wavelength values as possible.  This
        process will usually help speed up integrations using this bandpass.  You should weigh
        the speed improvements against your fidelity requirements for your particular use
        case.

        @param rel_err            The relative error allowed in the integral over the throughput
                                  function. [default: 1.e-4]
        @param preserve_range     Should the original range (`blue_limit` and `red_limit`) of the
                                  Bandpass be preserved? (True) Or should the ends be trimmed to
                                  include only the region where the integral is significant? (False)
                                  [default: False]

        @returns the thinned Bandpass.
        """
        if len(self.wave_list) > 0:
            x = self.wave_list
            f = self(x)
            newx, newf = utilities.thin_tabulated_values(x, f, rel_err=rel_err,
                                                         preserve_range=preserve_range)
            tp = galsim.LookupTable(newx, newf, interpolant='linear')
            blue_limit = np.min(newx)
            red_limit = np.max(newx)
            wave_list = np.array(newx)
            return Bandpass(tp, blue_limit, red_limit, _wave_list=wave_list)
        else:
            return self
示例#4
0
    def thin(self, rel_err=1.e-4, trim_zeros=True, preserve_range=True, fast_search=True):
        """Thin out the internal wavelengths of a Bandpass that uses a LookupTable.

        If the bandpass was initialized with a LookupTable or from a file (which internally
        creates a LookupTable), this function removes tabulated values while keeping the integral
        over the set of tabulated values still accurate to the given relative error.

        That is, the integral of the bandpass function is preserved to a relative precision
        of `rel_err`, while eliminating as many internal wavelength values as possible.  This
        process will usually help speed up integrations using this bandpass.  You should weigh
        the speed improvements against your fidelity requirements for your particular use
        case.

        @param rel_err            The relative error allowed in the integral over the throughput
                                  function. [default: 1.e-4]
        @param trim_zeros         Remove redundant leading and trailing points where f=0?  (The last
                                  leading point with f=0 and the first trailing point with f=0 will
                                  be retained).  Note that if both trim_leading_zeros and
                                  preserve_range are True, then the only the range of `x` *after*
                                  zero trimming is preserved.  [default: True]
        @param preserve_range     Should the original range (`blue_limit` and `red_limit`) of the
                                  Bandpass be preserved? (True) Or should the ends be trimmed to
                                  include only the region where the integral is significant? (False)
                                  [default: True]
        @param fast_search        If set to True, then the underlying algorithm will use a
                                  relatively fast O(N) algorithm to select points to include in the
                                  thinned approximation.  If set to False, then a slower O(N^2)
                                  algorithm will be used.  We have found that the slower algorithm
                                  tends to yield a thinned representation that retains fewer samples
                                  while still meeting the relative error requirement, and may also
                                  be somewhat more robust when computing SED fluxes through
                                  Bandpasses when a significant fraction of the integrated flux
                                  passes through low throughput bandpass light leaks.
                                  [default: True]

        @returns the thinned Bandpass.
        """
        if len(self.wave_list) > 0:
            x = self.wave_list
            f = self(x)
            newx, newf = utilities.thin_tabulated_values(x, f, rel_err=rel_err,
                                                         trim_zeros=trim_zeros,
                                                         preserve_range=preserve_range,
                                                         fast_search=fast_search)
            tp = galsim.LookupTable(newx, newf, interpolant='linear')
            blue_limit = np.min(newx)
            red_limit = np.max(newx)
            wave_list = np.array(newx)
            return Bandpass(tp, 'nm', blue_limit, red_limit, _wave_list=wave_list)
        else:
            return self
示例#5
0
文件: sed.py 项目: AriannaLanz/GalSim
    def thin(self, rel_err=1.e-4, trim_zeros=True, preserve_range=True, fast_search=True):
        """ If the SED was initialized with a LookupTable or from a file (which internally creates a
        LookupTable), then remove tabulated values while keeping the integral over the set of
        tabulated values still accurate to `rel_err`.

        @param rel_err            The relative error allowed in the integral over the SED
                                  [default: 1.e-4]
        @param trim_zeros         Remove redundant leading and trailing points where f=0?  (The last
                                  leading point with f=0 and the first trailing point with f=0 will
                                  be retained).  Note that if both trim_leading_zeros and
                                  preserve_range are True, then the only the range of `x` *after*
                                  zero trimming is preserved.  [default: True]
        @param preserve_range     Should the original range (`blue_limit` and `red_limit`) of the
                                  SED be preserved? (True) Or should the ends be trimmed to
                                  include only the region where the integral is significant? (False)
                                  [default: True]
        @param fast_search        If set to True, then the underlying algorithm will use a
                                  relatively fast O(N) algorithm to select points to include in the
                                  thinned approximation.  If set to False, then a slower O(N^2)
                                  algorithm will be used.  We have found that the slower algorithm
                                  tends to yield a thinned representation that retains fewer samples
                                  while still meeting the relative error requirement.
                                  [default: True]

        @returns the thinned SED.
        """
        if len(self.wave_list) > 0:
            wave_factor = 1.0 + self.redshift
            x = self.wave_list / wave_factor
            f = self._rest_photons(x)
            newx, newf = utilities.thin_tabulated_values(x, f, rel_err=rel_err,
                                                         trim_zeros=trim_zeros,
                                                         preserve_range=preserve_range,
                                                         fast_search=fast_search)
            spec = galsim.LookupTable(newx, newf, interpolant='linear')
            blue_limit = np.min(newx) * wave_factor
            red_limit = np.max(newx) * wave_factor
            wave_list = np.array(newx) * wave_factor
            return SED(spec, wave_type='nm', flux_type='fphotons',
                       redshift=self.redshift, _wave_list=wave_list,
                       _blue_limit=blue_limit, _red_limit=red_limit)
        else:
            return self