Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhassell committed Oct 30, 2024
1 parent fb741f2 commit 2586c99
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 37 deletions.
113 changes: 77 additions & 36 deletions cf/mixin/fielddomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
bounds_combination_mode,
normalize_slice,
)
from ..query import Query
from ..query import Query, wi
from ..units import Units

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -447,43 +447,84 @@ def _indices(self, config, data_axes, ancillary_mask, kwargs):
anchor0 = value.value[1]
anchor1 = value.value[0]

a = self.anchor(axis, anchor0, dry_run=True)["roll"]
b = self.flip(axis).anchor(axis, anchor1, dry_run=True)[
"roll"
]

size = item.size
if abs(anchor1 - anchor0) >= item.period():
if value.operator == "wo":
set_start_stop = 0
else:
set_start_stop = -a

start = set_start_stop
stop = set_start_stop
elif a + b == size:
b = self.anchor(axis, anchor1, dry_run=True)["roll"]
if (b == a and value.operator == "wo") or not (
b == a or value.operator == "wo"
):
set_start_stop = -a
else:
set_start_stop = 0

start = set_start_stop
stop = set_start_stop
# if value.operator == "wi":
if item.increasing:
a= value.value[0]
else:
a = value.value[1]

offset = self.anchor(axis, a, dry_run=True)["roll"]
nperiod = self.anchor(axis, a, dry_run=True)["nperiod"]
item = item + nperiod
item = item.roll(0, offset)
n = np.roll(np.arange(item.size), offset, 0)
print(n, (item == value).array, item.array, value)

if value.operator == "wi":
n = n[item == value]
if not n.size:
raise ValueError(
f"No indices found from: {identity}={value!r}"
)

start = n[0]
stop = n[-1] + 1
else:
if value.operator == "wo":
start = b - size
stop = -a + size
n = n[item == wi(*value.value)]
if n.size == item.size:
raise ValueError(
f"No indices found from: {identity}={value!r}"
)

start = n[-1] + 1
stop = start - n.size
print(n)
print ('start, stop=',start, stop)

if False: #else:
a = self.anchor(axis, anchor0, dry_run=True)["roll"]
b = self.flip(axis).anchor(axis, anchor1, dry_run=True)[
"roll"
]
print('a, b=', a, b)
size = item.size
if abs(anchor1 - anchor0) >= item.period():
if value.operator == "wo":
start = 0
stop = 0
else:
start = -a
stop = -a + size
elif a + b == size:
b = self.anchor(axis, anchor1, dry_run=True)["roll"]
if value.operator == "wi":
start = -a
stop = -a + size
elif (b == a and value.operator == "wo") or not (
b == a or value.operator == "wo"
):
start = -a
stop = -a
else:
start = 0
stop = 0

# start = set_start_stop
# stop = set_start_stop
else:
start = -a
stop = b - size

if start == stop == 0:
raise ValueError(
f"No indices found from: {identity}={value!r}"
)
if value.operator == "wo":
print('HERE0.9')
start = b - size
stop = -a + size
else:
print('HERE1')
start = -a
stop = b - size

#if start == stop == 0:
# raise ValueError(
# f"No indices found from: {identity}={value!r}"
# )

index = slice(start, stop, 1)

Expand Down
4 changes: 3 additions & 1 deletion cf/test/test_Field.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ def test_Field_insert_dimension(self):
with self.assertRaises(ValueError):
f.insert_dimension(1, "qwerty")

def test_Field_indices(self):
def test_Field__aaa__indices(self):
f = cf.read(self.filename)[0]

array = np.ma.array(f.array, copy=False)
Expand Down Expand Up @@ -1214,6 +1214,8 @@ def test_Field_indices(self):
(x == [-80, -40, 0, 40, 80, 120, 160, 200, 240.0]).all()
)

print(f)
print(f.dimension_coordinate('X').array, f.cyclic())
with self.assertRaises(ValueError):
# No X coordinate values lie inside the range [90, 100]
f.indices(grid_longitude=cf.wi(90, 100))
Expand Down

0 comments on commit 2586c99

Please sign in to comment.