credit.cli._convert
===================

.. py:module:: credit.cli._convert

.. autoapi-nested-parse::

   credit init and credit convert command handlers.



Attributes
----------

.. autoapisummary::

   credit.cli._convert._SPATIAL_TIME_DIMS


Classes
-------

.. autoapisummary::

   credit.cli._convert._FlowSeqDumper


Functions
---------

.. autoapisummary::

   credit.cli._convert._build_bridgescaler_jsons
   credit.cli._convert._yaml_dump
   credit.cli._convert._zarr_dims
   credit.cli._convert._write_reload_config
   credit.cli._convert._convert
   credit.cli._convert._init


Module Contents
---------------

.. py:function:: _build_bridgescaler_jsons(mean_path, std_path, var_groups, pre_out, post_out, source_name='ERA5')

   Convert old mean/std NetCDF files into two BridgeScaler JSON files.

   Creates one JSON for the preblock (batch-dict key structure) and one for
   the postblock (reconstructed prediction-dict structure).

   :param mean_path: Paths to NetCDF files with per-variable means and standard deviations.
                     3-D variables have a 'level' dimension; 2-D variables are scalars.
   :type mean_path: str
   :param std_path: Paths to NetCDF files with per-variable means and standard deviations.
                    3-D variables have a 'level' dimension; 2-D variables are scalars.
   :type std_path: str
   :param var_groups: ``{(field_type, dim): [varname, ...]}`` — maps ("prognostic", "3d") etc.
                      to the list of variable names that belong to that group.
   :type var_groups: dict
   :param pre_out: Output path for the preblock scaler JSON.
   :type pre_out: str
   :param post_out: Output path for the postblock scaler JSON.
   :type post_out: str

   :returns: * **pre_keys** (*list[str]*) -- Full key paths included in the preblock scaler
               (e.g. ``"era5/prognostic/3d/temperature"``).
             * **post_prog_vars** (*list[str]*) -- Short variable names of prognostic vars in the postblock scaler.


.. py:class:: _FlowSeqDumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)

   Bases: :py:obj:`yaml.Dumper`


   YAML dumper that writes lists of scalars as flow sequences [a, b, c].


   .. py:method:: represent_sequence(tag, sequence, flow_style=None)


.. py:function:: _yaml_dump(conf, f)

.. py:data:: _SPATIAL_TIME_DIMS

.. py:function:: _zarr_dims(glob_path: str) -> list[str] | None

   Return all dimension names from the first matching file, or None on failure.


.. py:function:: _write_reload_config(config_path: str) -> str

   Patch trainer reload fields and write a reload config next to the checkpoint.

   Reads the YAML at *config_path*, sets the five fields required for a clean
   resume, and writes the result to ``<save_loc>/config_reload.yml``.

   Returns the path to the written reload config.


.. py:function:: _convert(args: argparse.Namespace) -> None

   Interactive v1 → v2 config converter.


.. py:function:: _init(args: argparse.Namespace) -> None

   Copy a config template to the user's desired location.


