def testExportChronogram(self): """Try simple chronogram export""" size = (150, ) dtype = numpy.uint16 md = { model.MD_TIME_LIST: numpy.linspace(536e-9, 650e-9, size[0]).tolist(), model.MD_ACQ_TYPE: model.MD_AT_SPECTRUM, model.MD_DIMS: "T" } data = model.DataArray(numpy.zeros(size, dtype), md) data += 56 # export csv.export(FILENAME, data) # check it's here st = os.stat(FILENAME) # this test also that the file is created self.assertGreater(st.st_size, 150) raised = False try: pycsv.reader(open(FILENAME, 'rb')) except IOError: raised = True self.assertFalse(raised, 'Failed to read csv file')
def testExportAR(self): """Try simple AR export""" size = (101, 401) dtype = numpy.float metadata = { model.MD_DESCRIPTION: "Angle-resolved", model.MD_ACQ_TYPE: model.MD_AT_AR } data = model.DataArray(numpy.zeros(size, dtype), metadata) data += 26.1561 data[1:, 0] = numpy.linspace(0, math.pi / 2, data.shape[0] - 1) data[0, 1:] = numpy.linspace(0, math.pi * 2, data.shape[1] - 1) # export csv.export(FILENAME, data) # check it's here st = os.stat(FILENAME) # this test also that the file is created self.assertGreater(st.st_size, 100) raised = False try: pycsv.reader(open(FILENAME, 'rb')) except IOError: raised = True self.assertFalse(raised, 'Failed to read csv file')
def export_ar_to_csv(fn, background=None): """ fn (str): full path to the AR data file background (DataArray or None): background data to subtract """ das = dataio.open_acquisition(fn) if not das: # No such file or file doesn't contain data return streams = dataio.data_to_static_streams(das) # Remove the extension of the filename, to extend the name with .csv fn_base = dataio.splitext(fn)[0] ar_streams = [s for s in streams if isinstance(s, ARStream)] for s in ar_streams: try: s.background.value = background except Exception as ex: logging.error("Failed to use background data: %s", ex) ar_proj = stream.ARRawProjection(s) # Export every position separately for p in s.point.choices: if p == (None, None): # Special "non-selected point" => not interesting continue s.point.value = p # Project to "raw" = Theta vs phi array exdata = img.ar_to_export_data([ar_proj], raw=True) # Pick a good name fn_csv = fn_base if len(ar_streams) > 1: # Add the name of the stream fn_csv += "-" + s.name.value if len(s.point.choices) > 2: # More than one point in the stream => add position (in µm) fn_csv += f"-{p[0] * 1e6}-{p[1] * 1e6}" fn_csv += ".csv" # Save into a CSV file logging.info("Exporting point %s to %s", p, fn_csv) csv.export(fn_csv, exdata)
def testExportSpectrumNoWL(self): """Try simple spectrum export""" size = (10,) dtype = numpy.uint16 data = model.DataArray(numpy.zeros(size, dtype)) data += 56486 # export csv.export(FILENAME, data) # check it's here st = os.stat(FILENAME) # this test also that the file is created self.assertGreater(st.st_size, 10) raised = False try: pycsv.reader(open(FILENAME, 'rb')) except IOError: raised = True self.assertFalse(raised, 'Failed to read csv file')
def testExportSpectrumNoWL(self): """Try simple spectrum export""" size = (10, ) dtype = numpy.uint16 md = {model.MD_ACQ_TYPE: model.MD_AT_SPECTRUM, model.MD_DIMS: "C"} data = model.DataArray(numpy.zeros(size, dtype), md) data += 56486 # export csv.export(FILENAME, data) # check it's here st = os.stat(FILENAME) # this test also that the file is created self.assertGreater(st.st_size, 10) raised = False try: pycsv.reader(open(FILENAME, 'rb')) except IOError: raised = True self.assertFalse(raised, 'Failed to read csv file')
def testExportSpectrum(self): """Try simple spectrum export""" size = (150,) dtype = numpy.uint16 md = {model.MD_WL_LIST: numpy.linspace(536e-9, 650e-9, size[0]).tolist()} data = model.DataArray(numpy.zeros(size, dtype), md) data += 56 # export csv.export(FILENAME, data) # check it's here st = os.stat(FILENAME) # this test also that the file is created self.assertGreater(st.st_size, 150) raised = False try: pycsv.reader(open(FILENAME, 'rb')) except IOError: raised = True self.assertFalse(raised, 'Failed to read csv file')
def testExportSpectrumLineNoWL(self): """Try simple spectrum-line export""" size = (1340, 6) dtype = numpy.float md = {model.MD_PIXEL_SIZE: (None, 4.2e-06), model.MD_ACQ_TYPE: model.MD_AT_SPECTRUM} data = model.DataArray(numpy.zeros(size, dtype), md) # export csv.export(FILENAME, data) # check it's here st = os.stat(FILENAME) # this test also that the file is created self.assertGreater(st.st_size, 5) raised = False try: pycsv.reader(open(FILENAME, 'rb')) except IOError: raised = True self.assertFalse(raised, 'Failed to read csv file')
def testExportAR(self): """Try simple AR export""" size = (90, 360) dtype = numpy.float metadata = { model.MD_DESCRIPTION: "Angle-resolved", model.MD_ACQ_TYPE: model.MD_AT_AR } data = model.DataArray(numpy.zeros(size, dtype), metadata) data[...] = 26.1561 data[10, 10] = 10 # export csv.export(FILENAME, data) # check it's here st = os.stat(FILENAME) # this test also that the file is created self.assertGreater(st.st_size, 100) raised = False try: pycsv.reader(open(FILENAME, 'rb')) except IOError: raised = True self.assertFalse(raised, 'Failed to read csv file') # test intensity value is at correct position file = pycsv.reader(open(FILENAME, 'r')) a = numpy.zeros((91, 361)) index = 0 for line in file: if index == 0: a[index] = 0.0 else: a[index] = line index += 1 # test intensity for same px as defined above is also different when reading back # (+1 as we add a line for theta/phi MD to the array when exporting) self.assertEqual(a[11][11], 10)
def testExportAR(self): """Try simple AR export""" size = (101, 401) dtype = numpy.float metadata = {model.MD_DESCRIPTION: "Angle-resolved"} data = model.DataArray(numpy.zeros(size, dtype), metadata) data += 26.1561 data[1:, 0] = numpy.linspace(0, math.pi / 2, data.shape[0] - 1) data[0, 1:] = numpy.linspace(0, math.pi * 2, data.shape[1] - 1) # export csv.export(FILENAME, data) # check it's here st = os.stat(FILENAME) # this test also that the file is created self.assertGreater(st.st_size, 100) raised = False try: pycsv.reader(open(FILENAME, 'rb')) except IOError: raised = True self.assertFalse(raised, 'Failed to read csv file')
def testExportSpectrumLineNoWL(self): """Try simple spectrum-line export""" size = (1340, 6) dtype = numpy.float md = { model.MD_PIXEL_SIZE: (None, 4.2e-06), model.MD_ACQ_TYPE: model.MD_AT_SPECTRUM } data = model.DataArray(numpy.zeros(size, dtype), md) # export csv.export(FILENAME, data) # check it's here st = os.stat(FILENAME) # this test also that the file is created self.assertGreater(st.st_size, 5) raised = False try: pycsv.reader(open(FILENAME, 'rb')) except IOError: raised = True self.assertFalse(raised, 'Failed to read csv file')
def testExportAR(self): """Try simple AR export""" size = (90, 360) dtype = numpy.float metadata = {model.MD_DESCRIPTION: "Angle-resolved", model.MD_ACQ_TYPE: model.MD_AT_AR} data = model.DataArray(numpy.zeros(size, dtype), metadata) data[...] = 26.1561 data[10, 10] = 10 # export csv.export(FILENAME, data) # check it's here st = os.stat(FILENAME) # this test also that the file is created self.assertGreater(st.st_size, 100) raised = False try: pycsv.reader(open(FILENAME, 'rb')) except IOError: raised = True self.assertFalse(raised, 'Failed to read csv file') # test intensity value is at correct position file = pycsv.reader(open(FILENAME, 'rb')) a = numpy.zeros((91, 361)) index = 0 for line in file: if index == 0: a[index] = 0.0 else: a[index] = line index += 1 # test intensity for same px as defined above is also different when reading back # (+1 as we add a line for theta/phi MD to the array when exporting) self.assertEqual(a[11][11], 10)