• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ghiggi / gpm_api / 8501183871

31 Mar 2024 10:04PM UTC coverage: 87.857% (+0.2%) from 87.669%
8501183871

Pull #53

github

ghiggi
Add flake8-commas rules
Pull Request #53: Refactor code style

693 of 786 new or added lines in 86 files covered. (88.17%)

4 existing lines in 4 files now uncovered.

9001 of 10245 relevant lines covered (87.86%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/gpm/dataset/decoding/utils.py
1
# -----------------------------------------------------------------------------.
2
# MIT License
3

4
# Copyright (c) 2024 GPM-API developers
5
#
6
# This file is part of GPM-API.
7

8
# Permission is hereby granted, free of charge, to any person obtaining a copy
9
# of this software and associated documentation files (the "Software"), to deal
10
# in the Software without restriction, including without limitation the rights
11
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
# copies of the Software, and to permit persons to whom the Software is
13
# furnished to do so, subject to the following conditions:
14
#
15
# The above copyright notice and this permission notice shall be included in all
16
# copies or substantial portions of the Software.
17
#
18
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
# SOFTWARE.
25

26
# -----------------------------------------------------------------------------.
27
"""This module contains utilities for the decoding of GPM product variables."""
1✔
28
import dask.array
1✔
29
import numpy as np
1✔
30

31

32
def is_dataarray_decoded(da):
1✔
33
    """Check if a DataArray has been decoded by GPM-API."""
34
    return da.attrs.get("gpm_api_decoded", "no") == "yes"
1✔
35

36

37
def add_decoded_flag(ds, variables):
1✔
38
    """Add gpm_api_decoded flag to GPM-API decoded variables."""
39
    for var in variables:
1✔
40
        if var in ds:
1✔
41
            ds[var].attrs["gpm_api_decoded"] = "yes"
1✔
42
    return ds
1✔
43

44

45
def remap_numeric_array(arr, remapping_dict):
1✔
46
    """Remap the values of a numeric array."""
47
    # TODO: this is erroneous
48
    # TODO: implement that works with dask array also !
49
    # TODO: implement it works if values not in remapping dict
50
    # TODO: implement it works if only np.nan values
51
    # remapping_dict = {-1111: 0, 0: 1, 10: 2, 11: 3, 20: 4, 21: 5}
52
    original_values = list(remapping_dict.keys())
×
53

54
    # Use np.searchsorted to remap the array
55
    # TODO: works only if not np.nan and reamp to 0-n ?
NEW
56
    return np.searchsorted(original_values, arr, sorter=np.argsort(original_values))
×
57

58
    # Correct Alternative (but less performant) :
59
    # np.vectorize(remapping_dict.__getitem__)(arr)
60

61

62
def ceil_datarray(da):
1✔
63
    """Ceil a xr.DataArray."""
64
    data = da.data
1✔
65
    data = np.ceil(data) if hasattr(data, "chunks") else dask.array.ceil(data)
1✔
66
    da.data = data
1✔
67
    return da
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc