Exemplo n.º 1
0
def get_formatter(dtype):
    if types.is_datetime64_any_dtype(dtype):
        return DateFormatter(format="%Y-%m-%d %H:%M:%S.%N")
    elif types.is_bool_dtype(dtype):
        return None
        # return BooleanFormatter()
    else:
        return None
Exemplo n.º 2
0
    def _get_columns(self):
        if self.value is None:
            return []

        indexes = self.indexes
        col_names = list(self.value.columns)
        if not self.hierarchical or len(indexes) == 1:
            col_names = indexes + col_names
        else:
            col_names = indexes[-1:] + col_names
        df = self.value.reset_index() if len(indexes) > 1 else self.value
        columns = []
        for col in col_names:
            if col in df.columns:
                data = df[col]
            else:
                data = df.index

            col_kwargs = {}
            kind = data.dtype.kind
            if kind == 'i':
                formatter = NumberFormatter()
                editor = IntEditor()
            elif kind == 'f':
                formatter = NumberFormatter(format='0,0.0[00000]')
                editor = NumberEditor()
            elif isdatetime(data) or kind == 'M':
                formatter = DateFormatter(format='%Y-%m-%d %H:%M:%S')
                editor = DateEditor()
            else:
                formatter = StringFormatter()
                editor = StringEditor()

            if col in self.editors:
                editor = self.editors[col]

            if col in indexes or editor is None:
                editor = CellEditor()

            if col in self.formatters:
                formatter = self.formatters[col]
            if str(col) != col:
                self._renamed_cols[str(col)] = col
            if isinstance(self.widths, int):
                col_kwargs['width'] = self.widths
            elif str(col) in self.widths:
                col_kwargs['width'] = self.widths.get(str(col))

            title = str(col)
            if col in indexes and len(indexes) > 1 and self.hierarchical:
                title = 'Index: %s' % ' | '.join(indexes)
            column = TableColumn(field=str(col),
                                 title=title,
                                 editor=editor,
                                 formatter=formatter,
                                 **col_kwargs)
            columns.append(column)
        return columns
def get_table_formatters():
    datetime_formatter = DateFormatter(format="%Y-%m-%dT%H:%M")
    title_link_template = '''
          <table style="table-layout: fixed; width: 100%;white-space: normal;">
            <tr>
              <td style="word-wrap: break-word;text-align:left">
                <a href="<%= link %>"><%= value %></a>
              </td>
            </tr>
          </table>
        '''
    title_link_formatter = HTMLTemplateFormatter(template=title_link_template)

    return datetime_formatter, title_link_formatter
Exemplo n.º 4
0
    def _get_column_definitions(self, col_names, df):
        import pandas as pd
        indexes = self.indexes
        columns = []
        for col in col_names:
            if col in df.columns:
                data = df[col]
            else:
                data = df.index

            if isinstance(data, pd.DataFrame):
                raise ValueError("DataFrame contains duplicate column names.")

            col_kwargs = {}
            kind = data.dtype.kind
            if kind == 'i':
                formatter = NumberFormatter()
                editor = IntEditor()
            elif kind == 'b':
                formatter = StringFormatter()
                editor = CheckboxEditor()
            elif kind == 'f':
                formatter = NumberFormatter(format='0,0.0[00000]')
                editor = NumberEditor()
            elif isdatetime(data) or kind == 'M':
                if len(data) and isinstance(data.values[0], dt.date):
                    date_format = '%Y-%m-%d'
                else:
                    date_format = '%Y-%m-%d %H:%M:%S'
                formatter = DateFormatter(format=date_format)
                editor = DateEditor()
            else:
                formatter = StringFormatter()
                editor = StringEditor()

            if col in self.editors and not isinstance(self.editors[col],
                                                      (dict, str)):
                editor = self.editors[col]

            if col in indexes or editor is None:
                editor = CellEditor()

            if col in self.formatters and not isinstance(
                    self.formatters[col], (dict, str)):
                formatter = self.formatters[col]

            if str(col) != col:
                self._renamed_cols[str(col)] = col

            if isinstance(self.widths, int):
                col_kwargs['width'] = self.widths
            elif str(col) in self.widths:
                col_kwargs['width'] = self.widths.get(str(col))

            title = self.titles.get(col, str(col))
            if col in indexes and len(indexes) > 1 and self.hierarchical:
                title = 'Index: %s' % ' | '.join(indexes)
            column = TableColumn(field=str(col),
                                 title=title,
                                 editor=editor,
                                 formatter=formatter,
                                 **col_kwargs)
            columns.append(column)
        return columns
Exemplo n.º 5
0
]

data_table_loc = DataTable(source=source_table,
                           columns=columns,
                           height=500,
                           width=1000)

#Table Passengers
source_table_passengers = ColumnDataSource(data_passengers)

from bokeh.models.widgets.tables import DateFormatter

columns_passengers = [
    TableColumn(field='Bezugsjahr',
                title='Date',
                formatter=DateFormatter(format="%Y")),
    TableColumn(field='Code', title='Code'),
    TableColumn(field='Bahnhof_Haltestelle', title='Stop'),
    TableColumn(field='DTV', title='DTV'),
    TableColumn(field='DMW', title='DMW'),
    TableColumn(field='Eigner', title='Eigner'),
    TableColumn(field='geopos', title='GeoPos'),
]

data_table_passengers = DataTable(source=source_table_passengers,
                                  columns=columns_passengers,
                                  height=500,
                                  width=1000)

#Create the layout, column
layout_table = column(data_table_loc, data_table_passengers)
    days=["%m/%d/%Y %H:%M"],
    months=["%m/%d/%Y %H:%M"],
    hours=["%m/%d/%Y %H:%M"],
    minutes=["%m/%d/%Y %H:%M"]
)

p3.y_range = Range1d(0, 1000)
# }}}1

# ;------------;
# ; Data Table ;
# ;------------;
# {{{1
columns = [TableColumn(field="time",
                       title="Time",
                       formatter=DateFormatter(format="%m/%d/%Y %H:%M")),
           TableColumn(field="open", title="Open"),
           TableColumn(field="high", title="High"),
           TableColumn(field="low", title="Low"),
           TableColumn(field="close", title="Close"),
           TableColumn(field="volume", title="Volume")]
# }}}1

# Intro
print('\nGeneric Python CLI Application | {} | v{}\n'.format(
    get_global_property('APP_NAME'),
    get_global_property('APP_VERSION')))

# Test utilities.
utils.my_public_method()
utils.IO.my_public_method()
Exemplo n.º 7
0
    def __init__(self):

        # app variables
        self.active = True
        self.playAnimation = None
        self.start_epoch = None
        self.stop_epoch = None
        self.current_epoch = None

        # get initial configuration
        self.available_models = inspect.getmembers(StandardEphemerisModels,
                                                   inspect.isfunction)
        self.ephemeris_model = self.available_models[0][1]()
        self.spice_provider = SpiceProvider()
        self.spice_provider.SPICE_IDS = self.ephemeris_model.objects
        self.spice_provider.SPICE_NAMES = {
            v: k
            for k, v in self.ephemeris_model.objects.items()
        }

        # init data sources
        self.plot_source = self.spice_provider.state_source
        self.table_source = self.spice_provider.ephemeris_source
        self.cum_source = self.spice_provider.cum_source

        # gather options from ephemeris model and spice provider
        self.allowed_models = {
            model[1]().name: model[1]
            for model in self.available_models
        }
        allowed_objects = [
            self.spice_provider.fromId(name)
            for name in self.ephemeris_model.objects
        ]
        allowed_frames = self.ephemeris_model.FRAMES
        allowed_corrections = [name for name in SpiceProvider.CORRECTIONS]
        allowed_durations = [
            str(v) for v in self.ephemeris_model.DURATION_DAYS
        ]
        allowed_intervals = [name for name in SpiceProvider.INTERVALS]

        # set up widgets
        self.model = Select(title="Ephemeris Model",
                            options=list(self.allowed_models.keys()))

        self.center = Select(title="Center",
                             value=self.ephemeris_model.center,
                             options=allowed_objects)

        self.target = Select(title="Target",
                             value=self.ephemeris_model.target,
                             options=allowed_objects)

        self.frames = Select(title="Frame",
                             value=self.ephemeris_model.frame,
                             options=allowed_frames)

        self.planes = RadioButtonGroup(labels=['XY', 'YZ', 'XZ'], active=0)

        self.vector = Select(title='Vector Type',
                             value=self.ephemeris_model.vector_type,
                             options=allowed_corrections)

        self.epoch = DatePicker(title="Select Epoch",
                                value=datetime.strftime(
                                    self.ephemeris_model.epoch, "%Y-%m-%d"))

        self.offset = Slider(title="Days Since Epoch",
                             value=self.ephemeris_model.offset,
                             start=0,
                             end=self.ephemeris_model.duration,
                             step=1)

        self.duration = Select(title="Duration (Days)",
                               value=str(self.ephemeris_model.duration),
                               options=allowed_durations)

        self.interval = Select(title="Time Step",
                               value=str(self.ephemeris_model.step_size),
                               options=allowed_intervals)

        # create buttons
        self.play_button = Button(label="Play")
        self.exportRange = Div(text="Start and Stop Epoch: ")
        self.update_button = Button(label="Play")
        self.export_button = Button(label="Export")

        self.infoDiv = Div(
            text=
            "<hr>All ephemeris data shown on this website was obtained from publicly available "
            "SPICE files located at <a href='https://naif.jpl.nasa.gov/naif/data.html'>"
            "https://naif.jpl.nasa.gov/naif/data.html</a>, which is hosted by the  "
            "Navigation and Ancillary Information Facility (NAIF) at the NASA Jet Propulsion "
            "Laboratory. The exception is the SPICE kernel for the Parker Solar Probe, which is "
            "available at <a href='https://sppgway.jhuapl.edu/ancil_products'>"
            "https://sppgway.jhuapl.edu/ancil_products</a>, hosted by the Johns Hopkins University "
            "Applied Physics Laboratory. SpiceyPy is being used to process the SPICE files.",
            sizing_mode='stretch_width')

        # create plot tab objects
        self.plot = figure(match_aspect=True,
                           sizing_mode="stretch_both",
                           title="Astropynamics",
                           tools="hover, pan, reset, save",
                           tooltips=[("name", "@index")])

        self.plot.add_tools(BoxZoomTool(match_aspect=True))
        self.plot.circle('px',
                         'py',
                         size='radii',
                         source=self.plot_source,
                         line_width=3,
                         line_alpha=0.5,
                         name='XY')
        self.plot.circle('px',
                         'pz',
                         size='radii',
                         source=self.plot_source,
                         line_width=3,
                         line_alpha=0.5,
                         name='XZ').visible = False
        self.plot.circle('py',
                         'pz',
                         size='radii',
                         source=self.plot_source,
                         line_width=3,
                         line_alpha=0.5,
                         name='YZ').visible = False
        self.plot.line('px',
                       'py',
                       source=self.cum_source,
                       line_width=2,
                       line_alpha=0.5,
                       color='red',
                       name='XYOrbit')
        self.plot.line('px',
                       'pz',
                       source=self.cum_source,
                       line_width=2,
                       line_alpha=0.5,
                       color='red',
                       name='XZOrbit').visible = False
        self.plot.line('py',
                       'pz',
                       source=self.cum_source,
                       line_width=2,
                       line_alpha=0.5,
                       color='red',
                       name='YZOrbit').visible = False

        self.plotLayout = column(self.plot,
                                 self.offset,
                                 sizing_mode="stretch_width")
        self.plotTab = Panel(child=self.plotLayout, title="Display")

        # create data table tab objects
        fmt = NumberFormatter(format='0.000', text_align=TextAlign.right)
        columns = [
            TableColumn(field="index",
                        title="Epoch",
                        formatter=DateFormatter(format="%m/%d/%Y %H:%M:%S")),
            TableColumn(field="px", title="PX", formatter=fmt, width=10),
            TableColumn(field="py", title="PY", formatter=fmt),
            TableColumn(field="pz", title="PZ", formatter=fmt),
            TableColumn(field="vx", title="VX", formatter=fmt),
            TableColumn(field="vy", title="VY", formatter=fmt),
            TableColumn(field="vz", title="VZ", formatter=fmt)
        ]

        self.ephemerisTable = DataTable(source=self.table_source,
                                        columns=columns,
                                        sizing_mode="stretch_both")
        self.ephemerisLayout = column(self.exportRange,
                                      self.ephemerisTable,
                                      sizing_mode="stretch_width")
        self.dataTab = Panel(child=self.ephemerisLayout, title="Table")

        self.kernels = Div()
        self.kernelTab = Panel(child=self.kernels, title="Kernels")

        self.tabs = Tabs(tabs=[self.plotTab, self.dataTab, self.kernelTab])

        # init data
        self.model.value = "The Solar System"
        self.update_model(None, 0, self.model.value)
        self.update_epochs(None, 0, 0)
        self.update_states(None, 0, 0)

        self.model.on_change('value', self.update_model)
        self.frames.on_change('value', self.update_epochs)
        self.planes.on_change('active', self.update_plot_view)
        self.center.on_change('value', self.update_epochs)
        self.target.on_change('value', self.update_epochs)
        self.offset.on_change('value', self.update_offset)
        self.epoch.on_change('value', self.update_epochs)
        self.duration.on_change('value', self.update_epochs)
        self.interval.on_change('value', self.update_epochs)
        self.update_button.on_click(self.update_onclick)
        self.tabs.on_change('active', self.update_button_type)

        self.inputs = column(self.model, self.frames, self.planes, self.center,
                             self.target, self.epoch, self.duration,
                             self.interval, self.update_button)