<commit_before>#!/usr/bin/env python
"""
  analysis.py

  Methods to assist in the analysis of ROMS fields

  Written by <NAME> on 05/24/15
  Copyright (c)2019 University of Hawaii under the MIT-License.
"""

import numpy as np
from joblib import Parallel, delayed
import seapy
import netCDF4


def __find_surface_thread(grid, field, value, zeta, const_depth=False,
                          k_values=False, u_grid=False, v_grid=False):
    """
    Internal function to find a value in field_a and return the
    values from field_b at the same positions.
    """
    depth = seapy.roms.depth(grid.vtransform, grid.h, grid.hc,
                             grid.s_rho, grid.cs_r, zeta)
    if u_grid:
        depth = seapy.model.rho2u(depth)
    elif v_grid:
        depth = seapy.model.rho2v(depth)

    # Set the variables based on what we are finding
    if const_depth:
        field_a, field_b = depth, field
    else:
        field_a, field_b = field, depth

    # Determine the upper and lower bounds of the value in the field
    tmp = np.ma.masked_equal(
        np.diff(((field_a - value) < 0).astype(np.short), axis=0), 0)
    factor = np.mean(tmp).astype(np.short)
    bad = np.sum(tmp, axis=0).astype(bool)
    k_ones = np.arange(grid.n, dtype=np.short)
    upper = (k_ones[:, np.newaxis, np.newaxis] ==
             np.argmax(np.abs(tmp), axis=0)) * bad
    k_ones = np.arange(grid.n, dtype=np.short) - factor
    lower = (k_ones[:, np.newaxis, np.newaxis] ==
             np.argmax(np.abs(tmp), axis=0)) * bad<commit_msg>Verify that the direction factor is valid for odd points.<commit_after>#!/usr/bin/env python
"""
  analysis.py

  Methods to assist in the analysis of ROMS fields

  Written by <NAME> on 05/24/15
  Copyright (c)2019 University of Hawaii under the MIT-License.
"""

import numpy as np
from joblib import Parallel, delayed
import seapy
import netCDF4


def __find_surface_thread(grid, field, value, zeta, const_depth=False,
                          k_values=False, u_grid=False, v_grid=False):
    """
    Internal function to find a value in field_a and return the
    values from field_b at the same positions.
    """
    depth = seapy.roms.depth(grid.vtransform, grid.h, grid.hc,
                             grid.s_rho, grid.cs_r, zeta)
    if u_grid:
        depth = seapy.model.rho2u(depth)
    elif v_grid:
        depth = seapy.model.rho2v(depth)

    # Set the variables based on what we are finding
    if const_depth:
        field_a, field_b = depth, field
    else:
        field_a, field_b = field, depth

    # Determine the upper and lower bounds of the value in the field
    tmp = np.ma.masked_equal(
        np.diff(((field_a - value) < 0).astype(np.short), axis=0), 0)
    factor = np.round(np.mean(tmp)).astype(np.short)

    # If something is amiss with the factor, just set it to the
    # gradient of the field
    if factor == 0:
        grad = np.mean(np.diff(field, axis=0))
        factor = -1 if grad < 0 else 1

    # Determine the points of the upper bound and the lower bound
    bad = np.sum(tmp, axis=0).astype(bool)
    k_ones = np.arange(grid.n, dtype=np.short)
    upper = (k_ones[:, np.newaxis, np.newaxis] ==
             np.argmax(np.abs(tmp), axis=0)) * bad
    k_ones = np.arange(grid.n, dtype=np.short) - factor
    lower = (k_ones[:, np.newaxis, np.newaxis] ==
             np.argmax(np.abs(tmp), axis=0)) * bad
{'fraction_non_alphanumeric': 0.11238938053097346, 'fraction_numerical': 0.012684365781710914, 'mean_word_length': 2.599787685774947, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '884023', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1141, 'n_words': 338}