MCPcopy Create free account
hub / github.com/NCAR/wrf-python / _find_reverse

Function _find_reverse

src/wrf/util.py:1460–1527  ·  view source on GitHub ↗

Find and return the array object within a sequence for a specific time index. The sequence is searched in reverse. Args: wrfseq (iterable): An iterable type, which includes lists, tuples, dictionaries, generators, and user-defined classes. varname (:obj:`s

(wrfseq, varname, timeidx, is_moving, meta, _key)

Source from the content-addressed store, hash-verified

1458
1459
1460def _find_reverse(wrfseq, varname, timeidx, is_moving, meta, _key):
1461 """Find and return the array object within a sequence for a specific time
1462 index.
1463
1464 The sequence is searched in reverse.
1465
1466 Args:
1467
1468 wrfseq (iterable): An iterable type, which includes lists, tuples,
1469 dictionaries, generators, and user-defined classes.
1470
1471 varname (:obj:`str`) : The variable name.
1472
1473 timeidx (:obj:`int`): The desired time index. Must be negative.
1474
1475 is_moving (:obj:`bool`): A boolean type that indicates if the
1476 sequence is a moving nest.
1477
1478 meta (:obj:`bool`, optional): Set to False to disable metadata and
1479 return :class:`numpy.ndarray` instead of
1480 :class:`xarray.DataArray`. Default is True.
1481
1482 _key (:obj:`int`, optional): Cache key for the coordinate variables.
1483 This is used for internal purposes only. Default is None.
1484
1485 Returns:
1486
1487 :class:`xarray.DataArray` or :class:`numpy.ndarray`: If xarray is
1488 enabled and the *meta* parameter is True, then the result will be a
1489 :class:`xarray.DataArray` object. Otherwise, the result will be a
1490 :class:`numpy.ndarray` object with no metadata.
1491
1492 """
1493
1494 try:
1495 revwrfseq = reversed(wrfseq)
1496 except TypeError:
1497 revwrfseq = reversed(list(wrfseq))
1498
1499 wrf_iter = iter(revwrfseq)
1500 revtimeidx = -timeidx - 1
1501
1502 comboidx = 0
1503
1504 while True:
1505 try:
1506 wrfnc = next(wrf_iter)
1507 except StopIteration:
1508 break
1509 else:
1510 numtimes = extract_dim(wrfnc, "Time")
1511
1512 if revtimeidx < comboidx + numtimes:
1513 # Finds the "forward" sequence index, then counts that
1514 # number back from the back of the ncfile times,
1515 # since the ncfile needs to be iterated backwards as well.
1516 filetimeidx = numtimes - (revtimeidx - comboidx) - 1
1517

Callers 1

_find_arr_for_timeFunction · 0.85

Calls 2

extract_dimFunction · 0.85
_build_data_arrayFunction · 0.85

Tested by

no test coverage detected