<commit_before>#!/bin/python3
# -*- coding: utf-8 -*-

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import Axes3D
import seaborn as sns
import matplotlib as mpl
import argparse
import os
from numpy import pi, sin, exp
import json
import pandas as pd

sns.set(context="poster", style='white')


class Analyzer:
    def __init__(self, base_path, meta_path):
        self.load(base_path, meta_path)

    def load(self, base_path: str, meta_path: str) -> None:
        with open(os.path.join(base_path, meta_path)) as fp:
            self.meta = json.load(fp)
            self.solution = self.load_block(base_path, self.meta["solution"])

    @staticmethod
    def load_block(base_path: str, block: dict) -> np.ndarray:
        if block["format"] == "arma_ascii":
            return np.loadtxt(os.path.join(base_path, block["path"]))

        if block["type"] == "float64":
            type = np.float64
        elif block["type"] == "int8":
            type = np.int8
        elif block["type"] == "int16":
            type = np.int16
        elif block["type"] == "int32":
            type = np.int32
        elif block["type"] == "int64":
            type = np.int64
        elif block["type"] == "uint64":
            type = np.uint64
        else:
            raise(RuntimeError(f"{block['type']} from {block['path']} is not supported"))

        data = np.fromfile(os.path.join(base_path, block["path"]), dtype=type)
        return data.reshape(*block["dim"])

    def plot(self):
        # self.plot_analytic_solution()
        self.plot_numerical_solution()

    def plot_numerical_solution(self):
        x = np.linspace(0, 1, self.meta['x steps']+2)
        trange = range(0, self.meta['t steps'], self.meta['t steps']//10)
        palette = sns.color_palette("GnBu_d", len(trange))
        for i, t in enumerate(trange):
            plt.plot(x, self.solution[t, :], label=rf'{t*self.meta["dt"]}', c=palette[i])
        plt.legend()
        plt.show()

    def plot_analytic_solution(self):
        U = 1
        h = 1
        nu = 1

        def u(y, t):
            S = 0
            for n in range(1, 1000):
                S += 1/n*exp(-n**2*pi**2*nu*t/h**2)*sin(n*pi*(1-y/h))
            return U*y/h - 2*U/pi * S

        fig, ax = plt.subplots(1)
        y = np.linspace(0, 1, 100)
        ts = [0, 0.001, 0.01, 0.1, 0.2, 0.3, 0.5, 0.8, 0.9, 1.0]
        palette = sns.color_palette("GnBu_d", len(ts))
        for i, t in enumerate(ts):<commit_msg>Add quiver plot to analyze<commit_after>#!/bin/python3
# -*- coding: utf-8 -*-

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import Axes3D
import seaborn as sns
import matplotlib as mpl
import argparse
import os
from numpy import pi, sin, exp
import json
import pandas as pd

sns.set(context="poster", style='white')


class Analyzer:
    def __init__(self, base_path, meta_path):
        self.load(base_path, meta_path)

    def load(self, base_path: str, meta_path: str) -> None:
        with open(os.path.join(base_path, meta_path)) as fp:
            self.meta = json.load(fp)
            self.solution = self.load_block(base_path, self.meta["solution"])

    @staticmethod
    def load_block(base_path: str, block: dict) -> np.ndarray:
        if block["format"] == "arma_ascii":
            return np.loadtxt(os.path.join(base_path, block["path"]))

        if block["type"] == "float64":
            type = np.float64
        elif block["type"] == "int8":
            type = np.int8
        elif block["type"] == "int16":
            type = np.int16
        elif block["type"] == "int32":
            type = np.int32
        elif block["type"] == "int64":
            type = np.int64
        elif block["type"] == "uint64":
            type = np.uint64
        else:
            raise(RuntimeError(f"{block['type']} from {block['path']} is not supported"))

        data = np.fromfile(os.path.join(base_path, block["path"]), dtype=type)
        return data.reshape(*block["dim"])

    def plot(self):
        # self.plot_analytic_solution()
        # self.plot_numerical_solution()
        self.plot_quiver()

    def plot_numerical_solution(self):
        x = np.linspace(0, 1, self.meta['x steps']+2)
        trange = range(0, self.meta['t steps'], self.meta['t steps']//10)
        palette = sns.color_palette("GnBu_d", len(trange))
        for i, t in enumerate(trange):
            plt.plot(x, self.solution[t, :], label=rf'{t*self.meta["dt"]}', c=palette[i])
        plt.legend()
        plt.show()

    def plot_quiver(self):
        y = np.linspace(0,1,self.meta['x steps'] + 2)
        fig, ax = plt.subplots(1,1)
        U = self.solution[0,:]
        zeros = np.zeros_like(U)
        Q = ax.quiver(zeros, y, U, zeros)
        ax.set_xlim(-0.1*U.max(), 1.1*U.max())
        ax.set_ylim(-0.1, 1.1)
        t = 0

        anim = animation.FuncAnimation(fig, self.update_quiver,
                                       fargs=(U,Q),
                                       interval=10,
                                       frames=range(0,len(self.solution)),
                                       blit=False)
        plt.show()

    def update_quiver(self, num, U, Q):
        U = self.solution[num,:]
        Q.set_UVC(U, np.zeros_like(U))
        return Q,

    def plot_analytic_solution(self):
        U = 1
        h = 1
        nu = 1

        def u(y, t):
            S = 0
            for n in range(1, 1000):
                S += 1/n*exp(-n**2*pi**2*nu*t/h**2)*sin(n*pi*(1-y/h))
            return U*y/h - 2*U/pi * S

        fig, ax = plt.subplots(1)
        y = np.linspace(0, 1, 100)
        ts = [0, 0.001, 0.01, 0.1, 0.2, 0.3, 0.5, 0.8, 0.9, 1.0]
        palette = sns.color_palette("GnBu_d", len(ts))
        for i, t in enumerate(ts):
{'fraction_non_alphanumeric': 0.15210355987055016, 'fraction_numerical': 0.0286152273888605, 'mean_word_length': 2.090526315789474, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4795065', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2031, 'n_words': 461}