def test_row_noheader_datalabels(): data = read_csv(data_dir.joinpath("row no header data labels.csv")) expected_array = unyt_array([0, 1, 2], "s") assert allclose_units(data.R0, expected_array) expected_array = unyt_array([3, 4, 5], "V/m") assert allclose_units(data.R1, expected_array) assert data.header == ""
def test_prefixes(): data = read_csv( data_dir.joinpath("column header data labels units prefixes.csv")) expected_array = unyt_array([0.0, 1.0e-6, 3.0e6], "s") assert allclose_units(data.Time, expected_array) expected_array = unyt_array([0.001, 2000.0, 4.0e9], "V") assert allclose_units(data.Voltage, expected_array)
def test_column_header_datalabels(): data = read_csv(data_dir.joinpath("column header data labels.csv")) expected_array = unyt_array(np.arange(10), "s") assert allclose_units(data.Time, expected_array) expected_array = unyt_array(np.arange(10)**2, "V") assert allclose_units(data.Voltage, expected_array) assert ( data.header == "Some data generated in LabVIEW\nPartioned into columns of Time, Voltage" )
def test_frequency_reim(): with TemporaryFile(mode="w+t", encoding="utf-8") as file: file.write("""Freq.\tV(out) 0.0e+0\t0.0e+0,0.0e+0 1.0e+0\t2.0e+0,3.0e+0""") file.seek(0) data = read_ltxt(file) assert data.header == "frequency\tV(out)" expected = unyt_array([0.0, 1.0], "Hz") assert allclose_units(data.frequency, expected) expected = unyt_array([0.0, 2.0], "V") assert allclose_units(data.V_out[0], expected) expected = unyt_array([0.0, 3.0], "V") assert allclose_units(data.V_out[1], expected)
def test_frequency_dBdeg(): with TemporaryFile(mode="w+t", encoding="utf-8") as file: file.write("""Freq.\tV(out) 0.0e+0\t(0.0e+0dB,0.0e+0°) 1.0e+0\t(-3.0e+0dB,-9.0e+1°)""") file.seek(0) data = read_ltxt(file) assert data.header == "frequency\tV(out)" expected = unyt_array([0.0, 1.0], "Hz") assert allclose_units(data.frequency, expected) expected = unyt_array([0.0, -3.0], "dB") assert allclose_units(data.V_out[0], expected) expected = unyt_array([0.0, -90.0], "degree") assert allclose_units(data.V_out[1], expected)
def test_vsource(): sim = read_ltraw(data_dir.joinpath("vsource.raw")) assert sim.variables == [ "time", "V(v1)", "V(v2)", "I(R2)", "I(R1)", "I(V2)", "I(V1)", ] assert allclose_units(sim.time[-1], unyt_array(0.001, "s")) assert allclose_units(sim["V(v1)"], unyt_array(4 * [1.0], "V")) assert allclose_units(sim["I(R1)"], unyt_array(4 * [2.0], "A")) assert allclose_units(sim["V(v2)"], unyt_array(4 * [3.0], "V")) assert allclose_units(sim["I(R2)"], unyt_array(4 * [4.0], "A"))
def test_column_noheader_datalabelsnounits(): data = read_csv( data_dir.joinpath("column no header data labels no units.csv")) assert isinstance(data, DataContainer) expected_array = unyt_array(np.arange(10), "dimensionless") assert allclose_units(data[0], expected_array) assert allclose_units(data["Time"], expected_array) assert allclose_units(data["Time - Plot 0"], expected_array) expected_array = unyt_array(np.arange(10)**2, "dimensionless") assert allclose_units(data[1], expected_array) assert allclose_units(data["Amplitude"], expected_array) assert allclose_units(data["Amplitude - Plot 0"], expected_array) assert data.header == "" assert data.legends == ["Plot 0", "Plot 0"]
def test_time(): with TemporaryFile(mode="w+t", encoding="utf-8") as file: file.write("time\tV(out)\n0.0e+0\t1.0e+0\n1.0e+0\t2.0e+0") file.seek(0) data = read_ltxt(file) assert data.header == "time\tV(out)" assert data.legends == ["time", "V(out)"] expected = unyt_array([0.0, 1.0], "s") assert allclose_units(data.time, expected) assert allclose_units(data["time"], expected) assert allclose_units(data[0], expected) expected = unyt_array([1.0, 2.0], "V") assert allclose_units(data.V_out, expected) assert allclose_units(data["V(out)"], expected) assert allclose_units(data[1], expected)
def test_vsourceac(): sim = read_ltraw(data_dir.joinpath("vsource ac.raw")) assert sim.variables == ["frequency", "V(v1)", "I(C1)", "I(V1)"] assert allclose_units(sim.frequency, unyt_array([1, 2, 3], "Hz")) assert allclose_units(sim["V(v1)"], unyt_array(3 * [complex(1, 0)], "V")) assert allclose_units(sim["I(C1)"].imag, unyt_array([1, 2, 3], "A"))
def test_column_noheader_datalabels(): data = read_csv(data_dir.joinpath("column no header data labels.csv")) expected_array = unyt_array(np.arange(10), "s") assert allclose_units(data["Time (s) - Plot 0"], expected_array) expected_array = unyt_array(np.arange(10)**3, "V") assert allclose_units(data["Amplitude (V) - Plot 1"], expected_array)
def test_singlecolumn_header_datalabel(): data = read_csv(data_dir.joinpath("single column header data label.csv")) expected_array = unyt_array(np.arange(10), "dimensionless") assert allclose_units(data.Time, expected_array) assert read_csv.header == "My data"
def test_singlerow_header_datalabel(): data = read_csv(data_dir.joinpath("single row header data label.csv")) assert allclose_units(data.Time, unyt_array(np.arange(10), "s")) assert data.header == "My data"
def test_extraspaceinname(): data = read_csv(data_dir.joinpath("extra space in name.csv")) assert allclose_units(data.I_bat[0], unyt_quantity(10e-6, "A"))
def test_file(): file = StringIO("My data\nTime (s),1p,2u,3k") data = read_csv(file) file.close() assert data.header == "My data" assert allclose_units(data.Time, unyt_array([1e-12, 2e-6, 3e3], "s"))