Beispiel #1
0
 def test_closed_wrong(self):
     data = SFDataFiles(FNAME_ALL)
     ch = data[CH_1D_NAME]
     for f in data.files:
         f.file.close()  # close only h5 file
         f.close()  # also create ClosedH5, which cannot read file info
     check_channel_closed(self, ch)
Beispiel #2
0
    def test_error(self):
        with self.assertRaises(NoMatchingFileError):
            SFDataFiles("does not exist")
        modfname = sfdata.sfdatafiles.__file__
        line = 56  #TODO this will break!
        prefix = f"{modfname}:{line}: UserWarning: "
        suffix = "\n  print_skip_warning(exc, quoted_fn)"
        broken_file = "fake_data/run_broken.SCALARS.h5"
        msg = f"Skipping \"{broken_file}\" since it caused OSError: Unable to open file (file signature not found)"
        msg = prefix + msg + suffix
        with self.assertRaises(NoMatchingFileError), self.assertPrintsError(
                msg):
            SFDataFiles(broken_file)

        msg = f"Skipping \"{broken_file}\" since it caused OSError: Unable to open file (file signature not found)"
        with self.assertRaises(NoMatchingFileError), self.assertWarns(msg):
            SFDataFiles(broken_file)
Beispiel #3
0
    def test_to_dataframe_dtypes(self):
        with SFDataFiles("fake_data/run_dtypes.SCALARS.h5") as data:
            methods = (data.to_dataframe, data.to_dataframe_accumulate,
                       data.to_dataframe_fill)
            for func in methods:
                df_objects = func(as_nullable=False)
                df_nullable = func(as_nullable=True)

                for ch in df_objects:
                    dtype = df_objects[ch].dtype
                    self.assertEqual(dtype, object)

                for ch in df_nullable:
                    ref = ch[0]  # first char in channel names is type code
                    dtype = df_nullable[ch].dtype
                    self.assertEqual(dtype.kind, ref)
                    str_dtype = str(dtype).lower()
                    char_dtype = str_dtype[0]
                    self.assertEqual(char_dtype, ref)
Beispiel #4
0
def main():
    import argparse

    parser = argparse.ArgumentParser(
        description="Print statistics for SwissFEL data files")

    parser.add_argument("filenames",
                        type=str,
                        nargs="+",
                        help="names of files to read, accepts wildcards")
    parser.add_argument(
        "-c",
        "--complete",
        action="store_true",
        help="also show channels that have the complete set of pulse IDs")

    clargs = parser.parse_args()

    from sfdata import SFDataFiles

    with SFDataFiles(*clargs.filenames) as data:
        data.print_stats(show_complete=clargs.complete)
Beispiel #5
0
 def test_read_column_vector(self):
     with SFDataFiles(FNAME_SCALARS) as data:
         self.assertAllEqual(data[CH_1D_COL_NAME].data, CH_1D_COL_DATA)
Beispiel #6
0
 def run(self, *args, **kwargs):
     with SFDataFiles(FNAME_ALL) as data:
         self.data = data
         self.ch = data[CH_ND_NAME]
         super().run(*args, **kwargs)
Beispiel #7
0
 def test_names_file_vs_files(self):
     with SFDataFile(FNAME_SCALARS) as data1, SFDataFiles(
             FNAME_SCALARS) as data2:
         self.assertEqual(data1.names, data2.names)
Beispiel #8
0
 def run(self, *args, **kwargs):
     with SFDataFiles(FNAME_ALL) as data:
         self.data = data[
             data.names]  # subset with all names to convert to plain SFData
         super().run(*args, **kwargs)
Beispiel #9
0
 def test_closed_twice(self):
     data = SFDataFiles(FNAME_ALL)
     ch = data[CH_1D_NAME]
     data.close()
     data.close()
     check_channel_closed(self, ch)
Beispiel #10
0
 def test_closed1(self):
     with SFDataFiles(FNAME_ALL) as data:
         ch = data[CH_1D_NAME]
     check_channel_closed(self, ch)
#!/usr/bin/env python3

from sfdata import SFDataFiles


with SFDataFiles("run_000041.BSREAD.h5") as data:
    print(data)
    print("#entries:", len(data))
#    print(data.names)

    ch = data["SLAAR11-LTIM01-EVR0:DUMMY_PV1_NBS"]
    print(ch)
    print(ch.pids)
    print(ch.data)

    subset = data["SLAAR11-LTIM01-EVR0:DUMMY_PV1_NBS", "SLAAR11-LTIM01-EVR0:DUMMY_PV2_NBS", "SAR-CVME-TIFALL5:EvtSet"]
    print(subset)

    df = subset.to_dataframe()
#    print(df)