<commit_before># coding=utf-8
# Copyright 2022 The Google Research Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Visualization and logging."""

import io
import json
import math
import os

from absl import logging
import jax.numpy as np
from matplotlib import cm
import matplotlib.pyplot as plt
import mediapy as media
import ml_collections
import numpy as onp
import tensorflow as tf
import tensorflow.io.gfile as gfile


def scale_depth(depth, min_depth=4 - onp.sqrt(3), max_depth=4 + onp.sqrt(3)):
  """Clips a depth image to a unit cube, scales to [0, 1] then color maps."""
  depth_scaled = onp.clip(depth, min_depth, max_depth)
  depth_scaled = depth_scaled - onp.min(depth_scaled)
  depth_scaled = depth_scaled / onp.max(depth_scaled)

  depth_colored = cm.get_cmap('turbo')(depth_scaled)
  alpha = depth_colored[Ellipsis, 3:]<commit_msg>Fallback to jet colormap for older versions of matplotlib<commit_after># coding=utf-8
# Copyright 2022 The Google Research Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Visualization and logging."""

import io
import json
import math
import os

from absl import logging
import jax.numpy as np
from matplotlib import cm
import matplotlib.pyplot as plt
import mediapy as media
import ml_collections
import numpy as onp
import tensorflow as tf
import tensorflow.io.gfile as gfile


def scale_depth(depth, min_depth=4 - onp.sqrt(3), max_depth=4 + onp.sqrt(3)):
  """Clips a depth image to a unit cube, scales to [0, 1] then color maps."""
  depth_scaled = onp.clip(depth, min_depth, max_depth)
  depth_scaled = depth_scaled - onp.min(depth_scaled)
  depth_scaled = depth_scaled / onp.max(depth_scaled)

  try:
    cmap = cm.get_cmap('turbo')
  except ValueError:
    # Fallback to jet cmap for older versions of matplotlib, <3.3
    cmap = cm.get_cmap('jet')
  depth_colored = cmap(depth_scaled)
  alpha = depth_colored[Ellipsis, 3:]
{'fraction_non_alphanumeric': 0.0803448275862069, 'fraction_numerical': 0.011724137931034483, 'mean_word_length': 4.525714285714286, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5604569', 'n_tokens_mistral': 900, 'n_tokens_neox': 881, 'n_words': 358}