Пример #1
0
def plot_residuals(dset):
    """Plot residuals

    Args:
        dset:   Dataset, information about model run.
    """
    log.out(f"Residuals at stage {dset.vars['stage']}")
    hipsterplot.plot(x_vals=dset.time.utc.datetime,
                     y_vals=dset.residual,
                     num_x_chars=console.columns() - 12,
                     num_y_chars=20)
Пример #2
0
    def entry_as_str(self,
                     width: Optional[builtins.int] = None,
                     key_width: builtins.int = 30,
                     metadata: builtins.bool = True) -> builtins.str:
        """The configuration entry represented as a string

        This is simililar to what is shown by `str(entry)` (and implemented by `__str__`), but has more flexibility.

        Args:
            width:      Width of text for wrapping. Default is width of console.
            key_width:  Width of the key column. Default is 30 characters.
            metadata:   Include metadata like type and help text.

        Returns:
            String representation of the configuration entry.
        """
        lines = list()
        width = console.columns() if width is None else width
        fill_args = dict(width=width,
                         hanging=key_width + 3,
                         break_long_words=False,
                         break_on_hyphens=False)

        # The entry itself
        lines.append(
            console.fill(f"{self._key:<{key_width}} = {self._value}",
                         **fill_args))

        # Metadata, including help text and type hints
        if metadata and self.meta:
            for meta_key, meta_value in self.meta.items():
                if meta_value is None:
                    lines.append(
                        console.fill(f"{self._key}:{meta_key}", **fill_args))
                else:
                    lines.append(
                        console.fill(
                            f"{f'{self._key}:{meta_key}':<{key_width}} = {meta_value}",
                            **fill_args))
            lines.append("")

        return "\n".join(lines)
Пример #3
0
def show_config(rundate, pipeline, *args, **kwargs):
    """Show the configuration of a Where analysis

    """
    line = "=" * console.columns()

    # Warn about missing session
    if not has_config(rundate, pipeline, *args, **kwargs):
        log.warn(
            f"No configuration found for {pipeline.upper()} {rundate.strftime(config.FMT_date)}"
        )

    # Read configuration from file
    else:
        cfg = _read_config(rundate, pipeline, *args, **kwargs)

        # Print configuration to console
        print(line)
        print(f"{pipeline.upper()} {rundate.strftime(config.FMT_date)}\n")
        print(cfg)
        print(f"\nConfig file at {', '.join(cfg.sources)}")
Пример #4
0
def show_config(rundate, pipeline, session):
    """Show the configuration of a Where analysis

    """
    line = "=" * console.columns()

    # Warn about missing session
    if not has_config(rundate, pipeline, session):
        log.warn(
            f"No configuration found for {pipeline.upper()} {session} {rundate.strftime(config.FMT_date)}"
        )

    # Read configuration from file
    else:
        cfg = _read_config(rundate, pipeline, session)

        # Print configuration to console
        print(line)
        print(
            f"{pipeline.upper()} {session} {rundate.strftime(config.FMT_date)}\n"
        )
        print(cfg)
        print(f"\nConfig file at {', '.join(cfg.sources)}")

    # Add instructions about how to update configuration
    print(line)
    pipeline_opt = [
        o for o, p in pipelines.options().items()
        if p == pipeline and o.startswith("--")
    ][0]
    cmd = f"{util.get_program_name()} {rundate.year} {rundate.month} {rundate.day} {pipeline_opt} --session={session}"
    print(f"Use '{cmd} --edit' to edit configuration manually")
    print(
        f"    '{cmd} --<key>=<value>' to update an entry in the [{pipeline}] section"
    )
    print(
        f"    '{cmd} --<section>:<key>=<value>' to update an entry in a specific section"
    )
Пример #5
0
def test_console_width_is_positive():
    """Test that number of columns in the console is positive"""
    assert console.columns() > 0