當前位置: 首頁>>代碼示例>>Python>>正文


Python Table.field方法代碼示例

本文整理匯總了Python中atpy.Table.field方法的典型用法代碼示例。如果您正苦於以下問題:Python Table.field方法的具體用法?Python Table.field怎麽用?Python Table.field使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在atpy.Table的用法示例。


在下文中一共展示了Table.field方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: SED

# 需要導入模塊: from atpy import Table [as 別名]
# 或者: from atpy.Table import field [as 別名]

#.........這裏部分代碼省略.........
            component.plot()
        plt.xlim(xlim)
        plt.ylim(ylim)
        plt.legend()
        logging.info('Writing {0}'.format(filename))
        plt.savefig(filename)

    def add_component(self, catalog_format, catalog_name,
                      object_name, plot_pivot=False, **ecpl_params):
        """ Read necessary parameters from FITS file and plot butterfly

        Parameters:
        catalog_format = 'hess', 'fermi'
        catalog_name = FITS file name
        object_name  = object name string in 'name' column

        Note: Since every catalog has columns with different
        names and units, a general SED plotting is not possible.
        Instead for each catalog type a handler function that
        deals converts to a standard format is called.

        @todo: Possibly pass plotting parameters along here by
        appending them to the ecpl_params dictionary
        -> I don't think this works at the moment!!!"""
        from atpy import Table
        # Get the catalog from file and initialize some things
        self.catalog_format = catalog_format
        self.catalog_name = catalog_name
        self.object_name = object_name
        self.catalog = Table(catalog_name).data
        # Build a dictionary of parameters needed for the plot
        self.ecpl_params = ecpl_params
        self.get_ecpl_params()
        # Plot curve
        self.plot_ecpl(plot_pivot=plot_pivot, **ecpl_params)
        # Plot points if present
        if self.plot_points is not None:
            # Get the values needed for plotting
            e = self.plot_points[0]
            f = self.plot_points[1]
            f_err = self.plot_points[2]
            e_err = self.plot_points[3]
            is_ul = self.plot_points[4]
            for ii in range(e.size):
                self.plot_point(e[ii], f[ii],
                                f_err=f_err[ii],
                                e_err=[[e_err[0][ii]], [e_err[1][ii]]],
                                ul=is_ul[ii])
            # Remove so that it doesn't get plotted again.
            self.plot_points = None

    def get_ecpl_params(self):
        """Build self.ecpl_params dictionary
        by parsing one of the supported catalogs"""
        if self.catalog_format == 'hess':
            self.get_ecpl_params_hess_cat()
        elif self.catalog_format == 'fermi':
            self.get_ecpl_params_fermi_cat()
        # Change numpy types to regular types
        # and replace nan values with 0
        for key, value in self.ecpl_params.items():
            if isinstance(value, np.float32):
                value = float(value)
            if isinstance(value, np.int16):
                value = int(value)

    def get_ecpl_params_fermi_cat(self):
        """ Build self.ecpl_params dictionary from Fermi catalog fields """
        i = self.find_object_index('source_name')
        # Set all plot parameters:
        self.ecpl_params['e_pivot'] = self.catalog.field('Pivot_Energy')[i]
        self.ecpl_params['e_min'] = 1e2
        self.ecpl_params['e_max'] = 1e5
        self.ecpl_params['e_cut'] = 0.0
        self.ecpl_params['e_cut_err'] = 0.0
        self.ecpl_params['e_scale'] = 1
        self.ecpl_params['norm'] = self.catalog.field('Flux_Density')[i]
        self.ecpl_params['norm_err'] = self.catalog.field('Unc_Flux_Density')[i]
        self.ecpl_params['norm_scale'] = 1
        self.ecpl_params['index'] = self.catalog.field('Spectral_Index')[i]
        self.ecpl_params['index_err'] = self.catalog.field('Unc_Spectral_Index')[i]
        self.ecpl_params['color'] = 'green'
        self.ecpl_params['butterfly'] = True
        # Set flux point data
        self.plot_points = self.get_flux_points_fermi(i)
        # Add text label
        fmt = '%s\n%s, %s\n' + \
            r'S = %3.1f, C = %3.1f, $\Gamma = %1.2f \pm %1.2f$'
        values = (self.object_name,
                  self.catalog.field('class1')[i],
                  self.catalog.field('assoc1')[i],
                  self.catalog.field('signif_avg')[i],
                  self.catalog.field('curvature_index')[i],
                  self.catalog.field('spectral_index')[i],
                  self.catalog.field('unc_spectral_index')[i]
                  )
        self.ax.text(0.05, 0.95, fmt % values,
                     horizontalalignment='left',
                     verticalalignment='top',
                     transform=self.ax.transAxes)
開發者ID:mwcraig,項目名稱:gammapy,代碼行數:104,代碼來源:sed.py


注:本文中的atpy.Table.field方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。