data-exchange / dxchange

data exchange supporting tomopy
http://dxchange.readthedocs.io
Other
34 stars 42 forks source link

exchange.read_aps13_bm value error #73

Closed bramgibs closed 6 years ago

bramgibs commented 6 years ago

@decarlof Not what is going on here. When I merge dxchange master into my fork, read_aps_13bm now returns "ValueError: too many values to unpack (expected 4)". I replicated this issue with the example doc as well.

I decided to debug with the rec_aps_13bm.py example. I took the netcdf4 method from exchange and placed into rec_aps_13bm as a separate method. If I change 'slc = (proj, sino)' to slc = None' in the method, it passes the data just fine. If I change that in dxchange.exchange and pass to dxchange, I receive the same ValueError. Thoughts?


!/usr/bin/env python

-- coding: utf-8 --

""" TomoPy example script to reconstruct the APS 13-BM tomography data as original netcdf files. To use, change fname to just the file name (e.g. 'sample[2].nc' would be 'sample'. Reconstructed dataset will be saved as float32 netcdf3. """ import glob import numpy as np import tomopy as tp import dxchange as dx import dxchange.reader as dxreader

from netCDF4 import Dataset

if name == 'main':

Set path (without file suffix) to the micro-CT data to reconstruct.

fname = 'Foram_B2.nc'   #example data of what I'm using, but does not work with any netcdf data currently.

'''
if slc in read_netcdf4 is set to None, data will returnself.
'''
def mf (fname):
    #creates list of filenames in directory sharing that same name scheme.
    files = glob.glob(fname[0:-5] + '*[1-3].nc')
    print(files)
    tomo = dxreader.read_netcdf4(files[1], 'array_data', slc=None)
    print('tomo', tomo.shape)
    flat1 = dxreader.read_netcdf4(files[0], 'array_data', slc=None)
    flat2 = dxreader.read_netcdf4(files[2], 'array_data', slc=None)
    flat = np.concatenate((flat1, flat2), axis = 0)
    del flat1, flat2
    print('flat', flat.shape)
    # mines the setup textfile for dark current.
    setup = glob.glob(fname[0:-5] + '*.setup')
    setup = open(setup[0], 'r')
    setup_data = setup.readlines()
    result = {}
    for line in setup_data:
        words = line[:-1].split(':',1)
        result[words[0].lower()] = words[1]

    print('result', result)
    dark = float(result['dark_current'])
    dark = flat*0+dark
    print('dark', dark.shape)
    theta = np.linspace(0.0, np.pi, tomo.shape[0])
    print('theta', theta.shape)
    return tomo, flat, dark, theta
## Import Data.

'''
Commented line is from example doc. This yields a ValueError even if you modify exchange to be as aboveself.
'''

proj, flat, dark, theta = dx.exchange.read_aps_13bm(fname, format = 'netcdf4')

'''
This works when calling above.
'''
proj, flat, dark, theta = mf(fname)

'''
Beneath here returns to example
'''
## Flat-field correction of raw data.
proj = tp.normalize(proj, flat = flat, dark = dark)

## Additional flat-field correction of raw data to negate need to mask.
proj = tp.normalize_bg(proj, air = 10)

## Set rotation center.
rot_center = tp.find_center_vo(proj)
print('Center of rotation: ', rot_center)

tp.minus_log(proj, out = proj)

# Reconstruct object using Gridrec algorith.
rec = tp.recon(proj, theta, center = rot_center, sinogram_order = False, algorithm = 'gridrec', filter_name = 'hann')
rec = tp.remove_nan(rec)
bramgibs commented 6 years ago

This problem was on my end. My python was pointing to the previous version of dxchange.

decarlof commented 6 years ago

@bramgibs I think your conda environment is still using the earlier dxchange version. Make sure you install the new dxchange. For this you can do a "python set up install" from within the dxchange home directory

decarlof commented 6 years ago

@bramgibs great!