|
2 | 2 | from typing import ClassVar, Optional |
3 | 3 |
|
4 | 4 | import numpy as np |
5 | | -from attrs import Converter, setters |
| 5 | +from attrs import Converter |
6 | 6 | from numpy.typing import NDArray |
7 | 7 | from xattree import xattree |
8 | 8 |
|
|
14 | 14 |
|
15 | 15 | def _update_maxbound(instance, attribute, new_value): |
16 | 16 | """Update maxbound when period block arrays change.""" |
17 | | - if hasattr(instance, '_updating_maxbound'): |
| 17 | + if hasattr(instance, "_updating_maxbound"): |
18 | 18 | return new_value |
19 | | - |
| 19 | + |
20 | 20 | # Calculate maxbound from all relevant arrays |
21 | 21 | maxbound_values = [] |
22 | | - |
| 22 | + |
23 | 23 | # Check elev array |
24 | | - elev_val = new_value if attribute and attribute.name == 'elev' else getattr(instance, 'elev', None) |
| 24 | + elev_val = ( |
| 25 | + new_value if attribute and attribute.name == "elev" else getattr(instance, "elev", None) |
| 26 | + ) |
25 | 27 | if elev_val is not None: |
26 | 28 | elev = elev_val if elev_val.data.shape == elev_val.shape else elev_val.todense() |
27 | 29 | maxbound_values.append(len(np.where(elev != FILL_DNODATA)[0])) |
28 | | - |
| 30 | + |
29 | 31 | # Check cond array |
30 | | - cond_val = new_value if attribute and attribute.name == 'cond' else getattr(instance, 'cond', None) |
| 32 | + cond_val = ( |
| 33 | + new_value if attribute and attribute.name == "cond" else getattr(instance, "cond", None) |
| 34 | + ) |
31 | 35 | if cond_val is not None: |
32 | 36 | cond = cond_val if cond_val.data.shape == cond_val.shape else cond_val.todense() |
33 | 37 | maxbound_values.append(len(np.where(cond != FILL_DNODATA)[0])) |
34 | | - |
35 | | - # Check aux array |
36 | | - aux_val = new_value if attribute and attribute.name == 'aux' else getattr(instance, 'aux', None) |
| 38 | + |
| 39 | + # Check aux array |
| 40 | + aux_val = new_value if attribute and attribute.name == "aux" else getattr(instance, "aux", None) |
37 | 41 | if aux_val is not None: |
38 | 42 | aux = aux_val if aux_val.data.shape == aux_val.shape else aux_val.todense() |
39 | 43 | maxbound_values.append(len(np.where(aux != FILL_DNODATA)[0])) |
40 | | - |
| 44 | + |
41 | 45 | # Check boundname array |
42 | | - boundname_val = new_value if attribute and attribute.name == 'boundname' else getattr(instance, 'boundname', None) |
| 46 | + boundname_val = ( |
| 47 | + new_value |
| 48 | + if attribute and attribute.name == "boundname" |
| 49 | + else getattr(instance, "boundname", None) |
| 50 | + ) |
43 | 51 | if boundname_val is not None: |
44 | | - boundname = boundname_val if boundname_val.data.shape == boundname_val.shape else boundname_val.todense() |
| 52 | + boundname = ( |
| 53 | + boundname_val |
| 54 | + if boundname_val.data.shape == boundname_val.shape |
| 55 | + else boundname_val.todense() |
| 56 | + ) |
45 | 57 | maxbound_values.append(len(np.where(boundname != "")[0])) |
46 | | - |
| 58 | + |
47 | 59 | # Update maxbound if we have values |
48 | 60 | if maxbound_values: |
49 | 61 | instance._updating_maxbound = True |
50 | 62 | try: |
51 | 63 | instance.maxbound = max(maxbound_values) |
52 | 64 | finally: |
53 | | - delattr(instance, '_updating_maxbound') |
54 | | - |
| 65 | + delattr(instance, "_updating_maxbound") |
| 66 | + |
55 | 67 | return new_value |
56 | 68 |
|
57 | 69 |
|
@@ -111,5 +123,10 @@ class Drn(Package): |
111 | 123 |
|
112 | 124 | def __attrs_post_init__(self): |
113 | 125 | # Trigger maxbound calculation on initialization |
114 | | - if self.elev is not None or self.cond is not None or self.aux is not None or self.boundname is not None: |
| 126 | + if ( |
| 127 | + self.elev is not None |
| 128 | + or self.cond is not None |
| 129 | + or self.aux is not None |
| 130 | + or self.boundname is not None |
| 131 | + ): |
115 | 132 | _update_maxbound(self, None, None) |
0 commit comments