bw_processing.merging ===================== .. py:module:: bw_processing.merging Functions --------- .. autoapisummary:: bw_processing.merging.add_resource_suffix bw_processing.merging.mask_resource bw_processing.merging.merge_datapackages_with_mask bw_processing.merging.update_nrows bw_processing.merging.write_data_to_fs Module Contents --------------- .. py:function:: add_resource_suffix(metadata: dict, suffix: str) -> dict Update the ``name``, ``path``, and ``group`` values to include ``suffix``. The suffix comes after the basename but after the data type suffix (e.g. indices, data). Given the suffix ``_foo`` and the metadata:: { "name": "sa-data-vector-from-dict.indices", "path": "sa-data-vector-from-dict.indices.npy", "group": "sa-data-vector-from-dict", } It will return:: { "name": "sa-data-vector-from-dict_foo.indices", "path": "sa-data-vector-from-dict_foo.indices.npy", "group": "sa-data-vector-from-dict_foo", } .. py:function:: mask_resource(obj: Any, mask: numpy.ndarray) -> Any .. py:function:: merge_datapackages_with_mask(first_dp: bw_processing.datapackage.DatapackageBase, first_resource_group_label: str, second_dp: bw_processing.datapackage.DatapackageBase, second_resource_group_label: str, mask_array: numpy.ndarray, output_fs: Optional[fsspec.AbstractFileSystem] = None, metadata: Optional[dict] = None) -> bw_processing.datapackage.DatapackageBase Merge two resources using a Numpy boolean mask. Returns elements from ``first_dp`` where the mask is ``True``, otherwise ``second_dp``. Both resource arrays, and the filter mask, must have the same length. Both datapackages must be static, i.e. not interfaces. This is because we don't yet have the functionality to select only some of the values in a resource group in ``matrix_utils``. This function currently **will not** mask or filter JSON or CSV metadata. :param \* first_dp: The datapackage from whom values will be taken when ``mask_array`` is ``True``. :param \* first_resource_group_label: Label of the resource group in ``first_dp`` to select values from. :param \* second_dp: The datapackage from whom values will be taken when ``mask_array`` is ``False``. :param \* second_resource_group_label: Label of the resource group in ``second_dp`` to select values from. :param \* mask_array: Boolean numpy array :param \* output_fs: Filesystem to write new datapackage to, if any. :param \* metadata: Metadata for new datapackage, if any. :returns: A `Datapackage` instance. Will write the resulting datapackage to ``output_fs`` if provided. .. py:function:: update_nrows(resource: dict, data: Any) -> dict .. py:function:: write_data_to_fs(resource: dict, data: Any, fs: fsspec.AbstractFileSystem) -> None