<commit_before># -*- coding: utf-8 -*-
import os
import time

import cf_units
import iris

iris.FUTURE.netcdf_no_unlimited = True

def nearest_tval(cube, dt):
    timevar = cube.coord('time')
    itime = timevar.nearest_neighbour_index(timevar.units.date2num(dt))
    return timevar.units.num2date(timevar.points[itime])

class grdstep(object):
    def __init__(self, key):
        self.key = key

    def to_str(self, mask='{0}.{1}km'):
        """km2p2 -> 2.2km"""
        return mask.format(self.key[2], self.key[4])

    def to_flt(self, unit='m'):
        """km2p2 -> 2200"""
        un = cf_units.Unit(self.to_str())
        return un.convert(1, cf_units.Unit(unit))<commit_msg>add nearest_plevel() and unrotate_xy_grids() to utils<commit_after># -*- coding: utf-8 -*-
import os
import time

import cf_units
import iris

iris.FUTURE.netcdf_no_unlimited = True

def unrotate_xy_grids(cube):
    """
    Convert rotated-pole lons and lats to unrotated ones using X and Y coordinate for a given cube.
    Unites get_xy_grids() and unrotate_pole() functions.

    Args:

        * cube - The cube with rotated coordinate system for which to generate 2D X and Y unrotated coordinates.

    Example::

        lon, lat = unrotate_xy_grids(cube)

    """
    x, y = iris.analysis.cartography.get_xy_grids(cube)

    cs = cube.coord_system('CoordSystem')
    if isinstance(cs, iris.coord_systems.RotatedGeogCS):
        nplon = cube.coord_system().grid_north_pole_longitude
        nplat = cube.coord_system().grid_north_pole_latitude
        x, y = iris.analysis.cartography.unrotate_pole(x, y, nplon, nplat)
    else:
        # no rotation needed
        pass

    return (x, y)


def nearest_plevel(cube, pval):
    pcoord = cube.coord('pressure')
    i = pcoord.nearest_neighbour_index(pval)
    return pcoord.points[i]


def nearest_tval(cube, dt):
    timevar = cube.coord('time')
    itime = timevar.nearest_neighbour_index(timevar.units.date2num(dt))
    return timevar.units.num2date(timevar.points[itime])

class grdstep(object):
    def __init__(self, key):
        self.key = key

    def to_str(self, mask='{0}.{1}km'):
        """km2p2 -> 2.2km"""
        return mask.format(self.key[2], self.key[4])

    def to_flt(self, unit='m'):
        """km2p2 -> 2200"""
        un = cf_units.Unit(self.to_str())
        return un.convert(1, cf_units.Unit(unit))
{'fraction_non_alphanumeric': 0.1306553911205074, 'fraction_numerical': 0.015644820295983086, 'mean_word_length': 3.209964412811388, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4393151', 'n_tokens_mistral': 891, 'n_tokens_neox': 847, 'n_words': 179}