Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak include/exclude args to be lists of ints as needed #184

Closed
wants to merge 1 commit into from

Conversation

jeanconn
Copy link
Contributor

@jeanconn jeanconn commented Dec 6, 2018

Tweak include/exclude args to be lists of ints as needed

The include_, exclude_ kwargs seems to end up as either empty numpy arrays, numpy arrays of floats, or single numpy ints when passed to Python from Matlab with pyexec. I think none of those work in get_aca_catalog. This PR is intended to cast all of them to lists of ints.

@jeanconn
Copy link
Contributor Author

jeanconn commented Dec 6, 2018

@taldcroft Should be able to come up with something nicer that works with the attribute syntax. I just didn't see a good way to deal with this on the Matlab side, and also did not want to write Python subroutines to munge the kwargs as lambda functions in the Matlab.

for name, val in kwargs.items():
if name in self.allowed_kwargs:
setattr(self, name, val)
else:
raise ValueError(f'unexpected keyword argument "{name}"')


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops.

@taldcroft
Copy link
Member

I think you can do the transform in one line:

In [3]: np.atleast_1d([1.]).astype(int)
Out[3]: array([1])

In [4]: np.atleast_1d([]).astype(int)
Out[4]: array([], dtype=int64)

In [5]: np.atleast_1d(1).astype(int)
Out[5]: array([1])

@taldcroft
Copy link
Member

And then make a subclass for those attributes:

class Int1dMetaAttribute(MetaAttribute):
    def __set__(self, instance, value):
        instance.meta[self.name] = np.atleast_1d(value).astype(int)

@jeanconn
Copy link
Contributor Author

jeanconn commented Dec 7, 2018

Yes, np.atleast_1d seems to help just fine. Per my comment in the email thread, I think this can just go in the updated Matlab file and doesn't need a proseco edit.

@taldcroft
Copy link
Member

Er. I'd prefer to make the Python accept different args in a generalized way rather than hacking the Matlab Python calls. I'm guessing you are going to end up with a lot of repetition in the Matlab/Python calls?

@jeanconn
Copy link
Contributor Author

jeanconn commented Dec 7, 2018

OK. I didn't see much value added on the Python side and was just trying to avoid yet another release. On the matlab side it was just looking like:

get_aca_catalog(...
include_ids_acq = np.atleast_1d($include_ids_acq), include_ids_guide=np.atleast_1d($include_ids_guide), ..

So yeah, you repeat np.atleast_1d 5 times.

@taldcroft
Copy link
Member

That's not fixing the type to int. I suspect that getting floats will break things, though maybe you've already tested?

@jeanconn
Copy link
Contributor Author

jeanconn commented Dec 7, 2018

Yes, I was live testing the np.atleast_1d idea. I think the "or floats" was a mistake on my part in reading a stack trace and they were still coming through as numpy ints.

@jeanconn
Copy link
Contributor Author

jeanconn commented Dec 7, 2018

Though now failing in a different area.

In [16]: %debug
> /proj/sot/ska/jeanproj/git/proseco/proseco/acq.py(498)select_best_p_acqs()
    496                 if accepted:
    497                     acq_indices.append(acq_idx)
--> 498                     box_sizes.append(box_size)
    499 
    500                 if len(acq_indices) == self.n_acq:

ipdb> box_size
160
ipdb> box_sizes
array([], dtype=float64)

So temporarily fixing on Matlab side with

get_aca_catalog(...
include_ids_acq = list(np.atleast_1d($include_ids_acq)), include_ids_guide=list(np.atleast_1d($include_ids_guide)), ..

@jeanconn
Copy link
Contributor Author

jeanconn commented Dec 7, 2018

Right, so do we care about this for 4.3 or is the matlab sufficient

            'include_ids_acq=list(np.atleast_1d($include_ids_acq)),'...
            'exclude_ids_acq=list(np.atleast_1d($exclude_ids_acq)),'...
            'include_halfws_acq=list(np.atleast_1d($include_halfws_acq)),'...
            'include_ids_guide=list(np.atleast_1d($include_ids_guide)), '...
            'exclude_ids_guide=list(np.atleast_1d($exclude_ids_guide)))'];

@taldcroft
Copy link
Member

See #187.

@taldcroft
Copy link
Member

If we get in a time crunch then the above makes me unhappy but works.

@jeanconn
Copy link
Contributor Author

jeanconn commented Dec 7, 2018

Define "time crunch".

@jeanconn jeanconn closed this Dec 7, 2018
@taldcroft taldcroft deleted the include_exclude_api_tweak branch December 9, 2018 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants