( selector, dimensions, coordinates, shape, chunks, x, y )
| 457 | } |
| 458 | |
| 459 | export const getChunks = ( |
| 460 | selector, |
| 461 | dimensions, |
| 462 | coordinates, |
| 463 | shape, |
| 464 | chunks, |
| 465 | x, |
| 466 | y |
| 467 | ) => { |
| 468 | const chunkIndicesToUse = dimensions.map((dimension, i) => { |
| 469 | if (['x', 'lon'].includes(dimension)) { |
| 470 | return [x] |
| 471 | } else if (['y', 'lat'].includes(dimension)) { |
| 472 | return [y] |
| 473 | } |
| 474 | |
| 475 | const selectorValue = selector[dimension] |
| 476 | const coords = coordinates[dimension] |
| 477 | const chunkSize = chunks[i] |
| 478 | let indices |
| 479 | if (Array.isArray(selectorValue)) { |
| 480 | // Return all indices of selector value when array |
| 481 | indices = selectorValue.map((v) => coords.indexOf(v)) |
| 482 | } else if (selectorValue != undefined) { |
| 483 | // Return index of single selector value otherwise when present |
| 484 | indices = [coords.indexOf(selectorValue)] |
| 485 | } else { |
| 486 | // Otherwise, vary over the entire shape of the dimension |
| 487 | indices = Array(shape[i]) |
| 488 | .fill(null) |
| 489 | .map((_, j) => j) |
| 490 | } |
| 491 | |
| 492 | return ( |
| 493 | indices |
| 494 | .map((index) => Math.floor(index / chunkSize)) |
| 495 | // Filter out repeated instances of indices |
| 496 | .filter((v, i, a) => a.indexOf(v) === i) |
| 497 | ) |
| 498 | }) |
| 499 | |
| 500 | let result = [[]] |
| 501 | chunkIndicesToUse.forEach((indices) => { |
| 502 | const updatedResult = [] |
| 503 | indices.forEach((index) => { |
| 504 | result.forEach((prev) => { |
| 505 | updatedResult.push([...prev, index]) |
| 506 | }) |
| 507 | }) |
| 508 | result = updatedResult |
| 509 | }) |
| 510 | |
| 511 | return result |
| 512 | } |
| 513 | |
| 514 | export const getPositions = (size, mode) => { |
| 515 | let position = [] |
no outgoing calls
no test coverage detected