Modules
Top-level package for sarwaveifrproc.
- class sarwaveifrproc.utils.RobustScaler(medians, iqrs)[source]
Class to mimic scikit-learn RobustScaler. This is done in order to prevent warning messages when using pickle to load the scikit-learn scaler.
- sarwaveifrproc.utils.get_output_filename(l1x_path, output_safe, tail='e00')[source]
Constructs and returns the file path for saving a processed file based on input parameters.
- Parameters:
l1x_path (str): The path to the input file. It can be either a L1B or L1C file. root_savepath (str): The root directory where the processed file will be saved. tail (str, optional): The tail string to be appended to the filename corresponding to the processing options. Defaults to ‘e00’.
- Returns:
str: File path for saving the processed file.
- sarwaveifrproc.utils.get_output_safe(l1x_safe, root_savepath, tail='E00')[source]
Generates the final SAFE filename with specified modifications.
- Parameters:
l1x_safe (str): The input SAFE path. root_savepath (str): The root path for saving the output. tail (str): The tail to append to the filename. Defaults to ‘E00’.
- Returns:
str: The output savepath.
- Raises:
ValueError: If the input SAFE does not meet the filename requirements.
- sarwaveifrproc.utils.get_safe_date(safe)[source]
Extracts and returns the date and time from a given SAFE directory name.
- Parameters:
safe (str): SAFE directory name.
- Returns:
datetime: A datetime object representing the extracted date and time.
- sarwaveifrproc.utils.load_models(paths, predicted_variables)[source]
Loads models, scalers, and bins necessary for prediction.
- Parameters:
- paths (dict): Dictionary containing paths to model files, scaler files, and bin files.
- Keys:
‘model_intraburst’: Path to the intraburst model file.
‘model_interburst’: Path to the interburst model file.
‘scaler_intraburst’: Path to the intraburst scaler file.
‘scaler_interburst’: Path to the interburst scaler file.
‘bins_intraburst’: Path to the intraburst bins directory.
‘bins_interburst’: Path to the interburst bins directory.
predicted_variables (list): List of variable names to be predicted.
- Returns:
- tuple: Tuple containing the following items:
model_intraburst (tf.keras.Model): Intraburst model loaded from the provided path.
model_interburst (tf.keras.Model): Interburst model loaded from the provided path.
scaler_intraburst (RobustScaler): Intraburst scaler loaded from the provided path.
scaler_interburst (RobustScaler): Interburst scaler loaded from the provided path.
bins_intraburst (dict): Dictionary containing intraburst bins for each predicted variable.
bins_interburst (dict): Dictionary containing interburst bins for each predicted variable.
- sarwaveifrproc.utils.process_files(input_safe, output_safe, model_intraburst, model_interburst, scaler_intraburst, scaler_interburst, bins_intraburst, bins_interburst, predicted_variables, product_id)[source]
Processes files in the input directory, generates predictions, and saves results in the output directory.
- Parameters:
input_safe (str): Input safe path. output_safe (str): Path to the directory where output data will be saved. model_intraburst (tf.keras.Model): Intraburst model for prediction. model_interburst (tf.keras.Model): Interburst model for prediction. scaler_intraburst (RobustScaler): Scaler for intraburst data. scaler_interburst (RobustScaler): Scaler for interburst data. bins_intraburst (dict): Dictionary containing intraburst bins for each predicted variable. bins_interburst (dict): Dictionary containing interburst bins for each predicted variable. predicted_variables (list): List of variable names to be predicted. product_id (str): Identifier for the output product.
- Returns:
None
- sarwaveifrproc.l2_wave.compute_mean(x, y)[source]
Compute the expected value.
- Args:
x (np.ndarray): Input values. y (np.ndarray): Probabilities.
- Returns:
np.ndarray: Expected value.
- sarwaveifrproc.l2_wave.compute_std(x, y)[source]
Compute the standard deviation.
- Args:
x (np.ndarray): Input values. y (np.ndarray): Probabilities.
- Returns:
np.ndarray: Standard deviation.
- sarwaveifrproc.l2_wave.compute_values(ds, var, function, vectorize=False)[source]
Compute values for the given variable using the given function.
- Args:
ds (xr.Dataset): Dataset containing the data. var (str): Variable name. function (callable): Function to compute values. vectorize (bool): Whether to vectorize the computation.
- Returns:
xr.DataArray: Computed values.
- sarwaveifrproc.l2_wave.format_dataset(ds, predictions, predicted_variables, kept_variables, bins)[source]
Format a dataset based on predictions, variables, and bins.
Parameters: - ds (xarray.Dataset): Input dataset (l1b or l1c). - predictions (list): Predictions for each variable. - predicted_variables (list): List of predicted variable names. - kept_variables (list): List of variables from the input dataset that are kept in the final product. - bins (dict): Dictionary containing bin values for each variable.
Returns: - ds_pred (xarray.Dataset): Formatted dataset with predictions and original data.
The function computes various statistical values (mean, most likely, standard deviation) from the predictions and adds them to the new dataset. It also includes original data from the input dataset and some additional attributes.
- sarwaveifrproc.l2_wave.generate_intermediate_product(ds, model, scaler, bins, predicted_variables, kept_variables)[source]
Generate an intermediate l2 product, depending of the input dataset (intraburst or interburst).
Parameters: - ds (xarray.Dataset): Input dataset. - model: Machine learning model for predicting sea parameters. - scaler: Scaler used for normalization. - bins (dict): Dictionary containing bins for each variable. - predicted_variables (list): List of predicted variable names. - kept_variables (list): List of variables from the input dataset that are kept in the final product.
Returns: - ds_pred (xarray.Dataset): Intermediate predictions dataset.
- sarwaveifrproc.l2_wave.generate_l2_wave_product(xdt, intraburst_model, interburst_model, intraburst_scaler, interburst_scaler, intraburst_bins, interburst_bins, predicted_variables)[source]
Generate a level-2 wave (L2 WAV) product.
Parameters: - xdt (dict): DataTree containing intraburst and interburst datasets. - intraburst_model (tf.keras.Model): Machine learning model for intraburst predictions. - interburst_model (tf.keras.Model): Machine learning model for interburst predictions. - intraburst_scaler (Union[StandardScaler, MinMaxScaler, RobustScaler]): Scaler used for intraburst normalization. - interburst_scaler (Union[StandardScaler, MinMaxScaler, RobustScaler]): Scaler used for interburst normalization. - intraburst_bins (dict): Dictionary containing bins for intraburst variables. - interburst_bins (dict): Dictionary containing bins for interburst variables. - predicted_variables (list): List of predicted variable names. Returns: - l2_wave_product (dtt.DataTree): Level-2 wave product.
Notes: - The scaler objects should be one of StandardScaler, MinMaxScaler, or RobustScaler from sklearn.preprocessing.
- sarwaveifrproc.l2_wave.generate_product_on_land(ds, predicted_variables, kept_variables, bins)[source]
Patch function when input dataset does not contain all necessary variables.
Parameters: - ds (xarray.Dataset): Input dataset. - predicted_variables (list): List of predicted variable names. - kept_variables (list): List of variables from the input dataset that are kept in the final product. - bins (dict): Dictionary containing bins for each variable.
- sarwaveifrproc.l2_wave.get_attributes(var)[source]
Generate a dictionary of attributes for a given variable.
Parameters: - var (str): The variable name for which attributes are to be generated. This should correspond to keys in the spec_dict.
Returns: - attributes (dict): A dictionary containing various attributes for the given variable.
The function uses a predefined spec_dict to look up information about the variable. If the variable is not found in spec_dict, default attributes are generated with the variable name itself.
- sarwaveifrproc.l2_wave.get_most_likely(x, y)[source]
Get the maximum of probability for each prediction.
- Args:
x (np.ndarray): Input values. y (np.ndarray): Probabilities.
- Returns:
np.ndarray: Most likely values.
- sarwaveifrproc.l2_wave.predict_variables(sigma0, normalized_variance, incidence, azimuth_cutoff, cwave_params, model, scaler, indices)[source]
Launch predictions using a neural model.
Parameters: - sigma0 (xarray.DataArray): Array containing sigma0 values. - normalized_variance (xarray.DataArray): Array containing normalized variance values. - incidence (xarray.DataArray): Array containing incidence values. - azimuth_cutoff (xarray.DataArray): Array containing azimuth cutoff values. - cwave_params (xarray.DataArray): Array containing the cwave parameters. - model (tf.keras.Model): Machine learning model for predicting sea parameters. - scaler (Union[StandardScaler, MinMaxScaler, RobustScaler]): Scaler used for normalization. - indices (list): List of indices to segment predictions.
Returns: - res (tuple): Tuple containing predictions for each variable.