示例#1
0
文件: Plot.py 项目: axk19970225/DDB
    def plot_one(self,
                 Tag=None,
                 Shot=None,
                 Savepath=None,
                 xline=None,
                 yline=None,
                 Showplot=False):
        if Savepath:
            root_path = Savepath
            if not os.path.exists(root_path):
                raise ValueError(
                    'No such saving path, you need to create one! ')
        else:
            root_path = os.getcwd() + os.sep + "plot"
            print(root_path)
            if not os.path.exists(root_path):
                os.makedirs(root_path)

        reader = Reader(root_path=self.hdf5path)
        try:
            data = reader.read_one(int(Shot), Tag)
            tag_name = Tag[1:]
            plt.figure((str(Shot) + tag_name))
            plt.plot(data[1], data[0], 'g')
            if xline:
                if not isNum(xline):
                    raise ValueError('xline needs to be number ')
                plt.axvline(round(xline, 3))
            if yline:
                if not isNum(yline):
                    raise ValueError('yline needs to be number ')
                plt.axhline(round(yline, 3))
            name = str(Shot) + r" " + tag_name
            path = root_path + os.sep + r"{}.png".format(name)
            plt.savefig(path)
            if Showplot:
                plt.show()
            plt.close()
        except Exception as err:
            print("Shot:{}".format(shot) + " Tag:{}  ".format(tag_name) +
                  "No data")
            plt.close()
            pass
示例#2
0
 def Vpfiltshot(self, Shotlist=None, Threshold=None, Detail=False):
     Shotlist = list(Shotlist)
     input = Shotlist
     if not Threshold:
         Threshold = 0.015
     reader = Reader(root_path=self.hdf5path)
     breakvp = []
     n = 1
     for shot in Shotlist:
         print("第{}个".format(n))
         n += 1
         data = reader.read_one(int(shot), r"\vp2")
         # 低通滤波
         ba = signal.butter(8, 0.01, "lowpass")
         fdata = signal.filtfilt(ba[0], ba[1], data[0])
         if max(fdata) < Threshold:
             breakvp.append(shot)
     output = breakvp
     if Detail:
         print("Number of input shots    : {}".format(len(input)))
         print("Number of output shots   : {}".format(len(output)))
     return output
示例#3
0
文件: Plot.py 项目: axk19970225/DDB
    def plot_much(self,
                  Taglist=None,
                  Shotlist=None,
                  Savepath=None,
                  ShowDownTime=False,
                  ShowIpFlat=False,
                  xline=None,
                  yline=None):
        if Savepath:
            root_path = Savepath
            if not os.path.exists(root_path):
                raise ValueError(
                    'No such saving path, you need to create one! ')
        else:
            root_path = os.getcwd() + os.sep + "plot"
            print(root_path)
            if not os.path.exists(root_path):
                os.makedirs(root_path)
        for tag in Taglist:
            tag_name = tag[1:]
            file_path = root_path + os.sep + tag_name
            if not os.path.exists(file_path):
                os.makedirs(file_path)

        reader = Reader(root_path=self.hdf5path)
        db = Query()
        for tag in Taglist:
            tag_name = tag[1:]
            file_path = root_path + os.sep + tag_name
            n = 1
            for shot in Shotlist:
                print("Shot:{}".format(shot) + " Tag:{}  ".format(tag_name) +
                      "No.{}".format(n))
                n += 1
                try:
                    shot_info = db.tag(int(shot))
                    data = reader.read_one(int(shot), tag)
                    plt.figure((str(shot) + tag_name))
                    plt.plot(data[1], data[0], 'g')
                    if ShowDownTime:
                        if shot_info["IsValidShot"]:
                            if shot_info["IsDisrupt"]:
                                plt.axvline(round(shot_info["CqTime"], 3),
                                            c='r')
                            else:
                                plt.axvline(round(shot_info["RampDownTime"],
                                                  3),
                                            c='r')
                    if ShowIpFlat:
                        if tag == r"\ip":
                            if shot_info["IsValidShot"]:
                                plt.axhline(round(shot_info["IpFlat"], 3),
                                            c='k')
                    if xline:
                        if not isNum(xline):
                            raise ValueError('xline needs to be number ')
                        plt.axvline(round(xline, 3))
                    if yline:
                        if not isNum(yline):
                            raise ValueError('yline needs to be number ')
                        plt.axhline(round(yline, 3))
                    path = file_path + os.sep + r"{}.png".format(shot)
                    plt.savefig(path)
                    plt.close()
                except Exception as err:
                    print("Shot:{}".format(shot) +
                          " Tag:{}  ".format(tag_name) + "No data")
                    plt.close()
                    pass
    os.makedirs(save_path)

n = 1
mistake = []
reader = Reader()
db = Query()
for shot in TrainShot:
    print("Shot:{}  ".format(shot) + "No.{}".format(n))
    n += 1
    try:
        shot_info = db.tag(int(shot))
        file = h5py.File(save_path + os.sep + r"{}.hdf5".format(shot))
        if not shot_info["IsDisrupt"]:
            DownTime = shot_info["RampDownTime"]
            for shottag in all_tags:
                dataset = reader.read_one(int(shot), shottag)
                data = dataset[0]
                time = dataset[1]
                data = data[time <= DownTime]
                time = time[time <= DownTime]
                data = data[time > 0.2]
                time = time[time > 0.2]
                datatemp = data[time < 0.21]
                if len(datatemp) < 200:
                    processed_data = process_10kHz(data)
                elif len(datatemp) < 700:
                    processed_data = process_50kHz(data)
                elif len(datatemp) < 3000:
                    processed_data = process_250kHz(data)
                elif len(datatemp) < 7000:
                    processed_data = process_500kHz(data)