Giter Club home page Giter Club logo

least_asymmetry's People

Contributors

exowanderer avatar natelust avatar rychallener avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

least_asymmetry's Issues

"RuntimeError: Arrays must be square"

I am attempting to cycle through a stack of ~60k images, each of size 32x32 and find the center of the Spitzer PSF that is expected to be at the dead center of the image (pixel 15x15).

I use this code:

def fit_least_asymmetry_centering(imageCube, yguess, xguess, asym_rad):
    '''
        imageCube : nD-array (assume: (60k, 32, 32))
        yguess    : initial y center guess (assume: 15)
        xguess    : initial x center guess (assume: 15)
        asym_rad  : width of asymmetry subframe -- attempt to control corner cases (assume: 5)
    '''
    y,x = 0,1
    
    nFrames = imageCube.shape[0]
    
    yinds0, xinds0 = indices(imageCube[0].shape)
    
    nAsymParams = 2 # Xc, Yc
    centering_LeastAsym  = np.zeros((nFrames, nAsymParams))

    for kframe in tqdm(range(nFrames), total=nFrames):
        center_asym = least_asymmetry.actr(imageCube[kframe], [yguess, xguess], \
                           asym_rad=asym_rad, asym_size=5, maxcounts=2, method='gaus', \
                           half_pix=False, resize=False, weights=False)[0]

        try:
            centering_LeastAsym[kframe]  = center_asym[::-1]
        except:
            print('Least Asymmetry FAILED: Setting centering_LeastAsym[%s] to Initial Guess: [%s,%s]' % (kframe, yguess, xguess))
            centering_LeastAsym[kframe]  = np.arange([yguess, xguess])

    return centering_LeastAsym

from sklearn.externals import joblib
from pylab import *;ion()
import least_asymmetry

xgf_imageCube = joblib.load('xgf_image_cube_array.pickle') # input 60k x 32 x 32 nD-array

yguess   = 15
xguess   = 15
asym_rad = 5 # tried 8 before too

fit_least_asymmetry_centering(xgf_imageCube, yguess, xguess, asym_rad)

and receive this error RuntimeError: Arrays must be square (see Traceback below)

This error is generated from the make_asym.cc code on line 35.

I can process about 1% of the images before this error is triggered. So I assume that the first 600 images worked fine, but then they 601st image breaks.

I added std::cout << data.shape[0] << '\t' << data.shape[1]; to make_asym.cc on line 26 just to see what shape the python generator was sending to cpp code. The error is generated when the std::cout reads 17 0, which means that data.shape[1] == 0

I tracked the error this far, but cannot figure out why it's happening.

Any idea?

Right now, I bypass the whole problem with a simple "try/except" in the python script.

Traceback (most recent call last):
  File "least_asym_test.py", line 68, in <module>
    fit_least_asymmetry_centering(xgf_imageCube, 15,15,8)
  File "least_asym_test.py", line 51, in fit_least_asymmetry_centering
    half_pix=False, resize=False, weights=False)[0]
  File "/Users/jonathan/anaconda/lib/python3.6/site-packages/least_asymmetry-0.2-py3.6-macosx-10.7-x86_64.egg/least_asymmetry/asym.py", line 248, in actr
    asym = np.array(list(map(make_asym, views, lb_views, w_truth_dup)))
RuntimeError: Arrays must be square

Installing on Linux Server

When installing the code (master or devel) on a linux server -- with either python2 and python3:

uname -a ==> Linux server.name.edu 4.5.7-202.fc23.x86_64 #1 SMP Tue Jun 28 18:22:51 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

If I run python setup.py install, then I get the following output + error:

running install
running build
running build_ext
building 'make_asym' extension
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Iinclude -I/home/jdfraine/anaconda3/include/python3.5m -c make_asym.cc -o build/temp.linux-x86_64-3.5/make_asym.o -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.7
gcc: error: unrecognized command line option ‘-stdlib=libc++’
gcc: error: unrecognized command line option ‘-mmacosx-version-min=10.7’
error: command 'gcc' failed with exit status 1

The cause seems to be in the setup.py file where you list the cpp_args as

cpp_args = ['-std=c++11', '-stdlib=libc++', '-mmacosx-version-min=10.7']

and Linux has no idea what "-mmacosx-version-min=10.7" means. It apparently also does not know what "-stdlib=libc++" means.

If I take out both of those, then the cpp_args looks like this
cpp_args = ['-std=c++11']

and python setup.py install


  1. Am I missing something about my particular linux setup or should we indeed delete these cpp_args entries?

  2. Also, is this PR worthy?

`initmake_asym` flags an error -- fix provided in text

Hi Nate,

Your "make_asym.c" flags an error when I try to run "python setup.py install" or "./build.sh" (almost the same thing).

The error is:
"""
make_asym.c:139:3: error: void function 'initmake_asym' should not return a value [-Wreturn-type]
return Py_InitModule("make_asym", make_asym_methods);
"""

So I changed the function slightly to the following, and now it works without a hitch.

void
initmake_asym(void)
{
Py_InitModule("make_asym", make_asym_methods);
import_array();
}


I found this code snippet elsewhere that led me to the answer. It involved creating a macro for the condition "python3" vs "python2" situation. Therefore, the code that I am actually using looks like this:

# if PY_MAJOR_VERSION >= 3
# define NUMPY_IMPORT_ARRAY_RETURN_TYPE int
# else
# define NUMPY_IMPORT_ARRAY_RETURN_TYPE void
# endif

NUMPY_IMPORT_ARRAY_RETURN_TYPE
initmake_asym(void)
{
  Py_InitModule("make_asym", make_asym_methods);
  import_array();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.