axes.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:specviz 作者: spacetelescope 项目源码 文件源码
def tickStrings(self, values, scale, spacing):
        """
        Defines the tick marking format based on display mode

        See `~pygtgraph.AxisItem` for parameter definitions.
        """
        if self._layer is None:
            return super(DynamicAxisItem, self).tickStrings(values, scale,
                                                            spacing)

        spatial_unit = self._layer.masked_dispersion.data.unit
        dispersion = self._layer.masked_dispersion
        inds = np.arange(dispersion.size, dtype=int)

        if self.mode == 0:
            c = const.c.to('{}/s'.format(spatial_unit))

            waves = u.Quantity(np.array(values), spatial_unit)

            ref_wave = u.Quantity(self.ref_wave, spatial_unit)

            v_quant = ((waves - ref_wave) / waves * c).to('km/s')
            v = v_quant.value
            v[np.isnan(v)] = 0.0

            self.setLabel("Velocity [{}]".format(v_quant.unit), None, None)

            return ["{:.4E}".format(x) for x in v]
        elif self.mode == 1:
            self.setLabel('Redshifted Wavelength [{}]'.format(spatial_unit))

            return ["{:0.2f}".format(v / (1 + self.redshift) * scale)
                    for v in values]
        elif self.mode == 2:
            self.setLabel("Pixel", None, None)
            inds = np.searchsorted(dispersion, values)

            return list(inds)

        return super(DynamicAxisItem, self).tickStrings(values, scale, spacing)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号