credit.transforms.transforms_global
===================================

.. py:module:: credit.transforms.transforms_global

.. autoapi-nested-parse::

   normalize_global.py
   -------------------------------------------------------
   Content
       - Normalize_ERA5_and_Forcing
       - ToTensor_ERA5_and_Forcing



Attributes
----------

.. autoapisummary::

   credit.transforms.transforms_global.logger


Classes
-------

.. autoapisummary::

   credit.transforms.transforms_global.Normalize_ERA5_and_Forcing
   credit.transforms.transforms_global.ToTensor_ERA5_and_Forcing


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

.. py:data:: logger

.. py:class:: Normalize_ERA5_and_Forcing(conf)

   Class to normalize ERA5 and Forcing Datasets.


   .. py:attribute:: mean_ds


   .. py:attribute:: std_ds


   .. py:attribute:: mean_tensors


   .. py:attribute:: std_tensors


   .. py:attribute:: levels


   .. py:attribute:: varname_upper_air


   .. py:attribute:: num_upper_air


   .. py:attribute:: flag_surface


   .. py:attribute:: flag_dyn_forcing


   .. py:attribute:: flag_diagnostic


   .. py:attribute:: flag_forcing


   .. py:attribute:: flag_static


   .. py:method:: __call__(sample: credit.data.Sample, inverse: bool = False) -> credit.data.Sample

      Normalize ERA5 and Forcing.

      :param sample: batch.
      :param inverse: whether to transform or inverse transform the sample.

      :returns: transformed and normalized sample.
      :rtype: torch.tensor



   .. py:method:: transform_dataset(DS: xarray.Dataset) -> xarray.Dataset


   .. py:method:: transform_array(x: torch.Tensor) -> torch.Tensor

      Transform of y_pred.

      Transform via provided scaler file/s of the prediction variable.
      Dynamic forcing, forcing, and static vars not transformed.

      :param x: batch.

      :returns: transformed x.



   .. py:method:: transform(sample: Dict[str, numpy.ndarray]) -> Dict[str, numpy.ndarray]

      Transform training batches.

      Transform handles forcing & static as follows:
      - forcing & static don't need to be transformed; users should transform them and save them to the file
      - other variables (upper-air, surface, dynamic forcing, diagnostics) need to be transformed

      :param sample: batch.

      :returns: transformed sample.



   .. py:method:: inverse_transform(x: torch.Tensor) -> torch.Tensor

      Inverse transform of y_pred.

      Inverse transform of prediction variable. Dynamic forcing, forcing,
      and static vars not transformed.

      :param x: batch.

      :returns: inverse transformed x.



   .. py:method:: inverse_transform_input(x: torch.Tensor) -> torch.Tensor

      Inverse transform for input x.

      Forcing and static variables are not transformed
      (they were not transformed in the transform function).

      :param x: batch.

      :returns: transformed x.



   .. py:method:: _align_coords(DS: xarray.Dataset, ref_ds: xarray.Dataset, rtol: float = 1e-06, atol: float = 1e-08) -> xarray.Dataset

      Ensure DS has the same lat/lon as ref_ds (to within tolerance),
      then re-assign DS.coords to exactly match ref_ds.coords.



   .. py:method:: inverse_transform_dataset(DS: xarray.Dataset, rtol: float = 1e-06, atol: float = 1e-08) -> xarray.Dataset

      Inverse‐transform DS by (DS * std_ds) + mean_ds, after
      aligning its coordinates to mean_ds/std_ds.



.. py:class:: ToTensor_ERA5_and_Forcing(conf)

   Class to convert ERA5 and Forcing Datasets to torch tensor.


   .. py:attribute:: conf


   .. py:attribute:: output_dtype
      :value: Ellipsis



   .. py:attribute:: hist_len


   .. py:attribute:: for_len


   .. py:attribute:: flag_surface


   .. py:attribute:: flag_dyn_forcing


   .. py:attribute:: flag_diagnostic


   .. py:attribute:: flag_forcing


   .. py:attribute:: flag_static


   .. py:attribute:: varname_upper_air


   .. py:attribute:: flag_upper_air
      :value: True



   .. py:attribute:: num_forcing_static
      :value: 0



   .. py:method:: __call__(sample: credit.data.Sample) -> credit.data.Sample

      Convert variables to input/output torch tensors.

      :param sample: batch.
      :type sample: interator

      :returns: converted torch tensor.
      :rtype: torch.tensor



