Find and return the array object within a sequence for a specific time index. Args: wrfseq (iterable): An iterable type, which includes lists, tuples, dictionaries, generators, and user-defined classes. varname (:obj:`str`) : The variable name. timeidx
(wrfseq, varname, timeidx, is_moving, meta, _key)
| 1394 | |
| 1395 | |
| 1396 | def _find_forward(wrfseq, varname, timeidx, is_moving, meta, _key): |
| 1397 | """Find and return the array object within a sequence for a specific time |
| 1398 | index. |
| 1399 | |
| 1400 | Args: |
| 1401 | |
| 1402 | wrfseq (iterable): An iterable type, which includes lists, tuples, |
| 1403 | dictionaries, generators, and user-defined classes. |
| 1404 | |
| 1405 | varname (:obj:`str`) : The variable name. |
| 1406 | |
| 1407 | timeidx (:obj:`int`): The desired time index. Must be positive. |
| 1408 | |
| 1409 | is_moving (:obj:`bool`): A boolean type that indicates if the |
| 1410 | sequence is a moving nest. |
| 1411 | |
| 1412 | meta (:obj:`bool`, optional): Set to False to disable metadata and |
| 1413 | return :class:`numpy.ndarray` instead of |
| 1414 | :class:`xarray.DataArray`. Default is True. |
| 1415 | |
| 1416 | _key (:obj:`int`, optional): Cache key for the coordinate variables. |
| 1417 | This is used for internal purposes only. Default is None. |
| 1418 | |
| 1419 | Returns: |
| 1420 | |
| 1421 | :class:`xarray.DataArray` or :class:`numpy.ndarray`: If xarray is |
| 1422 | enabled and the *meta* parameter is True, then the result will be a |
| 1423 | :class:`xarray.DataArray` object. Otherwise, the result will be a |
| 1424 | :class:`numpy.ndarray` object with no metadata. |
| 1425 | |
| 1426 | """ |
| 1427 | |
| 1428 | wrf_iter = iter(wrfseq) |
| 1429 | comboidx = 0 |
| 1430 | |
| 1431 | while True: |
| 1432 | try: |
| 1433 | wrfnc = next(wrf_iter) |
| 1434 | except StopIteration: |
| 1435 | break |
| 1436 | else: |
| 1437 | numtimes = extract_dim(wrfnc, "Time") |
| 1438 | |
| 1439 | if timeidx < comboidx + numtimes: |
| 1440 | filetimeidx = timeidx - comboidx |
| 1441 | |
| 1442 | if meta: |
| 1443 | return _build_data_array(wrfnc, varname, filetimeidx, |
| 1444 | is_moving, True, _key) |
| 1445 | else: |
| 1446 | var = wrfnc.variables[varname] |
| 1447 | if len(var.shape) > 1: |
| 1448 | result = var[filetimeidx, :] |
| 1449 | return result[np.newaxis, :] # So that nosqueeze works |
| 1450 | else: |
| 1451 | result = var[filetimeidx] |
| 1452 | return result[np.newaxis] # So that nosqueeze works |
| 1453 |
no test coverage detected