text:
# coding=utf-8
# Copyright 2020 The TensorFlow Datasets 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.

# Lint as: python3
"""CIFAR datasets."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import collections
import os

import numpy as np
import tensorflow.compat.v2 as tf
import tensorflow_datasets.public_api as tfds

# Shared constants
_CIFAR_IMAGE_SIZE = 32
_CIFAR_IMAGE_SHAPE = (_CIFAR_IMAGE_SIZE, _CIFAR_IMAGE_SIZE, 3)

_CITATION = """\
@TECHREPORT{Krizhevsky09learningmultiple,
    author = {Alex Krizhevsky},
    title = {Learning multiple layers of features from tiny images},
    institution = {},
    year = {2009}
}
"""

class Cifar10(tfds.core.GeneratorBasedBuilder):
  """CIFAR-10."""

  VERSION = tfds.core.Version("3.0.1")
  SUPPORTED_VERSIONS = [
      tfds.core.Version(
          "3.0.2", experiments={tfds.core.Experiment.METADATA: True}
      ),
  ]

  def _info(self):
    return tfds.core.DatasetInfo(
        builder=self,
        description=("The CIFAR-10 dataset consists of 60000 32x32 colour "
                     "images in 10 classes, with 6000 images per class. There "
                     "are 50000 training images and 10000 test images."),
        features=tfds.features.FeaturesDict({
            "id": tfds.features.Text(),
            "image": tfds.features.Image(shape=_CIFAR_IMAGE_SHAPE),
            "label": tfds.features.ClassLabel(num_classes=10),
        }),
        supervised_keys=("image", "label"),
        homepage="https://www.cs.toronto.edu/~kriz/cifar.html",
        citation=_CITATION,
    )

  @property
  def _cifar_info(self):
    return CifarInfo(
        name=self.name,
        url="https://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz",
        train_files=[
            "data_batch_1.bin", "data_batch_2.bin", "data_batch_3.bin",
            "data_batch_4.bin", "data_batch_5.bin"
        ],
        test_files=["test_batch.bin"],
        prefix="cifar-10-batches-bin/",
        label_files=["batches.meta.txt"],
        label_keys=["label"],
    )

  def _split_generators(self, dl_manager):
    """Returns SplitGenerators."""
    cifar_path = dl_manager.download_and_extract(self._cifar_info.url)
    cifar_info = self._cifar_info

    cifar_path = os.path.join(cifar_path, cifar_info.prefix)

    # Load the label names
    for label_key, label_file in zip(cifar_info.label_keys,
                                     cifar_info.label_files):
      labels_path = os.path.join(cifar_path, label_file)
      with tf.io.gfile.GFile(labels_path) as label_f:
        label_names = [name for name in label_f.read().split("\n") if name]
      self.info.features[label_key].names = label_names

    # Define the splits
    def gen_filenames(filenames):
      for f in filenames:
        yield os.path.join(cifar_path, f)

    return [
        tfds.core.SplitGenerator(
            name=tfds.Split.TRAIN,
            gen_kwargs={
                "split_prefix": "train_",
                "filepaths": gen_filenames(cifar_info.train_files)
            }),
        tfds.core.SplitGenerator(
            name=tfds.Split.TEST,
            gen_kwargs={
                "split_prefix": "test_",
                "filepaths": gen_filenames(cifar_info.test_files)
            }),
    ]

  def _generate_examples(self, split_prefix, filepaths):
    """Generate CIFAR examples as dicts.

    Shared across CIFAR-{10, 100}. Uses self._cifar_info as
    configuration.

    Args:
      split_prefix (str): Prefix that identifies the split (e.g. "tr" or "te").
      filepaths (list[str]): The files to use to generate the data.

    Yields:
      The cifar examples, as defined in the dataset info features.
    """
    label_keys = self._cifar_info.label_keys
    index = 0  # Using index as key since data is always loaded in same order.
    for path in filepaths:
      for labels, np_image in _load_data(path, len(label_keys)):
        record = dict(zip(label_keys, labels))
        # Note: "id" is only provided for the user convenience. To shuffle the
        # dataset we use `index`, so that the sharding is compatible with
        # earlier versions.
        record["id"] = "{}{:05d}".format(split_prefix, index)
        record["image"] = np_image
        yield index, record
        index += 1

class Cifar100(Cifar10):
  """CIFAR-100 dataset."""

  VERSION = tfds.core.Version("3.0.1")
  SUPPORTED_VERSIONS = [
      tfds.core.Version(
          "3.0.2", experiments={tfds.core.Experiment.METADATA: True}
      ),
  ]

  @property
  def _cifar_info(self):
    return CifarInfo(
        name=self.name,
        url="https://www.cs.toronto.edu/~kriz/cifar-100-binary.tar.gz",
        train_files=["train.bin"],
        test_files=["test.bin"],
        prefix="cifar-100-binary/",
        label_files=["coarse_label_names.txt", "fine_label_names.txt"],
        label_keys=["coarse_label", "label"],
    )

  def _info(self):
    return tfds.core.DatasetInfo(
        builder=self,
        description=("This dataset is just like the CIFAR-10, except it has "
                     "100 classes containing 600 images each. There are 500 "
                     "training images and 100 testing images per class. The "
                     "100 classes in the CIFAR-100 are grouped into 20 "
                     "superclasses. Each image comes with a \"fine\" label "
                     "(the class to which it belongs) and a \"coarse\" label "
                     "(the superclass to which it belongs)."),
        features=tfds.features.FeaturesDict({
            "id": tfds.features.Text(),
            "image": tfds.features.Image(shape=_CIFAR_IMAGE_SHAPE),
            "label": tfds.features.ClassLabel(num_classes=100),
            "coarse_label": tfds.features.ClassLabel(num_classes=20),
        }),
        supervised_keys=("image", "label"),
        homepage="https://www.cs.toronto.edu/~kriz/cifar.html",
        citation=_CITATION,
    )

class CifarInfo(collections.namedtuple("_CifarInfo", [
    "name",
    "url",
    "prefix",
    "train_files",
    "test_files",
    "label_files",
    "label_keys",
])):
  """Contains the information necessary to generate a CIFAR dataset.

  Attributes:
    name (str): name of dataset.
    url (str): data URL.
    prefix (str): path prefix within the downloaded and extracted file to look
      for `train_files` and `test_files`.
    train_files (list<str>): name of training files within `prefix`.
    test_files (list<str>): name of test files within `prefix`.
    label_files (list<str>): names of the label files in the data.
    label_keys (list<str>): names of the label keys in the data.
  """

def _load_data(path, labels_number=1):
  """Yields (labels, np_image) tuples."""
  with tf.io.gfile.GFile(path, "rb") as f:
    data = f.read()
  offset = 0
  max_offset = len(data) - 1
  while offset < max_offset:
    labels = np.frombuffer(data, dtype=np.uint8, count=labels_number,
                           offset=offset).reshape((labels_number,))
    # 1 byte per label, 1024 * 3 = 3072 bytes for the image.
    offset += labels_number
    img = (np.frombuffer(data, dtype=np.uint8, count=3072, offset=offset)
           .reshape((3, _CIFAR_IMAGE_SIZE, _CIFAR_IMAGE_SIZE))
           .transpose((1, 2, 0))
          )
    offset += 3072
    yield labels, img

max_stars_repo_name: thomwolf/datasets

max_issues_repo_name: thomwolf/datasets

max_forks_repo_name: thomwolf/datasets


text:
#
# This file is a part of Siesta Help Scripts
#
# (c) Andrey Sobolev, 2013
#

import numpy as np
from abstract import PerAtomData

class VPVolumeData(PerAtomData):
    _shortDoc = "Total VP volume"

    def getData(self, calc):
        self.nsteps = len(calc)
        # default plot options
        self.plot_options['dx'] = 0.1

        self.x_title = "Volume"
        self.data = []
        for _, g in calc.evol:
            self.data.append(self._get_vp_totvolume(g))
        self.calculate()

    def _get_vp_totvolume(self, geom, n=None):
        """ Finds total volumes for resulting Voronoi polihedra

                :param geom: a Geom instance
                :param n: a tuple of arrays containing atomic numbers of corresponding type

        :return:
        """
        if geom.vp is None:
            geom.voronoi(self.pbc, self.ratio)
        if hasattr(geom.vp, 'vp_volume'):
            return geom.vp.vp_volume
        f = geom.vp.vp_faces()
        v, _ = geom.vp.vp_volumes(f)
        if n is not None:
            v = [v[i] for i in n]
        return v

class VPTotalFaceAreaData(PerAtomData):
    _shortDoc = "VP total face area"

    def getData(self, calc):
        self.nsteps = len(calc)
        # default plot options
        self.plot_options['dx'] = 0.2

        self.x_title = "Face area"
        self.data = []
        for _, g in calc.evol:
            self.data.append(self._get_vp_totfacearea(g))
        self.calculate()

    def _get_vp_totfacearea(self, geom, n=None):
        """
        Finds total face areas for resulting Voronoi polihedra
        :param geom: a Geom instance
        :param n: a tuple of arrays containing atomic numbers of corresponding type
        :return:
        """

        if geom.vp is None:
            geom.voronoi(self.pbc, self.ratio)
        if hasattr(geom.vp, 'vp_area'):
            return geom.vp.vp_area
        f = geom.vp.vp_faces()
        _, a = geom.vp.vp_volumes(f)
        return a

class VPSphericityCoefficient(PerAtomData):
    _shortDoc = "VP sphericity coefficient"

    def getData(self, calc):
        self.nsteps = len(calc)
        # default plot options
        self.plot_options['dx'] = 0.01

        self.x_title = "Ksph"
        self.data = []
        for _, g in calc.evol:
            self.data.append(self._get_vp_ksph(g))
        self.calculate()

    def _get_vp_ksph(self, geom):
        """ Finds total volumes for resulting Voronoi polyhedra
        """
        if geom.vp is None:
            geom.voronoi(self.pbc, self.ratio)
        if not hasattr(geom.vp, 'vp_volume'):
            f = geom.vp.vp_faces()
            v, a = geom.vp.vp_volumes(f, partial=False)
        else:
            v = geom.vp.vp_volume
            a = geom.vp.vp_area
        ksph = 36. * np.pi * v * v / (a * a * a)
        return ksph

class VPFaceAreaData(PerAtomData):
    _shortDoc = "VP face area"

    def getData(self, calc):
        self.nsteps = len(calc)
        # default plot options
        self.plot_options['dx'] = 0.04

        self.x_title = "Face area"
        self.data = []
        for _, g in calc.evol:
            self.data.append(np.ma.getdata(self._get_vp_facearea(g)))
        self.calculate()

    def calculate(self):
        if self.partial:
            _, types = self.calc.evol.getAtomsByType()
            types_list = sorted(types.keys())
            # single
            for ti in types_list:
                self.y_titles.append(ti)
                self.y.append(self.calculatePartial(types[ti]))
            # pairwise
            for i, ti in enumerate(types_list):
                for tj in types_list[i:]:
                    self.y_titles.append(ti + "-" + tj)
                    self.y.append(self.calculatePartial(types[ti], types[tj]))
        else:
            self.y_titles = ["Total"]
            raise NotImplementedError
# FIXME:            self.y = self.data

    def calculatePartial(self, ti, tj = None):
        if tj is None:
            return [self.data[i][t_i].flatten() for (i,t_i) in enumerate(ti)]
        else:
            return  [self.data[i][t_i][:,t_j].flatten() for i,(t_i,t_j) in enumerate(zip(ti,tj))]

    def _get_vp_facearea(self, geom):
        """ Finds face areas of Voronoi tesselation
        """
        if geom.vp is None:
            geom.voronoi(self.pbc, self.ratio)
        f = geom.vp.vp_faces()
        # TODO: Remove small VP faces (may be check pyvoro?)
        # if rm_small:
        #     fa = self.vp.vp_face_area(f)
        #     f = self.vp.remove_small_faces(f, fa, eps)
        fa = geom.vp.vp_face_area(f)
        # here fa is the list of dictionaries, we make it a 2d numpy array
        # with masked values
        # WARNING: O(nat^2 * nsteps) memory consumption!
        nat = len(fa)
        fa_np = np.zeros((nat, nat), dtype=np.float)
        for iat, ngbr in enumerate(fa):
            for jat, area in ngbr.iteritems():
                fa_np[iat, jat] = area
        fa_np = np.ma.masked_values(fa_np, 0.)
        return fa_np

class MagneticMoment(PerAtomData):
    _shortDoc = "Magnetic moment"

    def getData(self, calc):
        self.nsteps = len(calc)
        self.plot_options['dx'] = 0.1

        self.x_title = "Magnetic moment"
        self.data = []
        for _, g in calc.evol:
            self.data.append(self._get_magmom(g))
        self.calculate()

    def _get_magmom(self, geom):
        return geom.atoms['up'] - geom.atoms['dn']

class AbsMagneticMoment(PerAtomData):
    _shortDoc = "Absolute magnetic moment"

    def getData(self, calc):
        self.nsteps = len(calc)
        self.plot_options['dx'] = 0.1

        self.x_title = "Absolute magnetic moment"
        self.data = []
        for _, g in calc.evol:
            self.data.append(self._get_magmom(g))
        self.calculate()

    def _get_magmom(self, geom):
        return np.abs(geom.atoms['up'] - geom.atoms['dn'])

class SpinFlipsData(PerAtomData):
    _isHistogram = False
    _shortDoc = 'Number of spin flips'

    def getData(self, calc):
        self.x_title = "Spin flips"
        self.data = []
        for _, g in calc.evol:
            self.data.append(g.magmom())
        self.calculate()

    def calculateTotal(self):
        prev = self.data[0]
        result = [np.zeros(len(prev))]
        for cur in self.data[1:]:
            result.append((prev * cur) < 0)
            prev = cur
#        print len(result), len(result[0])
        return result

    def calculatePartial(self, t):
        data = self.calculateTotal()
        result = [d[ti] for d, ti in zip(data,t)]
        return result

    def plotData(self, plot_type):
        from plotdata import CumSumData
        return CumSumData(self)

class TopologicalIndices(PerAtomData):
    _isTimeEvol = False
    _shortDoc = 'Topological indices'

    def getData(self, calc):
        self.plot_options['threshold'] = 0.5
        self.x_title = 'VP TIs'
        self.data = []
        for _, g in calc.evol:
            self.data.append(self._get_vp_ti(g))
        self.calculate()

    def calculateTotal(self):
        return self.data

    def calculatePartial(self, t):
        result = []
        for d, ti in zip(self.data, t):
            result += [d[tij] for tij in ti]
        return result

    def plotData(self, plot_type):
        from plotdata import VarXData
        return VarXData(self, **self.plot_options)

    def _get_vp_ti(self, geom):
        """ Finds topological indices of Voronoi polihedra
        """

        if geom.vp is None:
            geom.voronoi(self.pbc, self.ratio)
        f = geom.vp.vp_faces()
        # TODO: remove small faces!
        # if rm_small:
        #     fa = self.vp.vp_face_area(f)
        #     f = self.vp.remove_small_faces(f, fa, eps)
        ti = self.vp.vp_topological_indices()
        return ti

ext: py

max_stars_repo_name: ansobolev/shs

max_issues_repo_name: ansobolev/shs

max_forks_repo_name: ansobolev/shs

reason: import numpy


text:
import numpy as np
from deep500.lv0.operators.operator_interface import CustomPythonOp
from deep500.frameworks.reference.custom_operators.python.pool_op_common import get_pad_shape, get_output_shape, pool

class MaxPoolOp(CustomPythonOp):
    def __init__(self, input_descriptors, output_descriptors, auto_pad='NOTSET', kernel_shape=None, pads=None, storage_order=0, strides=None):
        super(MaxPoolOp, self).__init__(input_descriptors, output_descriptors)
        self._input_desc = input_descriptors
        self._output_desc = output_descriptors

        self.auto_pad = auto_pad
        self.kernel_shape = kernel_shape

        temp_pads = []
        temp_strides = []
        for i in range(0, len(kernel_shape)):
            temp_pads.append(0)
            temp_pads.append(0)

            temp_strides.append(1)

        self.pads = temp_pads if pads is None else pads
        self.strides = temp_strides if strides is None else strides
        self.storage_order = storage_order

    def forward(self, X):
        if self.auto_pad != 'NOTSET':
            out_shape = get_output_shape(
                self.auto_pad,
                X.shape[2:],
                self.kernel_shape,
                self.strides
            )
        else:
            input_spatial_shape = X.shape[2:]
            out_shape = [0] * len(input_spatial_shape)
            for i in range(len(input_spatial_shape)):
                out_shape[i] = int(np.ceil(float(
                    input_spatial_shape[i] - \
                    (self.kernel_shape[i] - 1) + \
                    + self.pads[i] + \
                    self.pads[i + len(self.kernel_shape)]
                    ) / float(self.strides[i]))
                    )

        pad_shape = get_pad_shape(
            self.auto_pad,
            X.shape[2:],
            self.kernel_shape,
            self.strides,
            out_shape
        )

        pads_computed_before = [] #top, left, ...
        pads_computed_after = [] #bottom, right, ...
        if self.auto_pad == 'SAME_UPPER':
            for i in range(0, len(X.shape) - 2 ):
                pads_computed_before.append(pad_shape[i] // 2)
                pads_computed_after.append(pad_shape[i] - (pad_shape[i] // 2))
        elif self.auto_pad == 'SAME_LOWER':
            for i in range(0, len(X.shape) - 2 ):
                pads_computed_before.append(pad_shape[i] - (pad_shape[i] // 2))
                pads_computed_after.append(pad_shape[i] // 2)
        elif self.auto_pad == 'VALID':
            for i in range(0, len(X.shape) - 2 ):
                pads_computed_before.append(0)
                pads_computed_after.append(0)
        elif self.auto_pad == 'NOTSET':
            for i in range(0, len(X.shape) - 2 ):
                pads_computed_before.append(self.pads[i * 2])
                pads_computed_after.append(self.pads[i * 2 + 1])
                pad_shape[i] = self.pads[i] + self.pads[i + len(self.kernel_shape)]

        pad_width = [(0, 0), (0, 0)]
        for i in range(0, len(X.shape) - 2 ):
            pad_width.append((pads_computed_before[i], pads_computed_after[i]))

        input_padded = np.pad(
            X,
            pad_width,
            mode='constant',
            constant_values=np.nan
        )

        y = pool(
            input_padded,
            X.shape,
            self.kernel_shape,
            self.strides,
            out_shape,
            pad_shape,
            'MAX')

        return y

    def backward(self, grads, fwd_inputs, fwd_outputs):
        X = np.copy(fwd_inputs[0])
        Y = np.copy(fwd_outputs[0])
        grad_X = np.zeros(X.shape, dtype=X.dtype)
        grad_Y = np.copy(grads[0])

        out_shape = Y.shape[2:]

        pad_shape = get_pad_shape(
            self.auto_pad,
            fwd_inputs[0].shape[2:],
            self.kernel_shape,
            self.strides,
            out_shape
        )

        pads_computed_before = [] #top, left, ...
        pads_computed_after = [] #bottom, right, ...
        if self.auto_pad == 'SAME_UPPER':
            for i in range(0, len(fwd_inputs[0].shape) - 2 ):
                pads_computed_before.append(pad_shape[i] // 2)
                pads_computed_after.append(pad_shape[i] - (pad_shape[i] // 2))
        elif self.auto_pad == 'SAME_LOWER':
            for i in range(0, len(fwd_inputs[0].shape) - 2 ):
                pads_computed_before.append(pad_shape[i] - (pad_shape[i] // 2))
                pads_computed_after.append(pad_shape[i] // 2)
        elif self.auto_pad == 'VALID':
            for i in range(0, len(fwd_inputs[0].shape) - 2 ):
                pads_computed_before.append(0)
                pads_computed_after.append(0)
        elif self.auto_pad == 'NOTSET':
            for i in range(0, len(fwd_inputs[0].shape) - 2 ):
                pads_computed_before.append(self.pads[i])
                pads_computed_after.append(self.pads[i + len(self.kernel_shape)])
                pad_shape[i] = self.pads[i] + self.pads[i + len(self.kernel_shape)]

        #avoid out of bounds access, fill with default values
        original_input_shape = np.copy(X.shape)
        temp_input_shape = np.copy(X.shape)
        temp_weight_shape = [1, 1] + self.kernel_shape
        temp_output_shape = np.copy(Y.shape)
        temp_pads_computed_before = np.copy(pads_computed_before)
        temp_strides = np.copy(self.strides)
        for i in range(5 - len(fwd_inputs[0].shape)):
            temp_input_shape = np.append(temp_input_shape, [1])
            temp_weight_shape = np.append(temp_weight_shape, [1])
            temp_output_shape = np.append(temp_output_shape, [1])
            temp_pads_computed_before = np.append(temp_pads_computed_before, [0])
            temp_strides = np.append(temp_strides, [1])

        X = np.reshape(X, temp_input_shape)
        Y = np.reshape(Y, temp_output_shape)
        grad_X = np.reshape(grad_X, temp_input_shape)
        grad_Y = np.reshape(grad_Y, temp_output_shape)

        #loop over output tensor
        for i in range(temp_output_shape[0]):
            for j in range(temp_output_shape[1]):
                for k in range(temp_output_shape[2]):
                    for l in range(temp_output_shape[3]):
                        for m in range(temp_output_shape[4]):
                            found = False
                            #loop over kernel
                            for u in range(temp_weight_shape[2]):
                                if found:
                                    break
                                k_input_temp = - temp_pads_computed_before[0] + k * temp_strides[0] + u
                                if (k_input_temp >= 0 and k_input_temp < temp_input_shape[2]):
                                    for v in range(temp_weight_shape[3]):
                                        if found:
                                            break
                                        l_input_temp = - temp_pads_computed_before[1] + l * temp_strides[1] + v
                                        if (l_input_temp >= 0 and l_input_temp < temp_input_shape[3]):
                                            for w in range(temp_weight_shape[4]):
                                                m_input_temp = - temp_pads_computed_before[2] + m * temp_strides[2] + w
                                                if (m_input_temp >= 0 and m_input_temp < temp_input_shape[4]):
                                                    if (Y[i, j, k, l, m] == \
                                                    X[i, j, int(k_input_temp), int(l_input_temp), int(m_input_temp)]) :
                                                        grad_X[i, j, int(k_input_temp), int(l_input_temp), int(m_input_temp)] = \
                                                        grad_Y[i, j, k, l, m]
                                                        found = True
                                                        break

        return [np.reshape(grad_X, original_input_shape)]


text:
import cv2
from PIL import Image
import numpy as np
import os
import time

import torch
from torch import nn
# from torchvision.models import resnet50
import torchvision.transforms as T
from hubconf import detr_resnet50, detr_resnet50_panoptic ,_make_detr
import ssl

import matplotlib.pyplot as plt
from models.detr import DETR
from torchvision.ops.boxes import batched_nms
from common_utils import vis,visual

model = None
device = 'cpu'
size=(800,800)
infer_size=(800,800)
conf_thres =0.7
nms_thres=0.5
mean=[0.,0.,0.] # rbr
std=[255., 255., 255.] #bgr

LABEL = (
    'N/A', 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',
    'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'N/A',
    'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse',
    'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'N/A', 'backpack',
    'umbrella', 'N/A', 'N/A', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis',
    'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove',
    'skateboard', 'surfboard', 'tennis racket', 'bottle', 'N/A', 'wine glass',
    'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich',
    'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake',
    'chair', 'couch', 'potted plant', 'bed', 'N/A', 'dining table', 'N/A',
    'N/A', 'toilet', 'N/A', 'tv', 'laptop', 'mouse', 'remote', 'keyboard',
    'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'N/A',
    'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier',
    'toothbrush'
)

# 图像数据处理
transform = T.Compose([
    T.Resize(800),
    T.ToTensor(),
    T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])

# 将xywh转xyxy
def box_cxcywh_to_xyxy(x):
    x_c, y_c, w, h = x.unbind(1)
    b = [(x_c - 0.5 * w), (y_c - 0.5 * h),
         (x_c + 0.5 * w), (y_c + 0.5 * h)]
    return torch.stack(b, dim=1)

# 将0-1映射到图像
def rescale_bboxes(out_bbox, size):
    img_w, img_h = size
    b = box_cxcywh_to_xyxy(out_bbox)
    b = b.cpu().numpy()
    b = b * np.array([img_w, img_h, img_w, img_h], dtype=np.float32)
    return b

def get_support_models():
    model_list=[]
    now_dir = os.path.dirname(os.path.realpath(__file__))
    for file in os.listdir(now_dir):
        if str(file).endswith('.pth') and 'detr' in str(file):
            model_list.append(str(file).replace('.pth', ''))
    return model_list

def create_model(model_name='detr-r50-e632da11', dev='cpu'):
    global model
    global device
    model = None
    device = dev

    # Load model

    pre_train = os.path.join(os.path.dirname(os.path.realpath(__file__)), '%s.pth' % (model_name))

    model = detr_resnet50(pretrained=False, num_classes=90 + 1).eval()
    #model = _make_detr("resnet50", dilation=False, num_classes=80 + 1)
    state_dict = torch.load(pre_train, map_location=device)
    model.load_state_dict(state_dict["model"])
    if device == 'cuda':
        model.cuda()

def inference(img):
    global model
    global device
    global size
    global conf_thres
    global nms_thres
    global mean
    global std

    map_result = {'type': 'img'}
    img2 =  cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

    #标准化等
    img2 = Image.fromarray(img2)
    img3 = transform(img2).unsqueeze(0)

    if img3.mode == 'RGBA':
        r, g, b, a = img3.split()
        img3 = Image.merge("RGB", (r, g, b))

    if device == "cuda":
        img3 = img3.cuda()

    with torch.no_grad():
        outputs = model(img3)
        #nms
        #pred = non_max_suppression(output, infer_conf, nms_thre, classes=None, agnostic=False)

    probas = outputs['pred_logits'].softmax(-1)[0, :, :-1]
    keep = probas.max(-1).values > conf_thres

    probas = probas.cpu().detach().numpy()
    keep = keep.cpu().detach().numpy()

    # convert boxes from [0; 1] to image scales
    bboxes_scaled = rescale_bboxes(outputs['pred_boxes'][0, keep],  img2.size)

    # draw det
    if  probas[keep] is None:
        map_result['result'] = img
    else:
        scores = []
        boxes = []
        cls = []
        for prob, (xmin, ymin, xmax, ymax) in zip(probas[keep], bboxes_scaled):  # 对各个类的概率和位置
            cl = prob.argmax()  # 选择概率最大值
            #scores.append(round(prob[cl] * 100, 2))
            scores.append(prob[cl])
            cls.append(cl)
            boxes.append([xmin,ymin,xmax,ymax])

        clss = np.array(cls, dtype = int)
        usescores = np.array(scores,dtype = float)
        useboxes = np.array(boxes,dtype = int)

        #vis_res = vis(img, useboxes, usescores, clss, conf=conf_thres)
        vis_res = visual(img, useboxes, usescores, clss, conf=conf_thres, class_names=LABEL)
        map_result['result'] = vis_res

    return map_result

if __name__ == '__main__':
    create_model(model_name='detr-r50-e632da11', dev='cpu')
    image = cv2.imread('people.jpg', cv2.IMREAD_COLOR)
    ret = inference(image)


text:
#!/usr/bin/env python

import rospy
from sensor_msgs.msg import Image
from std_srvs.srv import Empty
import numpy as np
from os.path import expanduser
import sys
import cv2
from cv_bridge import CvBridge, CvBridgeError
from duckietown_msgs.msg import Rect, Rects, FSMState
#import caffe
import time
np.set_printoptions(threshold=np.inf)
home = expanduser("~")

class CNN_node():
    def __init__(self):
        self.image_sub = rospy.Subscriber("/pbody/image_rect", Image, self.img_cb)
        self.mode_sub = rospy.Subscriber("/pbody/fsm_node/mode", FSMState, self.fsm_mode)
        self.image_pub = rospy.Publisher('gray', Image, queue_size=10)
        self.bridge = CvBridge()
        self.cv_image = 0
        self.cv_img_crop = []
        self.start = 0
        #caffe params
        self.model = model = 'street_en_harvest'
        ##self.caffe_root = home +'/caffe'
        ##sys.path.insert(0, self.caffe_root + 'python')
        ##caffe.set_mode_gpu()
        ##self.net_full_conv = caffe.Net(home+'/models/'+self.model+'.prototxt', home+'/models/'+self.model+'.caffemodel', caffe.TEST)
        nx, ny = (3, 28)
        x = np.linspace(0, 0, nx)
        y = np.linspace(50, 255, ny)
        xv, yv = np.meshgrid(x, y)
        self.class_colors = np.zeros((29,3))
        self.class_colors[0:28]=yv
        self.class_colors[28]=[0,0,0]
        self.class_colors = self.class_colors.astype(np.uint8)
        self.colorful_class_colors = np.random.rand(29,3)*255
        self.colorful_class_colors = self.colorful_class_colors.astype(np.uint8)
        self.switch_quad = 0
        self.switch_img = 1
        self.time = 0
        self.n = 1
        self.stop_line = 0

    def fsm_mode(self, msg):
        print "FSM node callback"
        if msg.state == "INTERSECTION_CONTROL":
            self.stop_line = 1
            print "start text spotting"
        elif msg.state == "JOYSTICK_CONTROL":
            self.stop_line = 0
            print "stop text spotting"
    def img_cb(self, data):

        #print "Image callback"
        #print self.stop_line
        #self.switch_img += 1
        #if self.switch_img != 60:
            #print "wait for prediction"
        #    return

        ##if self.stop_line == 0:
        ##    return

        try:
            #caffe.set_mode_gpu()
            self.switch_img = 0
            print "switch_on"
            self.start = data.header.stamp.secs
            start = time.time()
            self.cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
            #np_arr = np.fromstring(data.data, np.uint8)
            #self.cv_image = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
            img_gray = cv2.cvtColor(self.cv_image, cv2.COLOR_BGR2GRAY)
            mser = cv2.MSER_create(3, 100, 250000, 0.25, 0.2, 200, 1.01, 0.003, 5)
            regions, _ = mser.detectRegions(img_gray)
            hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]
            #cv2.polylines(gray_img, hulls, 1, (255, 0, 0), 2)
            imgContours = self.cv_image
            contour_list = []
            for i, contour in enumerate(hulls):
                x,y,w,h = cv2.boundingRect(contour)
                #repeat = self.checkContourRepeat(contour_list, x, y, w, h)
                #img_region = img_cv[y:y+h, x:x+w]
                if 2*h < w and h*w < 10000 and h*w > 1000:
                    cv2.rectangle(imgContours,(x, y),(x+w, y+h),(0,255,0),3)
                    img_region = self.cv_image[y:y+h, x:x+w]
                    self.cv_img_crop.append(img_region)
            image_all_mser_image = Image()
            image_all_mser_image.header = rospy.Time.now
            image_all_mser_image = self.bridge.cv2_to_imgmsg(imgContours, "bgr8")
            self.image_pub.publish(image_all_mser_image)
            print "detection time:",time.time()-start
            #self.cnn()

        except CvBridgeError as e:
            print(e)

    def cnn(self):
        if type(self.cv_image) == np.int:
            print "CNN"
            return

        i = 0
        for im in self.cv_img_crop:
        #im = self.cv_image
            start = time.time()
            im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
            if im is None:
                break
            #im = im/255.0
            #im = cv2.resize(im, (0,0), fx=2, fy=2)
            im = im.reshape(im.shape[0], im.shape[1], 1)
            #print im.shape

            ##transformer = caffe.io.Transformer({'data': self.net_full_conv.blobs['data'].data.shape})
            ##transformer.set_transpose('data', (2,0,1))

            #transformer.set_raw_scale('data', 255.0)
            ##self.net_full_conv.blobs['data'].reshape(1,1,32,100)
            ##transformed_image = transformer.preprocess('data', im)
            ##transformed_image -= np.mean(transformed_image)
            #make classification map by forward and print prediction indices at each location
            ##self.net_full_conv.blobs['data'].data[...] = transformed_image
            #self.net_full_conv.blobs['data'].data[...] = im
            #out = self.net_full_conv.forward(data=np.asarray(transformed_image))
            print 'Prediction time:', time.time()-start
            ##out = self.net_full_conv.forward()
            if i == 0:
                now = rospy.get_rostime().secs
                self.time += (now - self.start)
                print self.n, self.time
                self.n += 1
            i += 1

            top1 = out['prob'][0].argmax()
            if out['prob'][0][top1] >= 0.9:
                print 'class: ',top1
                print out['prob'][0][top1][0][0]
                if top1 == 4 or top1 == 2:
                    turn_right = rospy.ServiceProxy('/pbody/open_loop_intersection_control_node/turn_right', Empty)
                    turn = turn_right()
                elif top1 == 23:
                    turn_left = rospy.ServiceProxy('/pbody/open_loop_intersection_control_node/turn_left', Empty)
                    turn = turn_left()
                elif top1 == 14 or top1 == 22:
                    turn_forward = rospy.ServiceProxy('/pbody/open_loop_intersection_control_node/turn_forward', Empty)
                    turn = turn_forward()
                self.stop_line = 0
                break
                print "stop text spotting"

        self.cv_img_crop = []

    def onShutdown(self):
        rospy.loginfo("[%s] Shutdown." %(self.node_name))

def main(args):
    rospy.init_node('CNN_node', anonymous = True)
    ic = CNN_node()
    rospy.on_shutdown(ic.onShutdown)
    rospy.spin()

if __name__ == '__main__':
    main(sys.argv)


text:
import numpy as np

import Lya_zelda as Lya

import sys

import pylab as plt

# Setting the locations of your grids

your_grids_location = '/Users/sidgurung/Desktop/test_2/Grids/'

Lya.funcs.Data_location = your_grids_location

# Line profile grids:

Geometry = 'Thin_Shell'

LyaRT_Grid = Lya.load_Grid_Line( Geometry )

print( LyaRT_Grid.keys() )

print( 'The expansion velocity [km/s] is evaluated in : ')
print( LyaRT_Grid['V_Arr'    ] )

print( 'The logarithmic of the HI column density [cm**-2] is evaluated in : ')
print( LyaRT_Grid['logNH_Arr'] )

print( 'The logarithmic of the dust optical depth is evaluated in : ')
print( LyaRT_Grid['logta_Arr'] )

print( LyaRT_Grid['Grid'     ].shape )
print( LyaRT_Grid['V_Arr'    ].shape )
print( LyaRT_Grid['logNH_Arr'].shape )
print( LyaRT_Grid['logta_Arr'].shape )

w_Arr = Lya.convert_x_into_lamda( LyaRT_Grid['x_Arr'] )

plt.plot( w_Arr , LyaRT_Grid['Grid'][0,1,2,] )
plt.xlim( 1213*1e-10 , 1218*1e-10 )
plt.xlabel( 'wavelength [m]' )
plt.ylabel( 'Flux density [a.u.]' )
plt.savefig( 'fig_Tutorial_5_1.png' )
plt.clf()

# Line grids with smaller RAM occupation

Geometry = 'Thin_Shell_Cont'

print( Lya.load_Grid_Line )

LyaRT_Grid_Full = Lya.load_Grid_Line( Geometry , MODE='FULL' )

print( LyaRT_Grid_Full.keys() )

LyaRT_Grid_Light = Lya.load_Grid_Line( Geometry , MODE='LIGHT' )

print( LyaRT_Grid_Light.keys() )

print( 'The expansion velocity [km/s] is evaluated in : ')
print( LyaRT_Grid_Full['V_Arr'] )

print( 'The logarithmic of the HI column density [cm**-2] is evaluated in : ')
print( LyaRT_Grid_Full['logNH_Arr'] )

print( 'The logarithmic of the dust optical depth is evaluated in : ')
print( LyaRT_Grid_Full['logta_Arr'] )

print( 'The logarithmic of the intrinsic equivalent width [A] is evaluated in : ')
print( LyaRT_Grid_Full['logEW_Arr'] )

print( 'The logarithmic of the intrinsic line width [A] is evaluated in : ')
print( LyaRT_Grid_Full['Wi_Arr'] )

print('=========================')

print( 'The logarithmic of the intrinsic equivalent width [A] is evaluated in : ')
print( LyaRT_Grid_Light['logEW_Arr'] )

print( 'The logarithmic of the intrinsic line width [A] is evaluated in : ')
print( LyaRT_Grid_Light['Wi_Arr'] )


text:
"""
ARGPARSE --> Codigo --> Classes

Ejercicio casa:

    1) Usar funcion "argparse" para pasar dos listas de numeros (Cómo pasar una lista de numeros en argparse?? --> google)
    # lista1 = [a,b,c,d] lista2 = [1,2,3,4]

    if suma:

    2) Hacer la suma de las dos lista de numeros

    if media:

    3) Hacer la media de las dos listas

    if correlacion:

    4) Hacer la correlacion entre las dos listas

    if plot:

    4) Hacer el plot de las dos listas

    if diccionario:

    5) Hacer un diccionario {elementolista1: elementolista2, elemento2lista2, elemento2lista2....}
    # {a:1, b:2 c:3 d:4} -> [a,b,c,d] [1,2,3,4]
"""

import argparse
import numpy as np
import matplotlib.pyplot as plt

def parse_args():
    parser = argparse.ArgumentParser(description='Lee, guarda y haz cosas con tu CSV!')
    "Recoger lista de listas"
    #parser.add_argument('-l1','--lista1',  type=list, action='append', help='Recoge 2 listas', required=True)
    # Use like:
    # python arg.py -l 1234 -l 2345 -l 3456 -l 4567

    "Recoger lista una a una"
    parser.add_argument('-l1','--lista1',  nargs="+", type=int, help='Introduce lista1', required=True)
    parser.add_argument('-l2','--lista2', nargs="+",  type=int, help='Introduce lista2', required=True)

    "Solicitar al usuario si realizar dicha accion"
    parser.add_argument('--suma', action="store_true", help='Realiza la suma')
    parser.add_argument('--media', action="store_true", help='Realiza la media')
    parser.add_argument('--corr', action="store_true", help='Realiza la corr')
    parser.add_argument('--plot', action="store_true", help='Realiza el plot')
    parser.add_argument('--dicc', action="store_true", help='Realiza el dicc')

    args = parser.parse_args() #Lee la linea de commandline
    return args.lista1, args.lista2, args.suma, args.media, args.corr, args.plot, args.dicc

class Lista ():

    def __init__(self, lista1, lista2):
        self.lista1 = lista1
        self.lista2 = lista2
        self.lista = lista1 + lista2

    def output(self, suma, media, corr, plot, dicc):
        if suma:
            self.suma()

        if media:
            self.media()

        if corr:
            self.correlacion()

        if plot:
            self.plot()

        if dicc:
            self.diccionario()

    def suma(self):
        suma = sum(self.lista)
        print(suma)

    def media(self):
        media = np.mean(self.lista)
        print(media)

    def correlacion(self):
        print(np.corrcoef(self.lista))

    def plot(self):
        plt.xlabel("X-axis")
        plt.ylabel("Y-axis")
        plt.title("A test graph")
        plt.plot(self.lista1, self.lista2)
        plt.legend()
        plt.show()

    def diccionario(self):
        dictionary = {}
        for elemento1, elemento2 in zip(self.lista1, self.lista2):
            dictionary[elemento1] = elemento2
        print(dictionary)

"Definir main() para la parte de las ejecuciones"
def main():
    lista1, lista2, suma, media, corr, plot, dicc = parse_args()
    print(lista1, lista2, suma, media, corr, plot, dicc)
    objeto_lista = Lista (lista1, lista2)
    objeto_lista.output(suma, media, corr, plot, dicc)

main()


text:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 12 12:54:45 2019

@author: emre
"""
import numpy as np
from matplotlib import pyplot as plt
from shutil import copyfile
import inspect
import os
import glob
###############################################
warpings_dir = "/media/emre/Data/warpings/13-02-19-30_gamma_0.7/"
save_output = True
iar_max = 9
iac_max = 9
ndegree = 3
nr = 512
nc = 512
#################################################
def get_neigh_locs(composite,nan_loc,degree,nr,nc):

    neigh_array = list(range(-degree,0))+list(range(1,degree+1))
    nanr,nanc = nan_loc

    neigh_locs = []
    for i in neigh_array:
        for j in neigh_array:
            neigh_r = max(min(nr-1,nanr + i),0)
            neigh_c = max(min(nc-1,nanc + i),0)
            if (neigh_r,neigh_c) not in neigh_locs:
                if not np.isnan(composite[neigh_r,neigh_c,0]):
                    neigh_locs.append((neigh_r,neigh_c))
    return neigh_locs

def fill_in_the_blanks(composite):

    nan_locs = np.where(np.isnan(composite[:,:,0])==True)

    for k in range(len(nan_locs[0])):

        nan_loc = nan_locs[0][k],nan_locs[1][k]
        neigh_locs = get_neigh_locs(composite,nan_loc,degree=ndegree,nr=nr,nc=nc)

        neigh_sum = 0
        for neigh_loc in neigh_locs:
            neigh_sum = neigh_sum + composite[neigh_loc]
        neigh_mean = neigh_sum/len(neigh_locs)

        composite[nan_locs[0][k],nan_locs[1][k]] = neigh_mean

    return composite

if save_output:
    curr_file = inspect.getfile(inspect.currentframe()) # script filename (usually with path)
    copyfile(curr_file,warpings_dir + curr_file.split("/")[-1])

sample_paths = glob.glob(warpings_dir + "Warped_*")

for sample_path in sample_paths:

    sample = sample_path.split("_")[-1].split(".npy")[0]

    sample_output_dir = warpings_dir + sample + "/"
    if not os.path.exists(sample_output_dir):
        os.mkdir(sample_output_dir)

    allWarpeds = np.load(sample_path).all()

    target_views = list(allWarpeds.keys())

    #fig,axs = plt.subplots(len(target_views),figsize=(55,55))
    composites = dict()
    for k,target_view in enumerate(target_views):

        composite = np.zeros((nr,nc,3))
        valid_locs = dict()
        valid_loc_sum = np.zeros((nr,nc))

        targets_ref_views = list(allWarpeds[target_view].keys())
        for ref_view in targets_ref_views:
            valid_locs[ref_view] = np.sum(allWarpeds[target_view][ref_view],2)!=-3
            valid_loc_sum = valid_loc_sum + valid_locs[ref_view]

            this_warped = allWarpeds[target_view][ref_view]
            this_warped[np.where(this_warped==-1)] = 0
            composite = composite + this_warped

        composite = composite/np.tile(valid_loc_sum[:,:,np.newaxis],(1,1,3))
    #    axs[k].imshow(composites[target_view])

        composites[target_view] = fill_in_the_blanks(composite)
        if save_output:
            plt.imsave(sample_output_dir + "view_"+str(target_view)+".png",composites[target_view])
    #    plt.imsave()

#plt.imsave(warpings_dir + "views.png")
#plt.show()


text:
# MIT License
#
# Copyright (c) 2020-2022, Alex M. Maldonado
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# pylint: disable=E1101

import numpy as np
from .. import __version__ as mbgdml_version
from .basedata import mbGDMLData
from ..predict import mbPredict

class predictSet(mbGDMLData):
    """A predict set is a data set with mbGDML predicted energy and forces
    instead of training data.

    When analyzing many structures using mbGDML it is easier (and faster) to
    predict all many-body contributions once and then analyze the stored data.
    The predict set accomplishes just this.

    Attributes
    ----------
    name : :obj:`str`
        File name of the predict set.
    theory : :obj:`str`
        Specifies the level of theory used for GDML training.
    entity_ids : :obj:`numpy.ndarray`
        A uniquely identifying integer specifying what atoms belong to
        which entities. Entities can be a related set of atoms, molecules,
        or functional group. For example, a water and methanol molecule
        could be ``[0, 0, 0, 1, 1, 1, 1, 1, 1]``.
    comp_ids : :obj:`numpy.ndarray`
        Relates ``entity_id`` to a fragment label for chemical components
        or species. Labels could be ``WAT`` or ``h2o`` for water, ``MeOH``
        for methanol, ``bz`` for benzene, etc. There are no standardized
        labels for species. The index of the label is the respective
        ``entity_id``. For example, a water and methanol molecule could
        be ``['h2o', 'meoh']``.
    """

    def __init__(self, *args):
        self.name = 'predictset'
        self.type = 'p'
        self._loaded = False
        self._predicted = False
        for arg in args:
            self.load(arg)

    def prepare(
        self, z, R, entity_ids, comp_ids, ignore_criteria=False
    ):
        """Prepares a predict set by calculated the decomposed energy and
        force contributions.
        """

        self.E_decomp, self.F_decomp = self.mbgdml.predict_decomposed(
            z, R, entity_ids, comp_ids,
            ignore_criteria=ignore_criteria, store_each=True
        )

        self.mbgdml_version = mbgdml_version
        self._predicted = True

    def asdict(self):
        """Converts object into a custom :obj:`dict`.

        Returns
        -------
        :obj:`dict`
        """
        predictset = {
            'type': np.array('p'),
            'sgdml_version': np.array(self.sgdml_version),
            'mbgdml_version': np.array(self.mbgdml_version),
            'name': np.array(self.name),
            'theory': np.array(self.theory),
            'z': self.z,
            'R': self.R,
            'r_unit': np.array(self.r_unit),
            'E_true': self.E_true,
            'e_unit': np.array(self.e_unit),
            'F_true': self.F_true,
            'E_decomp': self.E_decomp,
            'F_decomp': self.F_decomp,
            'entity_ids': self.entity_ids,
            'comp_ids': self.comp_ids,
            'models_order': self.models_order,
            'models_md5': self.models_md5
        }

        if self._loaded == False and self._predicted == False:
            if not hasattr(self, 'dataset') or not hasattr(self, 'mbgdml'):
                raise AttributeError(
                    'No data can be predicted or is not loaded.'
                )
            else:
                self.prepare(self.z, self.R, self.entity_ids, self.comp_ids)

        return predictset

    @property
    def e_unit(self):
        """Units of energy. Options are ``'eV'``, ``'hartree'``,
        ``'kcal/mol'``, and ``'kJ/mol'``.

        :type: :obj:`str`
        """
        return self._e_unit

    @e_unit.setter
    def e_unit(self, var):
        self._e_unit = var

    @property
    def E_true(self):
        """True energies from data set.

        :type: :obj:`numpy.ndarray`
        """
        return self._E_true

    @property
    def F_true(self):
        """True forces from data set.

        :type: :obj:`numpy.ndarray`
        """
        return self._F_true

    def load(self, predictset_path):
        """Reads predict data set and loads data.

        Parameters
        ----------
        predictset_path : :obj:`str`
            Path to predict set ``.npz`` file.
        """
        predictset = dict(np.load(predictset_path, allow_pickle=True))
        self.name = str(predictset['name'][()])
        self.theory = str(predictset['theory'][()])
        self.sgdml_version = str(predictset['sgdml_version'][()])
        self.mbgdml_version = str(predictset['mbgdml_version'][()])
        self._z = predictset['z']
        self._R = predictset['R']
        self.E_decomp = predictset['E_decomp']
        self.F_decomp = predictset['F_decomp']
        self._r_unit = str(predictset['r_unit'][()])
        self._e_unit = str(predictset['e_unit'][()])
        self._E_true = predictset['E_true']
        self._F_true = predictset['F_true']
        self.entity_ids = predictset['entity_ids']
        self.comp_ids = predictset['comp_ids']
        self.models_order = predictset['models_order']
        self.models_md5 = predictset['models_md5']

        self._loaded = True

    def nbody_predictions(self, nbody_orders):
        """Energies and forces of all structures .

        Predict sets have data that is broken down into many-body contributions.
        This function sums the many-body contributions up to the specified
        level; for example, ``3`` returns the energy and force predictions when
        including one, two, and three body contributions/corrections.

        Parameters
        ----------
        nbody_orders : :obj:`list` [:obj:`int`]
            N-body orders to include.

        Returns
        -------
        :obj:`numpy.ndarray`
            Energy of structures up to and including n-order corrections.
        :obj:`numpy.ndarray`
            Forces of structures up to an including n-order corrections.
        """
        E = np.zeros(self.E_true.shape)
        F = np.zeros(self.F_true.shape)
        for nbody_order in nbody_orders:
            E_nbody = [i[nbody_order]['T'] for i in self.E_decomp]
            F_nbody = [i[nbody_order]['T'] for i in self.F_decomp]
            E = np.add(E, E_nbody)
            F = np.add(F, F_nbody)
        return E, F

    def load_dataset(self, dataset_path):
        """Loads data set in preparation to create a predict set.

        Parameters
        ----------
        dataset_path : :obj:`str`
            Path to data set.
        """
        self.dataset_path = dataset_path
        dataset = dict(np.load(dataset_path, allow_pickle=True))
        self.dataset = dataset
        self.theory = str(dataset['theory'][()])
        self._z = dataset['z']
        self._R = dataset['R']
        self._r_unit = str(dataset['r_unit'][()])
        self._e_unit = str(dataset['e_unit'][()])
        self._E_true = dataset['E']
        self._F_true = dataset['F']
        self.entity_ids = dataset['entity_ids']
        self.comp_ids = dataset['comp_ids']

    def load_models(self, model_paths):
        """Loads model(s) in preparation to create a predict set.

        Parameters
        ----------
        model_paths : :obj:`list` [:obj:`str`]
            Paths to GDML models in assending order of n-body corrections, e.g.,
            ['/path/to/1body-model.npz', '/path/to/2body-model.npz'].
        """
        self.model_paths = model_paths
        self.mbgdml = mbPredict(model_paths)

        from mbgdml.data import mbModel
        models_md5 = []
        models_order = []
        for model_path in model_paths:
            model = mbModel(model_path)
            models_order.append(len(set(model.entity_ids)))
            try:
                models_md5.append(model.md5)
            except AttributeError:
                pass
        self.models_order = np.array(models_order)
        self.models_md5 = np.array(models_md5)

max_stars_repo_name: aalexmmaldonado/mbGDML

max_issues_repo_name: aalexmmaldonado/mbGDML

max_forks_repo_name: aalexmmaldonado/mbGDML


text:
# coding=utf-8
import matplotlib.pyplot as plt
import numpy as np

def plot_residuals_reference_sections(
        resid,
        sections,
        fig=None,
        title=None,
        plot_avg_std=None,
        plot_names=True,
        robust=True,
        units='',
        fig_kwargs=None,
        method='split',
        time_dim='time',
        x_dim='x'):
    """
    Analyze the residuals of the reference sections, between the Stokes
    signal and a best-fit
    decaying exponential.

    Parameters
    ----------
    plot_avg_std
    resid : DataArray
        The residuals of the fit to estimate the noise in the measured
        Stokes signal. is returned by `ds.variance_stokes`
    sections : Dict[str, List[slice]]
        The sections obj is normally used to set DataStore.sections, now is
        used toobtain the
        section names to plot the names on top of the residuals.
    fig : Figurehandle, optional
    title : str, optional
        Adds a title to the plot
    plot_names : bool
        Whether the names of the sections are plotted on top of the residuals
    method: str
        'split' will remove the distance between sections to cut down on the
        whitespace.
        'single' will use the previous method, where all sections are in one
        plot.
    time_dim : str
        Name of the time dimension to average/take the variance of
    x_dim : str
        Name of the spatial dimension

    Returns
    -------
    fig : Figurehandle

    """
    if method == 'single':
        plot_residuals_reference_sections_single(
            resid,
            fig=fig,
            title=title,
            plot_avg_std=plot_avg_std,
            plot_names=plot_names,
            sections=sections,
            robust=robust,
            units=units,
            fig_kwargs=fig_kwargs)

    elif method != 'split':
        raise AssertionError('Unknown method')

    else:
        # Set up the axes with gridspec
        if fig_kwargs is None:
            fig_kwargs = dict()

        if fig is None:
            fig = plt.figure(figsize=(8, 6), **fig_kwargs)

        if title:
            fig.suptitle(title)

        # Create the unsorted list
        section_list = []
        section_name_list = []
        for section in sections:
            for sl in sections[section]:
                section_list.append(sl)
                section_name_list.append(section)

        # Make dictionaries to start sorting
        sections_dict = {}
        section_start_dict = {}
        for ii in range(len(section_list)):
            sections_dict[str(ii)] = [section_name_list[ii],
                                      section_list[ii]]
            section_start_dict[str(ii)] = section_list[ii].start

        sorted_sections = sorted(sections_dict,
                                 key=section_start_dict.__getitem__,
                                 reverse=True)

        # Create the sorted name and slice lists
        section_name_list = [sections_dict[name][0] for name in
                             sorted_sections]
        section_list = [sections_dict[name][1] for name in
                        sorted_sections]

        resid_sections = [resid.sel(x=section) for section in section_list]

        section_ylims = [[sl.start, sl.stop] for sl in section_list]
        section_height_ratios = [sl.stop-sl.start for sl in section_list]
        nsections = len(section_list)

        grid = plt.GridSpec(
                ncols=3,
                nrows=nsections+1,
                height_ratios=[sum(section_height_ratios)/5] +
                section_height_ratios,
                width_ratios=[0.2, 0.8, 0.1],
                hspace=0.15,
                wspace=0.15,
                left=0.08,
                bottom=0.12,
                right=0.9,
                top=0.88)

        _x_ax_avg = fig.add_subplot(grid[0, 1])
        x_ax_avg = _x_ax_avg.twinx()

        cbar_ax = fig.add_subplot(grid[1:, 2])

        section_axes = [0]*nsections
        section_ax_avg = [0]*nsections

        legend_ax = fig.add_subplot(grid[0, 0])

        for ii in range(nsections):
            section_axes[ii] = fig.add_subplot(grid[ii+1, 1])
            section_ax_avg[ii] = fig.add_subplot(grid[ii+1, 0])

        # Link all 2dplot axes to their bottom row
        for section_ax in section_axes[:-1]:
            section_axes[-1].get_shared_x_axes().join(section_axes[-1],
                                                      section_ax)
            section_ax.set_xticklabels([])

        # Link all 2dplot axes to their avg axes
        for ii in range(nsections):
            section_ax_avg[ii].get_shared_y_axes().join(section_ax_avg[ii],
                                                        section_axes[ii])
            section_axes[ii].set_yticklabels([])

        # Link all avg axes to their bottom row
        for section_avg in section_ax_avg[:-1]:
            section_ax_avg[-1].get_shared_x_axes().join(section_ax_avg[-1],
                                                        section_avg)
            section_avg.set_xticklabels([])

        # Link the x ax avg to the bottom row
        section_axes[-1].get_shared_x_axes().join(section_axes[-1], x_ax_avg)
        x_ax_avg.set_xticklabels([])

        # Determine vmin, vmax;
        vmin, vmax = resid.quantile([.01, .99])

        # Plot the data
        for ii in range(nsections):
            resid_sections[ii].plot(ax=section_axes[ii],
                                    cbar_ax=cbar_ax,
                                    cbar_kwargs={'extend': 'both'},
                                    vmin=vmin, vmax=vmax)
            section_axes[ii].set_ylabel('')

            resid.sel(x=section_list[ii]).std(dim=time_dim).plot(
                                                        ax=section_ax_avg[ii],
                                                        y=x_dim,
                                                        c='blue')
            resid.sel(x=section_list[ii]).mean(dim=time_dim).plot(
                                                         ax=section_ax_avg[ii],
                                                         y=x_dim,
                                                         c='orange')
            section_ax_avg[ii].axvline(0, linestyle='-',
                                       c='black', linewidth=0.8)
            section_ax_avg[ii].set_ylabel('')

        cbar_ax.set_ylabel(units)

        for ii, section_avg in enumerate(section_ax_avg):
            section_avg.set_ylim(section_ylims[ii])
            section_avg.set_xlim([vmin, vmax])
            ticks = section_avg.set_yticks(section_ylims[ii])
            ticks[0].label1.set_verticalalignment('bottom')
            ticks[1].label1.set_verticalalignment('top')
        section_ax_avg[-1].set_xticks([np.floor(vmin*10)/10, 0, np.ceil(vmax*10)/10])
        section_ax_avg[-1].set_xlabel(units)

        for section_ax in section_axes[:-1]:
            section_ax.set_xlabel('')

        section_ax_avg[np.ceil(nsections/2).astype(int)-1].set_ylabel('x (m)')

        # plot the x ax avg
        resid.std(dim=x_dim).plot(ax=x_ax_avg, c='blue')
        resid.mean(dim=x_dim).plot(ax=x_ax_avg, c='orange')
        x_ax_avg.axhline(0, linestyle='-', c='black', linewidth=0.8)
        x_ax_avg.set_xlabel('')
        x_ax_avg.set_ylabel(units)
        _x_ax_avg.set_yticks([])

        # make the legend
        legend_ax.fill_between([], [], facecolor='blue', label='STD')
        legend_ax.fill_between([], [], facecolor='orange', label='MEAN')
        legend_ax.legend(loc='center')
        legend_ax.axis('off')

        # add section names
        if plot_names:
            for ii, section in enumerate(section_list):
                xlim = section_axes[ii].get_xlim()
                xc = (xlim[1] + xlim[0]) / 2
                yc = (section.start + section.stop) / 2
                section_axes[ii].text(
                    xc,
                    yc,
                    s=section_name_list[ii],
                    horizontalalignment='center',
                    verticalalignment='center',
                    bbox=dict(facecolor='white', alpha=0.90, edgecolor='none'))

        return fig

def plot_residuals_reference_sections_single(
        resid,
        fig=None,
        title=None,
        plot_avg_std=None,
        plot_names=True,
        sections=None,
        robust=True,
        units='',
        fig_kwargs=None,
        time_dim='time',
        x_dim='x'):
    """
    Analyze the residuals of the reference sections, between the Stokes
    signal and a best-fit
    decaying exponential.

    Parameters
    ----------
    plot_avg_std
    resid : DataArray
        The residuals of the fit to estimate the noise in the measured
        Stokes signal. is returned by `ds.variance_stokes`
    fig : Figurehandle, optional
    title : str, optional
        Adds a title to the plot
    plot_names : bool
        Whether the names of the sections are plotted on top of the residuals
    sections : Dict[str, List[slice]]
        The sections obj is normally used to set DataStore.sections, now is
        used toobtain the
        section names to plot the names on top of the residuals.
    time_dim : str
        Name of the time dimension to average/take the variance of
    x_dim : str
        Name of the spatial dimension

    Returns
    -------
    fig : Figurehandle

    """
    if plot_names:
        assert sections is not None, 'The sections names are obtained from ' \
                                     'the sections dict'

    # Set up the axes with gridspec
    if fig_kwargs is None:
        fig_kwargs = dict()

    if fig is None:
        fig = plt.figure(figsize=(8, 6), **fig_kwargs)

    if title:
        fig.suptitle(title)

    grid = plt.GridSpec(
        10,
        10,
        hspace=0.2,
        wspace=0.2,
        left=0.08,
        bottom=0.12,
        right=0.9,
        top=0.88)
    main_ax = fig.add_subplot(grid[2:, 2:-1])
    y_ax_avg = fig.add_subplot(grid[2:, :2])  # xticklabels=[],
    x_ax_avg = fig.add_subplot(grid[:2, 2:-1])  # , sharex=main_ax
    legend_ax = fig.add_subplot(grid[:2, :2], xticklabels=[], yticklabels=[])
    cbar_ax = fig.add_subplot(grid[2:, -1], xticklabels=[], yticklabels=[])
    if (np.issubdtype(resid[time_dim].dtype, np.float) or
            np.issubdtype(resid[time_dim].dtype, np.int)):
        resid.plot.imshow(ax=main_ax, cbar_ax=cbar_ax, cbar_kwargs={'aspect': 10}, robust=robust)
    else:
        resid.plot(
            ax=main_ax, cbar_ax=cbar_ax, cbar_kwargs={'aspect': 10}, robust=robust)
    main_ax.set_yticklabels([])
    main_ax.set_ylabel('')
    cbar_ax.set_ylabel(units)

    # x_ax_avg
    x_ax_avg2 = x_ax_avg.twinx()
    resid.std(dim=x_dim).plot(ax=x_ax_avg2, c='blue')
    resid.mean(dim=x_dim).plot(ax=x_ax_avg2, c='orange')
    x_ax_avg2.axhline(0, linestyle='-', c='black', linewidth=0.8)
    if plot_avg_std is not None:
        x_ax_avg2.axhline(plot_avg_std, linestyle='--', c='blue')

    x_ax_avg.set_xticklabels([])
    x_ax_avg.set_yticklabels([])
    x_ax_avg.set_xlim(main_ax.get_xlim())
    x_ax_avg2.set_ylabel(units)

    # y_ax_avg
    dp = resid.std(dim=time_dim)
    x = dp.values
    y = dp[x_dim]
    y_ax_avg.plot(x, y, c='blue')
    dp = resid.mean(dim=time_dim)
    x = dp.values
    y = dp[x_dim]
    y_ax_avg.plot(x, y, c='orange')
    y_ax_avg.set_ylim(main_ax.get_ylim())
    y_ax_avg.set_ylabel('x (m)')
    y_ax_avg.set_xlabel(units)
    if plot_avg_std is not None:
        y_ax_avg.axvline(plot_avg_std, linestyle='--', c='blue')

    y_ax_avg.axvline(0, linestyle='-', c='black', linewidth=0.8)
    # reverse axis
    y_ax_avg.set_xlim(y_ax_avg.get_xlim()[::-1])

    # legend
    legend_ax.fill_between([], [], facecolor='blue', label='STD')
    legend_ax.fill_between([], [], facecolor='orange', label='MEAN')
    legend_ax.legend(loc='center')
    legend_ax.axis('off')

    if plot_names:
        xlim = main_ax.get_xlim()
        xc = (xlim[1] + xlim[0]) / 2
        for k, section in sections.items():
            for stretch in section:
                yc = (stretch.start + stretch.stop) / 2
                main_ax.text(
                    xc,
                    yc,
                    k,
                    horizontalalignment='center',
                    verticalalignment='center',
                    bbox=dict(facecolor='white', alpha=0.90, edgecolor='none'))

    return fig

def plot_accuracy(
        accuracy,
        accuracy_x_avg,
        accuracy_time_avg,
        precision_x_avg=None,
        precision_time_avg=None,
        real_accuracy_time_avg=None,
        fig=None,
        title=None,
        plot_names=True,
        sections=None,
        x_dim='x'):
    """
    Analyze the residuals of the reference sections, between the Stokes
    signal and a best-fit
    decaying exponential.

    Parameters
    ----------
    plot_avg_std
    resid : DataArray
        The residuals of the fit to estimate the noise in the measured
        Stokes signal. is returned by `ds.variance_stokes`
    fig : Figurehandle, optional
    title : str, optional
        Adds a title to the plot
    plot_names : bool, optional
        Whether the names of the sections are plotted on top of the residuals
    sections : Dict[str, List[slice]]
        The sections obj is normally used to set DataStore.sections, now is
        used toobtain the
        section names to plot the names on top of the residuals.
    x_dim : str
        Name of the spatial dimension

    Returns
    -------
    fig : Figurehandle

    """
    if plot_names:
        assert sections is not None, 'The sections names are obtained from ' \
                                     'the sections dict'

    # Set up the axes with gridspec
    if fig is None:
        fig = plt.figure(figsize=(8, 6))

    if title:
        fig.suptitle(title)

    # setup the axes
    grid = plt.GridSpec(
        10,
        10,
        hspace=0.2,
        wspace=0.2,
        left=0.08,
        bottom=0.12,
        right=0.9,
        top=0.88)
    main_ax = fig.add_subplot(grid[2:, 2:-1])
    y_ax_avg = fig.add_subplot(grid[2:, :2])  # xticklabels=[],
    x_ax_avg = fig.add_subplot(grid[:2, 2:-1])  # , sharex=main_ax
    legend_ax = fig.add_subplot(grid[:2, :2], xticklabels=[], yticklabels=[])
    cbar_ax = fig.add_subplot(grid[2:, -1], xticklabels=[], yticklabels=[])

    accuracy.plot(
        ax=main_ax, cbar_ax=cbar_ax, cbar_kwargs={'aspect': 20}, robust=True)
    main_ax.set_yticklabels([])
    main_ax.set_ylabel('')
    cbar_ax.set_ylabel(r'$^\circ$C')

    # x_ax_avg
    x_ax_avg2 = x_ax_avg.twinx()
    x_ax_avg2.axhline(0, linestyle='-', c='black', linewidth=0.8)
    if precision_x_avg is not None:
        precision_x_avg.plot(ax=x_ax_avg2, c='blue', linewidth=1.1)
    accuracy_x_avg.plot(ax=x_ax_avg2, c='orange', linewidth=0.9)

    x_ax_avg.set_xticklabels([])
    x_ax_avg.set_yticklabels([])
    x_ax_avg.set_yticks([])
    x_ax_avg.set_xlim(main_ax.get_xlim())
    x_ax_avg2.set_ylabel(r'$^\circ$C')

    # y_ax_avg
    y_ax_avg.axvline(0, linestyle='-', c='black', linewidth=0.8)
    if precision_time_avg is not None:
        x = precision_time_avg.values
        y = precision_time_avg[x_dim]
        y_ax_avg.plot(x, y, c='blue', linewidth=1.1)
    x = accuracy_time_avg.values
    y = accuracy_time_avg[x_dim]
    y_ax_avg.plot(x, y, c='orange', linewidth=0.9)
    if real_accuracy_time_avg is not None:
        x = real_accuracy_time_avg.values
        y = real_accuracy_time_avg[x_dim]
        y_ax_avg.plot(x, y, c='green', linewidth=0.9)

    y_ax_avg.set_ylim(main_ax.get_ylim())
    y_ax_avg.set_xlabel(r'$^\circ$C')
    y_ax_avg.set_ylabel('x (m)')

    # reverse axis
    y_ax_avg.set_xlim(y_ax_avg.get_xlim()[::-1])

    # legend
    if real_accuracy_time_avg is not None:
        legend_ax.fill_between(
            [], [], facecolor='blue', label='Projected precision')
        legend_ax.fill_between(
            [], [], facecolor='orange', label='Projected accuracy')
        legend_ax.fill_between(
            [], [], facecolor='green', label='Measured accuracy')
    else:
        legend_ax.fill_between([], [], facecolor='blue', label='Precision')
        legend_ax.fill_between([], [], facecolor='orange', label='Accuracy')

    legend_ax.legend(loc='right', fontsize=9)
    legend_ax.axis('off')

    if plot_names:
        xlim = main_ax.get_xlim()
        xc = (xlim[1] + xlim[0]) / 2
        for k, section in sections.items():
            for stretch in section:
                # main axis
                yc = (stretch.start + stretch.stop) / 2
                main_ax.text(
                    xc,
                    yc,
                    k,
                    horizontalalignment='center',
                    verticalalignment='center',
                    bbox=dict(facecolor='white', alpha=0.90, edgecolor='none'))
                # main_ax.axhline(stretch.start, color='white', linewidth=1.4)
                main_ax.axhline(stretch.start, color='grey', linewidth=0.8)
                # main_ax.axhline(stretch.stop, color='white', linewidth=1.4)
                main_ax.axhline(stretch.stop, color='grey', linewidth=0.8)

                # y-avg-axis
                y_ax_avg.axhline(stretch.start, color='grey', linewidth=0.8)
                y_ax_avg.axhline(stretch.stop, color='grey', linewidth=0.8)

    return fig

def plot_sigma_report(
        ds, temp_label,
        temp_var_acc_label,
        temp_var_prec_label=None,
        itimes=None):
    """
    Returns two sub-plots. first a temperature with confidence boundaries.
    Parameters
    ----------
    ds
    temp_label
    temp_var_label
    itimes
    """
    time_dim = ds.get_time_dim(data_var_key=temp_label)
    x_dim = ds.get_x_dim(data_var_key=temp_label)
    assert 'CI' not in ds[temp_label].dims, 'use other plot report function'

    fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True, figsize=(12, 8))

    colors = ['#ffeda0', '#feb24c', '#f03b20']

    line_kwargs = dict(linewidth=0.7)

    if itimes:
        temp = ds[temp_label].isel(time=itimes)
        stds = np.sqrt(ds[temp_var_acc_label].isel(time=itimes)).compute()
    else:
        temp = ds[temp_label].mean(dim=time_dim).compute()
        stds = np.sqrt(ds[temp_var_acc_label]).mean(dim=time_dim).compute()

    for l, c in zip([2., 1.], colors):
        y1 = temp - l * stds
        y2 = temp + l * stds
        label_str = '{0:2.2f}'.format(l) + r'$\sigma$ confidence interval'
        ax1.fill_between(
            y1[x_dim],
            y1,
            y2,
            facecolor=c,
            label=label_str,
            alpha=0.9,
            linewidth=0.7,
            edgecolor=c)

    if isinstance(itimes, list):
        for iitimes in itimes:
            ds[temp_label].isel(time=iitimes).plot(
                ax=ax1, c='grey', label='DTS single', **line_kwargs)

    temp.plot(ax=ax1, linewidth=0.8, c='black', label='DTS')

    if itimes:
        # std_dts_proj = d.ufunc_per_section(
        #     func=np.std,
        #     label='TMPF_MC_set',
        #     calc_per='stretch',
        #     temp_err=False,
        #     subtract_from_label='TMPF',
        #     axis=[0, 1])
        # std_dts_meas = d.ufunc_per_section(
        #     func=np.std,
        #     label='TMPF',
        #     calc_per='stretch',
        #     temp_err=True,
        #     axis=0)
        sigma_est = ds.ufunc_per_section(
            label=temp_label,
            func=np.std,
            temp_err=True,
            calc_per='stretch',
            axis=0)
    else:
        sigma_est = ds.ufunc_per_section(
            label=temp_label, func=np.std, temp_err=True, calc_per='stretch')

    for (k, v), (k_se, v_se) in zip(ds.sections.items(), sigma_est.items()):
        for vi, v_sei in zip(v, v_se):
            if hasattr(v_sei, 'compute'):
                v_sei = v_sei.compute()

            if itimes:
                val = ds[k].mean(dim=time_dim)
            else:
                val = ds[k].isel(time=itimes)

            ax1.plot(
                [vi.start, vi.stop], [val, val],
                linewidth=0.8,
                c='blue',
                linestyle='--')
            sig_dts = stds.sel(x=vi).mean()
            tbx, tby = (vi.start + vi.stop) / 2, val
            tbt = r"$\sigma_{Est}$ = " + "{0:2.3f}".format(
                sig_dts.data) + r"$^\circ$C" + "\n" + \
                r"$\sigma_{DTS}$ = " + "{0:2.3f}".format(
                v_sei) + r"$^\circ$C"
            ax1.annotate(
                tbt,
                xy=(tbx, tby),
                ha='center',
                fontsize=8,
                xytext=(0, 16),
                textcoords='offset points',
                bbox=dict(fc='white', alpha=0.9, color='none'))

    if itimes is None:
        ax1.set_title(
            'Temperature and standard deviation averaged over '
            'time per reference section')
    else:
        ax1.set_title(
            'Projected uncertainty at t={} compared to standard error '
            'in baths'.format(itimes))
    ax1.legend()
    ax1.set_ylabel(r'Temperature [$^\circ$C]')

    err_ref = ds.ufunc_per_section(
        label=temp_label, func=None, temp_err=True, calc_per='stretch')
    x_ref = ds.ufunc_per_section(label=x_dim, calc_per='stretch')

    for (k, v), (k_se, v_se), (kx, vx) in zip(ds.sections.items(),
                                              err_ref.items(), x_ref.items()):
        for vi, v_sei, vxi in zip(v, v_se, vx):
            var_temp_t = np.std(v_sei, axis=1)
            ax2.plot(vxi, var_temp_t, label=k, **line_kwargs)

    if temp_var_acc_label:
        stds.plot(ax=ax2, c='black', label='Projected accuracy', **line_kwargs)

    if temp_var_prec_label:
        if itimes:
            stds_prec = np.sqrt(ds[temp_var_prec_label].isel(time=itimes))
        else:
            stds_prec = np.sqrt(ds[temp_var_prec_label]).mean(dim=time_dim)
        stds_prec.plot(
            ax=ax2, c='black', label='Projected precision', **line_kwargs)

    ax2.set_ylim([0., 1.1 * stds.max()])
    ax2.legend()
    ax2.set_ylabel(r'Temperature [$^\circ$C]')

    plt.tight_layout()

max_stars_repo_name: bvdscheer/python-dts-calibration

max_issues_repo_name: bvdscheer/python-dts-calibration

max_forks_repo_name: bvdscheer/python-dts-calibration


text:
import numpy as np
import datetime
import glob2
import xarray as xr
import pandas as pd
import re
#plt.close("all")
pd.options.display.max_columns = None
pd.options.display.max_rows = None
import plotly.io as pio
import plotly.express as px
pio.renderers.default='browser'

dircInput1 = 'C:/Users/Chenxi/OneDrive/phd/age_and_fire/data/01_raw/03_HALO-DB_mission_116/'
dircInput2 = 'C:/Users/Chenxi/OneDrive/phd/age_and_fire/data/03_cleaned/03_HALO-DB_mission_116_cleaned/'

#file names
fn_amica_database = glob2.glob(dircInput1 + 'AMICA/' + '*.ames')
fn_amica_wiki = glob2.glob(dircInput1 + 'AMICA/' + '*.dat')
fn_bahamas = glob2.glob(dircInput1 + 'BAHAMAS/' + '*.nc')
fn_fairo = glob2.glob(dircInput1 + 'FAIRO/' + '*FAIRO_O3*.ames')
fn_fairoCI = glob2.glob(dircInput1 + 'FAIRO/' + '*FAIROCI_O3*.ames')
fn_fish = glob2.glob(dircInput1 + 'FISH/' + '*FISH_H2O.ames')
fn_umaq = glob2.glob(dircInput1 + 'UMAQ/' + '*.ames')
fn_aeneas = glob2.glob(dircInput1 + 'AENEAS/' + '*.ames')
fn_hagar_li = glob2.glob(dircInput1+'*HAGARV_LI_prelim.ames')
fn_hagar_ecd = glob2.glob(dircInput1+'*HAGARV_ECD_preliminary.ames')
fn_ghost = glob2.glob(dircInput1+'*GhOST_MS_preliminary.ames')

fn_Met_V2 = glob2.glob(dircInput1 + 'CLAMS_Met/' + '*CLAMS_Met_V2.nc')
fn_agespec_HN2 = glob2.glob(dircInput1+'*CLAMS_agespec_HN2.nc')
# fn_backtraj_nr_ST1_cfc_clim = glob2.glob(dircInput1+'clams_at_halo/'+'*backtraj_nr_ST1_cfc_clim.nc')
# fn_backtraj_nr_ST1_clim = glob2.glob(dircInput1+'clams_at_halo/'+'*backtraj_nr_ST1_clim.nc')
fn_sfctracer_F02 = glob2.glob(dircInput1+'*CLAMS_sfctracer_F02.nc')
fn_chem_V1 = glob2.glob(dircInput1+'*CLAMS_chem_V1.nc')
#fn_gloria_kit = glob2.glob(dircInput1+'*GLORIA_chemistry_mode_KIT.nc')
#fn_gloria_fzj = glob2.glob(dircInput1+'*GLORIAFZJ_L1V0002preL2V00pre.nc')

############################in-situ measurements###############################
def clean_bahamas(res, fn = fn_bahamas):
    frame = []
    for filename in fn:
        df = xr.open_dataset(filename).to_dataframe()
        df.rename(columns = {'TIME': "time",
                              'IRS_ALT': 'ALT',
                              'IRS_LAT': 'LAT',
                              'IRS_LON': 'LON',
                              }, inplace = True)
        df.set_index('time', inplace = True)
        df = df.resample(f'{res}S').mean()
        df['flight'] = df.index[0].strftime('%Y-%m-%d')
        frame.append(df)
    output = pd.concat(frame)
    output.sort_index(inplace = True)
    return output[['ALT','LAT','LON','THETA','flight']]

def clean_amica(res, fn = fn_amica_wiki):
    frame = []
    for filename in fn:
        df = pd.read_csv(
                         filename,
                         delimiter = ',',
                         skiprows = [1],
                         header = [0],
                         parse_dates = [0],
                         infer_datetime_format = True,
                         #names=['time','AMICA:OCS','AMICA:CO','AMICA:H2O']
                         )
        df.set_index('time', inplace = True)
        df.sort_index(inplace = True)
        new_names = {
                'CO': 'AMICA_CO',
                'H2O': 'AMICA_H2O',
                }
        df.rename(columns = new_names, inplace = True)
        frame.append(df)
    output = pd.concat(frame)
    output.sort_index(inplace = True)
    output.rename(columns = {'O3': 'AMICA_O3',}, inplace = True)
    return output#[list(new_names.values())+ ['OCS', 'AMICA_O3']]

def clean_fairo(res, fn = fn_fairo):
    frame = []
    for filename in fn:
        date = pd.to_datetime(re.findall("(\d+)", filename)[-3])
        df = pd.read_csv(
                         filename,
                         delimiter='\t',
                         skiprows=27,
                         header=0
                         )
        df['time'] = df['UTC_seconds'].apply(lambda x: datetime.timedelta(seconds = x) + date)
        df.drop(columns = ['UTC_seconds'], inplace = True)
        df.set_index('time', inplace = True)
        df.replace(-9999, np.nan, inplace=True)
        df = df.resample(f'{res}S').mean()
        df.rename(columns = {'Ozone[ppb]': 'FAIRO_O3'}, inplace = True)
        frame.append(df)
    output = pd.concat(frame)
    output.sort_index(inplace = True)

    return output

def clean_fish(res, fn = fn_fish):
    frame=[]
    for filename in fn:
        date=pd.to_datetime(re.findall("(\d+)", filename)[-2])
        df = pd.read_csv(
                         filename,
                         skiprows=19,
                         delimiter=' ',
                         names=['UTC_seconds','H2O_tot','H2O_tot_err']
                         )
        df['time']=df['UTC_seconds'].apply(lambda x: datetime.timedelta(seconds=x)+date )
                         #,parse_dates=[0])
        df.set_index('time', inplace = True)
        df = df.resample(f'{res}S').mean()
        df.rename(columns = {'H2O_tot': 'FISH_H2O'}, inplace = True)
        frame.append(df)
    output = pd.concat(frame)
    output.sort_index(inplace = True)
    return output[['FISH_H2O']]

def clean_umaq(res, fn = fn_umaq):
    frame=[]
    for filename in fn:
        date=pd.to_datetime(re.findall("(\d+)", filename)[-5])
        df = pd.read_csv(
                         filename,
                         skiprows=36,
                         delimiter=' ',
                         header=0,
                         )
        df['time']=df['UTC_seconds'].apply(lambda x: datetime.timedelta(seconds=x)+date )
                         #,parse_dates=[0])
        df.drop(columns = ['UTC_seconds'], inplace = True)
        df.set_index('time', inplace = True)
        df.replace(99999.00, np.nan, inplace = True)
        df = df.resample(f'{res}S').mean()
        df.rename(columns = {'UMAQS_CH4_ppbv': 'UMAQS_CH4',
                             'UMAQS_N2O_ppbv': 'UMAQS_N2O',
                             'UMAQS_CO2_ppmv': 'UMAQS_CO2',
                             'UMAQS_CO_ppbv': 'UMAQS_CO',
                             }, inplace = True)
        frame.append(df)
    output = pd.concat(frame)
    output.sort_index(inplace = True)
    return output

def clean_aeneas(res, fn = fn_aeneas):
    frame=[]
    for filename in fn:
        date=pd.to_datetime(''.join(re.findall("(\d+)", filename)[-3:-1]))
        df = pd.read_csv(
                         filename,
                         skiprows=20,
                         delimiter=' ',
                         names=['UTC_seconds', 'AENEAS_NO', 'AENEAS_NOy'],
                         )
        df['time']=df['UTC_seconds'].apply(lambda x: datetime.timedelta(seconds=x)+date )
                         #,parse_dates=[0])
        df.drop(columns = ['UTC_seconds'], inplace = True)
        df.set_index('time', inplace = True)
        df.replace(-9999, np.nan, inplace = True)
        df = df.resample(f'{res}S').mean()
        frame.append(df)
    output = pd.concat(frame)
    output.sort_index(inplace = True)
    return output

#####################################CLaMS#####################################
def clean_Met_V2(res, fn = fn_Met_V2):
    frame=[]
    for filename in fn:
        df = xr.open_dataset(filename).to_dataframe()
        df = df.resample(f'{res}S').mean()
        # df=df.rename(columns={"TIME": "time"})
        # df=df.set_index('time')
        frame.append(df)
    output = pd.concat(frame)
    output.sort_index(inplace = True)
    return output[['PV']]

def clean_agespec_HN2(res, fn = fn_agespec_HN2):
    frame=[]
    for filename in fn:
        df = xr.open_dataset(filename).to_dataframe()
        df = df.resample(f'{res}S').mean()
        frame.append(df)
    output = pd.concat(frame)
    output.sort_index(inplace = True)
    new_names = {
        'AGESPEC_P50': 'P50',
        'AGEFRAC_L06': 'MF_06',
        'AGEFRAC_G24': 'MF_24',
        }
    output.rename(columns = new_names, inplace = True)
    output['MF_06'] = output['MF_06'] * 100
    output['MF_24'] = output['MF_24'] * 100
    return output[list(new_names.values()) + ['AGE']]

def clean_sfctracer_F02(res, fn = fn_sfctracer_F02):
    frame=[]
    for filename in fn:
        df = xr.open_dataset(filename).to_dataframe()
        df = df.resample(f'{res}S').mean()
        frame.append(df)
    output = pd.concat(frame)
    output.sort_index(inplace=True)
    output.drop(columns=['LAT',
                         'LON',
                         'NOONLAT',
                         'NOONLON',
                         'NOONTHETA',
                         'NOONZETA',
                         'PRESS',
                         'THETA',
                         'ZETA',
                         'P0',
                         'P1',
                         'P2',
                         'P3',
                         'P4',
                         'P5',
                         'P6',
                         'P7',
                         'P8',
                            ], inplace=True)
    return output

###############################################################################
def merge(df1, df2, res):
    return pd.merge_asof(df1, df2,
                     left_index=True,
                     right_index=True,
                     tolerance = pd.Timedelta(f'{res}S'),
                     direction = 'nearest')

def read(strat=0, res=30, LAT = '*', ALT = '*', local=0, transfer=0, PV=[2, 4]):
    """
    read all relevant data from SouthTRAC
    Parameters:
    strat (boolen): True: only shows stratopheric data. False: all data
    res (int): time resolution in seconds. Default: 30
    LAT ([lower_bound, higher_bound]): latitude range
    ALT (int or float): lower bound of the latitude range
    Returns:
    pd.dataframe
    """
    df = merge(clean_bahamas(res), clean_amica(res), res)
    df = merge(df, clean_fairo(res), res)
    df = merge(df, clean_fish(res), res)
    df = merge(df, clean_umaq(res), res)
    df = merge(df, clean_aeneas(res), res)
    df = merge(df, clean_Met_V2(res), res)
    df = merge(df, clean_agespec_HN2(res), res)
    df = merge(df, clean_sfctracer_F02(res), res)

    if strat:
        print (f'abs(PV)>{PV[0]} or theta>380K only')
        df = df[(abs(df['PV'])>PV[0]) | (df['THETA']>380)]

    if local:
        print ('local flights only')
        df = df[~df['flight'].isin(['2019-09-08','2019-09-09',
                           '2019-10-07','2019-10-06','2019-10-09',
                           '2019-11-02','2019-11-04','2019-11-06'])]

    if transfer:
        print ('trasnfer flights only')
        df = df[df['flight'].isin(['2019-09-08','2019-09-09',
                           '2019-10-07','2019-10-06','2019-10-09',
                           '2019-11-02','2019-11-04','2019-11-06'])]

    if isinstance(LAT, list):
        df = df[(df['LAT'] > LAT[0]) & (df['LAT'] <= LAT[1])]
        print(f'latitude between {LAT[0]} to {LAT[1]} only')
    else:
        print ('Attention: ALL latitude selected')

    df['ALT'] = df['ALT']/1000
    if isinstance(ALT, list):
        df = df[(df['ALT'] > LAT[0]) & (df['ALT'] <= LAT[1])]
        print(f'altitude between {ALT[0]} to {ALT[1]} only')
    elif type(ALT) == int or type(ALT) == float:
        df = df[df['ALT'] > ALT]
        print(f'altitude>{ALT} only')
    else:
        print ('Attention: ALL altitude selected')

    df.loc[:, 'air'] = 0
    strat_filter = (abs(df['PV'])>PV[0]) | (df['THETA']>380)
    real_strat_filter = abs(df['PV']) >= PV[1]
    df.loc[strat_filter, 'air'] = 1
    df.loc[real_strat_filter, 'air'] = 2

    return df

if __name__ == "__main__":
    #test the module
    res = int (input('time resolution in seconds:\n'))
    df = read(res = res, strat=0)
    print(df.head())


text:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Scripts gathering different chi2 functions.

Author:
    Dimitri Misiak (misiak@ipnl.in2p3.fr)
"""

import numpy as np
import scipy.optimize as op
import matplotlib.pyplot as plt

from .psd import psd, psd_from_fft2

def chi2_simple(data_1, data_2, err):
    """ Simplest chi2 function comparing two sets of datas.

    Parameters
    ==========
    data_1, data_2 : array_like
        Set of data to be compared.
    err : float or array_like
        Error affecting the data. If float is given, the error is the same
        for each points. If array_like, each point is affected by its
        corresponding error.

    Returns
    =======
    x2 : float
        Chi2 value.
    """
    array_1 = np.array(data_1)
    array_2 = np.array(data_2)
    err_array = np.array(err)
    x2 = np.sum( (array_1 - array_2)**2  / err_array**2 )
    return x2

def chi2_freq(fft_1, fft_2, psd_err, fs):
    """ Chi2 function comparing two sets of datas through their FFT, taking as
    reference the the PSD of the noise level.

    Parameters
    ==========
    fft_1, fft_2 : array_like
        FFT of data to be compared. Their frequency are ordered as
        the numpy.fft.fft function result (i.e. [0, positive, negative]).
    psd_err : float or array_like
        PSD of the error affecting the data. If float is given, the error is the same
        for each points. If array_like, each point is affected by its
        corresponding error.
    fs : float or int
        Sampling frequency.

    Returns
    =======
    x2 : float
        Chi2 value.
    """
    assert len(fft_1) == len(fft_2)
    assert len(psd_err) == 1 or len(psd_err) == len(fft_1)/2

    psd_data = psd(fft_1 - fft_2, fs)[1]

    x2 = np.sum( psd_data / np.array(psd_err) )

    return x2

def opt_chi2_amp(fft_data, fft_template, psd_err, fs):
    """ cf OF note. Based on the differenciation of the chi2 function to
    minimize the chi2 for the amplitude.
    """
    sv = psd_from_fft2(np.real(fft_template.conjugate() * fft_data), fs)[1]
    ss = psd_from_fft2(np.real(np.abs(fft_template)**2), fs)[1]
    numerator = np.sum(sv * psd_err**-1)
    denominator = np.sum(ss * psd_err**-1)
    if denominator == 0:
        amp_opt = 0
    else:
        amp_opt = numerator / denominator

    return amp_opt

reason: import numpy,import scipy


text:
#!/usr/bin/env python

# dataset: http://kdd.ics.uci.edu/databases/kddcup99/kddcup99.html

import sys
import os

# Path for spark source folder
os.environ['SPARK_HOME']="/usr/lib/spark"

# Append pyspark  to Python Path
sys.path.append("/usr/lib/spark/python")

try:
    from pyspark import SparkContext, SparkConf
    from pyspark.mllib.clustering import KMeans
    from pyspark.mllib.feature import StandardScaler
    print ("Successfully imported Spark Modules")
except ImportError as e:
    print ("Can not import Spark Modules", e)
    sys.exit(1)

from collections import OrderedDict
from numpy import array
from math import sqrt

def parse_interaction(line):
    """
    Parses a network data interaction.
    """
    line_split = line.split(",")
    clean_line_split = [line_split[0]]+line_split[4:-1]
    return (line_split[-1], array([float(x) for x in clean_line_split]))

def distance(a, b):
    """
    Calculates the euclidean distance between two numeric RDDs
    """
    return sqrt(
        a.zip(b)
        .map(lambda x: (x[0]-x[1]))
        .map(lambda x: x*x)
        .reduce(lambda a,b: a+b)
        )

def dist_to_centroid(datum, clusters):
    """
    Determines the distance of a point to its cluster centroid
    """
    cluster = clusters.predict(datum)
    centroid = clusters.centers[cluster]
    return sqrt(sum([x**2 for x in (centroid - datum)]))

def clustering_score(data, k):
    clusters = KMeans.train(data, k, maxIterations=10, runs=5, initializationMode="random")
    result = (k, clusters, data.map(lambda datum: dist_to_centroid(datum, clusters)).mean())
    print "Clustering score for k=%(k)d is %(score)f" % {"k": k, "score": result[2]}
    return result

if __name__ == "__main__":
    if (len(sys.argv) != 3):
        print "Usage: /path/to/spark/bin/spark-submit --driver-memory 2g " + \
          "KDDCup99.py max_k kddcup.data.file"
        sys.exit(1)

    # set up environment
    max_k = int(sys.argv[1])
    data_file = sys.argv[2]
    conf = SparkConf().setAppName("KDDCup99") \
      #.set("spark.executor.memory", "2g")
    sc = SparkContext(conf=conf)

    # load raw data
    print "Loading RAW data..."
    raw_data = sc.textFile(data_file)

    # count by all different labels and print them decreasingly
    print "Counting all different labels"
    labels = raw_data.map(lambda line: line.strip().split(",")[-1])
    label_counts = labels.countByValue()
    sorted_labels = OrderedDict(sorted(label_counts.items(), key=lambda t: t[1], reverse=True))
    for label, count in sorted_labels.items():
        print label, count

    # Prepare data for clustering input
    # the data contains non-numeric features, we want to exclude them since
    # k-means works with numeric features. These are the first three and the last
    # column in each data row
    print "Parsing dataset..."
    parsed_data = raw_data.map(parse_interaction)
    parsed_data_values = parsed_data.values().cache()

    # Standardize data
    print "Standardizing data..."
    standardizer = StandardScaler(True, True)
    standardizer_model = standardizer.fit(parsed_data_values)
    standardized_data_values = standardizer_model.transform(parsed_data_values)

    # Evaluate values of k from 5 to 40
    print "Calculating total in within cluster distance for different k values (10 to %(max_k)d):" % {"max_k": max_k}
    scores = map(lambda k: clustering_score(standardized_data_values, k), range(10,max_k+1,10))

    # Obtain min score k
    min_k = min(scores, key=lambda x: x[2])[0]
    print "Best k value is %(best_k)d" % {"best_k": min_k}

    # Use the best model to assign a cluster to each datum
    # We use here standardized data - it is more appropriate for exploratory purposes
    print "Obtaining clustering result sample for k=%(min_k)d..." % {"min_k": min_k}
    best_model = min(scores, key=lambda x: x[2])[1]
    cluster_assignments_sample = standardized_data_values.map(lambda datum: str(best_model.predict(datum))+","+",".join(map(str,datum))).sample(False,0.05)

    # Save assignment sample to file
    print "Saving sample to file..."
    cluster_assignments_sample.saveAsTextFile("sample_standardized")
    print "DONE!"

reason: from numpy


text:
import h5py
import os
import numpy as np
import math
import os.path
import random
import matplotlib.pyplot as plt

root_dir = "/home/ali/Codes/Caffe/models/yumi_pick_vae/results/"
data_type = "traj_restored/"
n_data = 1
traj_length = 77
n_joints = 7

trajs = np.zeros((n_data, n_joints*traj_length))

for i in range(0, n_data):
    data_filename = root_dir + data_type + '{:0>4}'.format(i) + '.txt'
    freader = open(data_filename, 'r')
    freader.readline()
    freader.readline()       # number of joints
    for j in range(0, n_joints):
        for t in range(0, traj_length ):
            trajs[i,t*n_joints+j] = float(freader.readline())

print trajs.shape
print np.amax(trajs)
print np.amin(trajs)

for d in range(0,n_data):
    x = np.zeros((traj_length))
    y = np.zeros((n_joints, traj_length))
    for j in range(0, n_joints):
        for t in range(0, traj_length):
            x[t] = t
            y[j,t] = trajs[d,t*n_joints+j]
        plt.plot(x, y[j], '-')
plt.show()

max_stars_repo_name: AliGhadirzadeh/Caffe

max_issues_repo_name: AliGhadirzadeh/Caffe

max_forks_repo_name: AliGhadirzadeh/Caffe


text:
from __future__ import division
from lxml import etree
import requests as rq
import re
import numpy as np

import json

url = "https://voice.baidu.com/act/newpneumonia/newpneumonia"

# 获取网页内容
def get_html(url):
    headers = {
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"}

    src_html = rq.get(url, headers).content
    return src_html

def parse_page(content):
    html = etree.HTML(content)
    pages = html.xpath('/html/body/script[8]/text()')
    return pages

for str in parse_page(get_html(url)):
    d = json.loads(str, encoding="utf-8")

    component = d["component"]

    for objts in component[0]["caseList"]:
        print(objts["confirmed"],
              objts["died"],
              objts["crued"],
              objts["relativeTime"],
              objts["confirmedRelative"],
              objts["diedRelative"],
              objts["curedRelative"],
              objts["curConfirm"],
              objts["area"])

    for oj in component[0]["globalList"]:
        print(oj)


text:
import json
import numpy as np
import tensorflow as tf
from tensorflow import keras
#from sklearn.externals import joblib
import azureml
from azureml.contrib.services.aml_request import AMLRequest, rawhttp
from azureml.contrib.services.aml_response import AMLResponse
from azureml.core.model import Model
from io import BytesIO

import PIL
from keras.models import load_model
from keras.preprocessing.image import load_img, img_to_array, ImageDataGenerator
from keras.preprocessing import image
from PIL import Image
import traceback

def init():
    global model
    # Replace filename if needed.
    model_path = Model.get_model_path('classification_model')
    # model = joblib.load(model_path)
    model = tf.keras.models.load_model(model_path)

@rawhttp
def run(request):
	global testType
	global testType2
	try:
		if(request.method=='POST'):
			#file_bytes = request.files['image']
			file_bytes = request.data

			my_image = Image.open(BytesIO(file_bytes)).convert('RGB')
			testType=type(my_image)
			#image = (Image.open(file_bytes.stream))
			#image.save('api_call_image\testphoto.png', 'PNG')
			#my_image = load_img('api_call_image\testphoto.png', target_size=(224, 224))
			my_image = my_image.resize((224,224))

			my_image = my_image.convert('L')
			testType2=type(my_image)
			my_image = image.img_to_array(my_image)
			my_image/=255
			my_image = np.expand_dims(my_image, axis=0)
			prediction = model.predict(my_image)[0][0]#

			confidence = abs(.5-prediction)*2
			if(prediction>.5):
				answer = "positive"
			else:
				answer = "negative"

			#print("prediction is ", prediction)
			#print("confidence is ", confidence)
			#print("diagnosis is ", answer)
			dict1 ={
			   "diagnosis": str(answer),
			   "confidence": str(confidence),
			   "probability": str(prediction)
					}

			return AMLResponse(json.dumps(dict1), 200)

		else:
			return AMLResponse(json.dumps("bad request"), 500)

	except Exception as e:
		dict2 ={
			"exception": "error is",
			"error": str(e),
			"tb": traceback.format_exc(),
			"type": str(testType),
			"type2": str(testType2)

				}

		return AMLResponse(json.dumps(dict2) , 200)

max_stars_repo_licenses: Unlicense MIT

max_issues_repo_licenses: Unlicense MIT

max_forks_repo_licenses: Unlicense MIT