data0.load_input ================ .. py:module:: data0.load_input Functions --------- .. autoapisummary:: data0.load_input.get_npy_from_netcdf data0.load_input.apply_config data0.load_input.apply_mask Module Contents --------------- .. py:function:: get_npy_from_netcdf(netcdf, year, input_config, x_or_y=None, var=None) Extract a numpy array for a specific year (and variable if requested) from a netcdf file. :param netcdf: Path to the netcdf file or an xarray Dataset. :type netcdf: `str` or `xr.Dataset` :param year: The year for which to extract the data. :type year: `int` :param input_config: Path to the input configuration JSON file or a dictionary containing the configuration. :type input_config: `str` or `dict` :param x_or_y: If 'x', return the stage 1 x variables, if 'x2', return the stage 2 x variables, if 'y', return the y variables. If None, return all variables. :type x_or_y: `str`, optional :param var: The variable to extract from the netcdf file. Overrides the `x_or_y` argument. If None, all variables are returned. :type var: `str`, optional :returns: * **data_array** (`numpy.ndarray`) -- The extracted data as a numpy array. * **lats** (`numpy.ndarray`) -- The latitude values of the arrays to restrict. * **lons** (`numpy.ndarray`) -- The longitude values of the arrays to restrict. .. rubric:: Examples >>> input_set = 'my_inputs' >>> arr, lats, lons = get_npy_from_netcdf(f'inputfiles/{input_set}/{input_set}.nc', 2019, 'x') >>> type(arr) >>> arr.shape (364, 56, 120, 9) .. py:function:: apply_config(input_netcdf, input_config) Apply the conditions in the config to the netcdf. Based on the parameters in the input configuration, modify the xarray in the input netcdf and return the resulting xarray dataset. :param input_netcdf: Path to the netcdf file or an xarray Dataset. :type input_netcdf: `str` or `xr.Dataset` :param input_config: Path to the input configuration JSON file or a dictionary containing the configuration. :type input_config: `str` or `dict` :returns: **prepped_dataset** -- The dataset from the input netcdf with the configuration rules applied. :rtype: `xr.Dataset` .. py:function:: apply_mask(xr_dataset, var, config_dict, year) Apply specified mask to the given variable. Determine the mask to apply based on the configuration dictionary and apply it to the specified variable in the xarray dataset. :param xr_dataset: The xarray dataset containing the variable to be masked. :type xr_dataset: `xr.Dataset` :param var: The variable to which the mask will be applied. :type var: `str` :param config_dict: Configuration dictionary specifying mask details. :type config_dict: `dict` :param year: The year for which the data is being processed. :type year: `int` :returns: The masked variable as an xarray DataArray. :rtype: xr.DataArray