<jupyter_start><jupyter_text>センサデータを解析するためのプログラム 流れ DataFrameにして、時系列グラフやヒストグラムなどで可視化  ライブラリインポート<jupyter_code>#必要なものいろいろインポートするでー
import numpy as np
import pandas as pd
import datetime
import matplotlib.pyplot as plt
from scipy import stats
import seaborn as sns<jupyter_output><empty_output><jupyter_text>sensor dataを読み込んでDataFrameに落とし込むclass<jupyter_code>class Sensor_Data:
        #違うセンサデータファイルでもclassのメソッドを使えるように初期化
    def __init__(self, file_name, delimiter, header, time, sensor1, probs, unit1, unit2):
        self.file_name = file_name #ファイルの名前
        self.delimiter = delimiter #delimiter…txtファイルで、隣り合うデータの区切り。半角スペースが多いかも
        self.header = header #ファイルのヘッダー
        #self.date = date #txtファイルで記録している日付
        self.time = time #テキストファイルで記録している時間
        self.sensor1 = sensor1 #テキストファイルで記録したsensor
        #self.sensor2 = sensor2
        self.probs = probs #表を回数→確率にするときに使う。（表の項目設定に使う。）
        self.unit1 = unit1
        self.unit2 = unit2
    
    def sensor_dataframe(self):
        global data
        data = pd.read_csv(self.file_name, self.delimiter, self.header, names = (self.time, self.unit1))
        data[self.unit2] = data[self.unit1] * 10** 4 #単位変換[G]->[T]
        return data 
       
sensor_data = Sensor_Data("3DM-DH_center_gnu_0706_2nd.txt", " ", None, "time[μs]", "center", "Probs", "magnetic intensity of z-axis[G]","magnetic intensity of z-axis[T]" )
data_frame = sensor_data.sensor_dataframe()
#data_frame["magnetic intensity of z-axis[T]"] = data_frame["magnetic intensity of z-axis[G]"] * 10** (4)
data_frame<jupyter_output>/tmp/ipykernel_626/2601637816.py:2: FutureWarning: In a future version of pandas all arguments of read_csv except for the argument 'filepath_or_buffer' will be keyword-only
  data_frame = sensor_data.sensor_dataframe()<jupyter_text>グラフを作るclass time_series_plt(self) : 時系列グラフをプロットする関数<jupyter_code>class Graph_Plot(Sensor_Data):
    #def __init__(self):
        #super().__init__()
    
    def time_series_plt(self):
        data = super().sensor_dataframe()
        #data = super().data
        
        fig, ax = plt.subplots()
        plt.figure(figsize=(6, 4))
        ax.plot(data[self.time], data[self.unit2])
        ax.set_xlabel(self.time)
        ax.set_ylabel(self.unit2)
        ax.set_title(self.sensor1)
        plt.show()
        
    def histgram_plt(self):
        data = super().sensor_dataframe()
        #return data["magnetic intensity of z-axis[T]"].values
        
        mag = []
        for i in range(len(data)):
            mag.append(data[self.unit2][i])
            
        """
        fig1, ax = plt.subplots()
        hist = ax.hist(data["magnetic intensity of z-axis[T]"].values, bins=30)
        ax.plot(hist)
        ax.set_xlabel("magnetic intensity of z-axis[T]")
        ax.set_ylabel("frequency")
        ax.set_title("histgram")
        plt.show()
        """
        plt.figure(figsize=(6, 4))
        plt.title(self.sensor1)
        plt.xlabel(self.unit2)
        plt.ylabel("frequency")
        plt.hist(mag, bins=30)
        plt.grid(True)
        plt.show()
        
        #print(data[self.unit])
        
graph_plot = Graph_Plot("3DM-DH_left_gnu_0705_2nd.txt", " ", None, "time[μs]", "left", "Probs", "magnetic intensity of z-axis[G]", "magnetic intensity of z-axis[T]")
#time_series = Time_Series()
graph_plot.time_series_plt()
graph_plot.histgram_plt()<jupyter_output>/tmp/ipykernel_626/669095725.py:18: FutureWarning: In a future version of pandas all arguments of read_csv except for the argument 'filepath_or_buffer' will be keyword-only
  data = super().sensor_dataframe()
{'fraction_non_alphanumeric': 0.12008916132627473, 'fraction_numerical': 0.020897185845639453, 'mean_word_length': 3.2738095238095237, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '433647', 'license': 'MIT', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1386, 'n_words': 235, 'path': 'New_Anaysis_SenosorData.ipynb', 'repo_name': 'hirotoppi/sensor_analysis', 'size': '3589'}