Example #1
0
def readFromServer(shot_no_start=1047630, shot_no_stop=1047634, signal_name='\ip', singal_dicimals=3, time_dicimals=4):
    # 从服务器读数据
    c = connection.Connection('211.67.27.7')
    print('{} shots to read'.format(shot_no_stop-shot_no_start+1))
    signals = []
    shots = []
    time = []
    print('Start Reading signal {} ...'.format(signal_name))
    for i in range(shot_no_stop-shot_no_start+1):
        shot_no = shot_no_start + i
        print('Shot No.{}'.format(shot_no))
        try:
            c.openTree('jtext', shot=shot_no)
            singal = c.get(r'{}'.format(signal_name)).tolist()
            if i == 0 or not time:
                time = c.get(r'DIM_OF(BUILD_PATH({}))'.format(signal_name)).tolist()
                time_round = list(np.round(np.array(time), time_dicimals))
            singal_round = list(np.round(np.array(singal), singal_dicimals))
        except:
            print('ATTENTION: Shot No.{} read fail, it might don\'t exist.'.format(shot_no))
            singal_round = []
        signals.append(singal_round)
        shots.append(shot_no)
    c.closeAllTrees()
    print('Reading finished')
    return shots, signals, time_round
Example #2
0
def generateShotData(shot, aspect_ratio, flux_ref):
    import MDSplus.connection as mdsplus
    mds = mdsplus.Connection("dave.physics.wisc.edu")
    mds.openTree("mst", shot)  # 1100903060 -> 10-40, 14-NOV-2005
    try:
        ip = mds.get(r"\ip").data()
        # vla = mds.get(r"\vloop_alpha").data()
        vlp = mds.get(r"\vloop_pfm").data()
        nel = mds.get(r"\n_co2").data()
        vpg = mds.get(r"\vpg").data()
        # vtg = mds.get(r"\vtg").data()
        btw = mds.get(r"\btw_b").data()
        btave = mds.get(r"\btave_b").data()
        alpha = mds.get(r"\alpha_par").data()
        minor_b = mds.get(r"\minor_b").data()
        tm_ip = mds.get(r"dim_of(\ip)").data()
        tm_nel = mds.get(r"dim_of(\n_co2)").data()
    finally:
        mds.closeAllTrees()

    a = minor_b
    R0 = aspect_ratio * a

    sub = (tm_nel >= tm_ip[0])
    tn = tm_nel[sub]
    density = nel[sub]

    offset = np.argwhere(ip > 0.1)[0, 0] + 160
    # offset = 160

    t = tm_ip[offset:]

    alpha = alpha[offset:]

    tn = tn[offset:]
    density = density[offset:]
    density = np.maximum(density * 1.0e6, 1.0e18)

    flux = btave[offset:] * 1e-4 * np.pi * a**2
    flux_multiplier = flux[0] / flux_ref

    V_phi = vpg[offset:]
    V_theta = smoothy(-deriv5(flux, t))

    I_phi = ip[offset:]
    I_theta = btw[offset:] * 0.97 * R0 / 2.0e-7 * 1.0e-10

    P_ohm_over_I_phi = vlp[offset:]

    nz = btave[offset:] != 0
    theta = t * np.nan
    theta[nz] = 4 * I_phi[nz] / btave[offset:][nz]
    f = t * np.nan
    f = btw[offset:][nz] / btave[offset:][nz]

    data = np.column_stack((t, alpha, V_phi, V_theta, flux, I_theta, I_phi,
                            P_ohm_over_I_phi, theta, f))
    header = "flux_multiplier = {0}".format(flux_multiplier)
    np.savetxt("realdata.dat", data, header=header)
    np.savetxt("density.dat", np.column_stack((tn, density)))


# @autosave(subconfig, prefix="x")
# def f(a, b):
# 	return b, a
#
# class autosave:
# 	def __init__(self, config, prefix=""):
# 		self.config = config
# 		self.prefix = prefix
# 	def __call__(self, f):
# 		self.f = f
# 		return self.wrap
# 	def wrap(self, *args, **kwargs):
# 		filename = hashname(self.config, prefix=self.prefix)
# 		try: # Load pre-computed data set if it exists
# 			with h5py.File(filename, "r") as file:
# 				data = Dict()
# 				for key in file:
# 					data[key] = file["lambda_0"][:]
# 				pass
# 		except: # Otherwise, pre-compute and save the results
# 			with h5py.File(filename, "w") as file:
# 				data = self.f(*args, **kwargs)
# 				file.create_dataset("lambda_0", data=lmbda0)
# 				pass
Example #3
0
    def download(self, shots=None, tags=None, sample_rate=None):
        """Download J-TEXT data
        @:param shots: shot list
        @:param tags: tag list
        @:param sr: sample rate for resample(kHz), if sr<sr0: do resample, else: do nothing
        :return: null
        """
        if shots is None or len(shots) == 0:
            raise ValueError('Param Error, ' 'shot list can\'t be Empty!')
        if tags is None or len(tags) == 0:
            raise ValueError('Param Error, ' 'tag list can\'t be Empty!')
        self.logger.info('Start download data')
        for shot in shots:
            try:
                c = connection.Connection('211.67.27.245')
                c.openTree('jtext', shot=shot)
                for tag in tags:
                    try:
                        if tag in self.reader.tags(shot):
                            self.logger.info(
                                'shot:{}, tag:{}, already exits.'.format(
                                    shot, tag))
                            continue
                        data = np.array(c.get(tag))
                        time = np.array(
                            c.get(r'DIM_OF(BUILD_PATH({}))'.format(tag)))
                        if data.shape[0] == 0 or time.shape[0] == 0:
                            self.logger.info(
                                'shot:{}, tag:{}, Shape of signal or dim_of(signal) is 0'
                            )
                        elif abs(data.shape[0] - time.shape[0]) > 10:
                            self.logger.info(
                                'shot:{}, tag:{}, Shape of signal and dim_of(signal) not equal'
                            )
                        else:
                            if 0 < data.shape[0] - time.shape[0] < 10:
                                data = data[:time.shape[0]]
                            if 0 < time.shape[0] - data.shape[0] < 10:
                                time = time[:data.shape[0]]
                            sr0 = int(len(data) /
                                      (time[-1] - time[0]) / 10) * 10

                            if sample_rate and sample_rate < sr0 / 100:
                                num = sample_rate * (int(
                                    round(time[-1] * 1000 - time[0] * 1000)))
                                data = signal.resample(data, num)
                                duration = (time[-1] - time[0]) / num
                                time = []
                                for i in range(num):
                                    time.append(i * duration)
                            result = self.exporter.save(shot, tag, data, time)
                            if result == 0:
                                self.logger.info(
                                    'shot:{}, tag:{}, Finish.'.format(
                                        shot, tag))
                            elif result == -1:
                                self.logger.info(
                                    'shot:{}, tag:{}, already exits.'.format(
                                        shot, tag))
                    except Exception as e:
                        self.logger.info(
                            'shot:{}, tag:{}, error occurs:{}.'.format(
                                shot, tag, e))
                c.closeTree('jtext', shot=shot)
                c.disconnect()
            except Exception as err:
                self.logger.info('shot {} is Empty, reason: {}\n{}'.format(
                    shot, err, traceback.format_exc()))
                if 'SS-W-SUCCESS' in '{}'.format(err):
                    self.logger.info('stop at shot {}\n{}'.format(
                        shot, traceback.format_exc()))
                    exit(-1)
Example #4
0
    r'\Polaris_Den_Rt07', r'\Polaris_Den_Rt08', r'\Polaris_Den_Rt09',
    r'\Polaris_Den_Rt10', r'\Polaris_Den_Rt11', r'\Polaris_Den_Rt12',
    r'\Polaris_Den_Rt13', r'\Polaris_Den_Rt14', r'\Polaris_Den_Rt15',
    r'\Polaris_Den_Rt16', r'\Polaris_Den_Rt17'
]
print(len(all_tags))

#shot_start = 1064014
shot_start = 1066648
shot_end = 1064034

exporter = Exporter(root_path=r'/nas/axk/data')
i = 0
while True:
    shot = shot_start - i
    if shot < shot_end:
        break
    print("第{}个".format(i + 1) + "    炮号:{}".format(shot))
    i += 1
    c = connection.Connection('211.67.27.245')
    try:
        c.openTree('jtext', shot=shot)
        for tag in all_tags:
            try:
                data, time = fetch_data(tag)
                exporter.save(data, time, shot, tag)
            except Exception as err:
                pass
        c.closeAllTrees()
    except Exception as err:
        print(err)