|
| 1 | +# (C) Copyright 2024 NOAA/NWS/EMC |
| 2 | +# |
| 3 | +# (C) Copyright 2024 United States Government as represented by the Administrator of the |
| 4 | +# National Aeronautics and Space Administration. All Rights Reserved. |
| 5 | +# |
| 6 | +# This software is licensed under the terms of the Apache Licence Version 2.0 |
| 7 | +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 8 | + |
| 9 | +# -------------------------------------------------------------------------------------------------- |
| 10 | + |
| 11 | +import os |
| 12 | +import netCDF4 as nc |
| 13 | +import numpy as np |
| 14 | +from xarray import Dataset, open_dataset |
| 15 | +from eva.utilities.config import get |
| 16 | +from eva.data.eva_dataset_base import EvaDatasetBase |
| 17 | +from eva.utilities.utils import parse_channel_list |
| 18 | + |
| 19 | + |
| 20 | +class GeovalSpace(EvaDatasetBase): |
| 21 | + |
| 22 | + """ |
| 23 | + A class for handling geoval files |
| 24 | + """ |
| 25 | + |
| 26 | + def execute(self, dataset_config, data_collections, timing): |
| 27 | + |
| 28 | + """ |
| 29 | + Executes the processing of data file dataset. |
| 30 | +
|
| 31 | + Args: |
| 32 | + dataset_config (dict): Configuration dictionary for the dataset. |
| 33 | + data_collections (DataCollections): Object for managing data collections. |
| 34 | + timing (Timing): Timing object for tracking execution time. |
| 35 | + """ |
| 36 | + |
| 37 | + # Set the collection name |
| 38 | + # ----------------------- |
| 39 | + collection_name = get(dataset_config, self.logger, 'name') |
| 40 | + |
| 41 | + # Get missing value threshold |
| 42 | + # --------------------------- |
| 43 | + threshold = float(get(dataset_config, self.logger, 'missing_value_threshold', 1.0e30)) |
| 44 | + |
| 45 | + # Get levels to plot profiles |
| 46 | + # --------------------------_ |
| 47 | + levels_str_or_list = get(dataset_config, self.logger, 'levels', []) |
| 48 | + |
| 49 | + # Convert levels to list |
| 50 | + levels = [] |
| 51 | + if levels_str_or_list is not []: |
| 52 | + levels = parse_channel_list(levels_str_or_list, self.logger) |
| 53 | + |
| 54 | + # Filename to be used for reads |
| 55 | + # --------------------------------------- |
| 56 | + data_filename = get(dataset_config, self.logger, 'data_file') |
| 57 | + |
| 58 | + # Get instrument name |
| 59 | + instr_name = get(dataset_config, self.logger, 'instrument_name') |
| 60 | + |
| 61 | + # Open instrument files xarray dataset |
| 62 | + instr_ds = open_dataset(data_filename) |
| 63 | + |
| 64 | + # Enforce that a variable exists, do not default to all variables |
| 65 | + variables = get(dataset_config, self.logger, 'variables') |
| 66 | + if not variables: |
| 67 | + self.logger.abort('A variables list needs to be defined in the config file.') |
| 68 | + vars_to_remove = list(set(list(instr_ds.keys())) - set(variables)) |
| 69 | + instr_ds = instr_ds.drop_vars(vars_to_remove) |
| 70 | + |
| 71 | + # Rename variables and nval dimension |
| 72 | + rename_dict = {} |
| 73 | + rename_dims_dict = {} |
| 74 | + for v in variables: |
| 75 | + # Retrieve dimension names |
| 76 | + dims = instr_ds[v].dims |
| 77 | + if np.size(dims) > 1: |
| 78 | + rename_dims_dict[dims[1]] = f'Level' |
| 79 | + rename_dict[v] = f'{instr_name}::{v}' |
| 80 | + instr_ds = instr_ds.rename(rename_dict) |
| 81 | + instr_ds = instr_ds.rename_dims(rename_dims_dict) |
| 82 | + |
| 83 | + # Add the dataset_config to the collections |
| 84 | + data_collections.create_or_add_to_collection(collection_name, instr_ds) |
| 85 | + |
| 86 | + # Nan out unphysical values |
| 87 | + data_collections.nan_float_values_outside_threshold(threshold) |
| 88 | + |
| 89 | + # Display the contents of the collections for helping the user with making plots |
| 90 | + data_collections.display_collections() |
| 91 | + |
| 92 | + def generate_default_config(self, filenames, collection_name): |
| 93 | + |
| 94 | + """ |
| 95 | + Generate a default configuration for the dataset. |
| 96 | +
|
| 97 | + This method generates a default configuration for the dataset based on the provided |
| 98 | + filenames and collection name. It can be used as a starting point for creating a |
| 99 | + configuration for the dataset. |
| 100 | +
|
| 101 | + Args: |
| 102 | + filenames: Filenames or file paths relevant to the dataset. |
| 103 | + collection_name (str): Name of the collection for the dataset. |
| 104 | +
|
| 105 | + Returns: |
| 106 | + dict: A dictionary representing the default configuration for the dataset. |
| 107 | + """ |
| 108 | + |
| 109 | + pass |
0 commit comments