-
Notifications
You must be signed in to change notification settings - Fork 106
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
hsm code updates to use Image class / eliminate cfitsio / make python interface #38
Comments
I hope to work on this issue this week, now that I have some more experience with various things and have a better idea what we want. Here's what I'm thinking (opinions would be appreciated from anyone, but I am particularly pinging @barnabytprowe , @TallJimbo , @rmjarvis ): If you look at examples/MeasMoments.cpp and examples/MeasShape.cpp, you will see that most of the code in those files is (a) handling of FITS file read-in and (b) preparing various inputs (e.g., allocating images and reading them in) before calling a single key function that does all the work -- So one way to proceed would be as follows: I thought of other ways to go, but this seems like the simplest / cleanest in terms of allowing easy access to the HSM functionality from python without having to rewrite large amounts of C++. It does mean more overhead due to all inputs having to be manipulated into RectImages and ObjectData each time the program is run. Thoughts? |
This seems like a good overall plan to me. I don't think we need to worry about the extra overhead, and I agree that it would be a good idea not to spend a lot of time modifying the core implementation. |
The only tweak I would make to this proposal is the return value of the functions. A bare array of numbers isn't very easy to use. e.g. One of them has e1,e2 at positions 4,5 and the other at 1,2. So I would suggest returning a simple structure that can be queried with things like But I do agree that a wrapper is better than going into the guts to change the underlying implementation. The surface layer shouldn't be too much overhead. And in addition to the reasons you gave, it lowers the chance that you will introduce a bug in the conversion. |
+1 on returning a struct. In fact, it might make sense to return a |
Yes, I was mostly worried about bugs that might be introduced in such a conversion! Rewrite = not too time-consuming, testing and fixing bugs = potentially an infinite amount of time. :) You make a good point about return values. Would it make sense to define a class that carries around the information about objects, which is defined in C++ and wrapped for python access? I would have to think a little more about the design of such a class - it has the potential to be complicated since there are moments and shapes of the observed object, and then there are PSF-corrected quantities. |
Oops, I didn't see Jim's comment when I wrote mine. |
I think it makes sense to have a single class that has all the stuff that you want to return with descriptively named elements. But you could have |
The plan sounds very sensible - I agree with Mike that I don't think an extra Image > RectImage / ObjectData conversion overhead will be crippling. The a container for two galsim::Shear objects sounds like a neat, minimal-extra-code solution to a handy output structure for HSM. |
(& Mike makes a good point about the names being descriptive... They could still both be |
Yes, sounds like a plan! Thanks for the useful discussion. |
A question: Currently, the functions find_ellipmom_2 and general_shear_estimator require the specification of some arguments that we probably don't want the general python user to have to specify... usually a default would suffice. I need to figure out how to handle this for the C++ functions that call them and that I will be wrapping for access via python. One option would be to overload those C++ functions, with versions that specify all parameters and others that specify a bare minimum (the Images only). Is there some other option that would be preferable? In case anyone is wondering what I mean, I just pushed a branch #38 that has modifications to include/galsim/hsm/Psfcorr.h which show a rather simple form for these functions. I would be overloading with versions that take additional arguments beyond what is already there. Also, that file contains the definition for the class that we discussed for the outputs of these HSM functions. |
If you can specify the defaults in the form of default arguments, that's slightly easier to wrap for Python (and it feels more natural, because pure-Python functions don't support overloading). But if you need to have multiple overloads of the same function, that's also quite doable. A side note: You probably want to use either |
I think what you want is to use default arguments. e.g. If there will be a lot of arguments that people might want to specify, it might be cleaner to have a struct for the input parameters as well with the defaults all set in the constructor, so people would only redefine the ones that they want to change. |
Mike's reply made me think of one more thing: if you use default arguments in C++, we can turn them into Python kwargs at the wrapper stage, so from Python you will be able to pass them in any order and specify later ones while leaving earlier ones defaulted. |
Wow, you guys are quick, thanks!
|
Some other (minor) style suggestions.
|
Here's an example of C++ default arguments turned into Python kwargs (downside is that you have to repeat the defaults and keep them in sync): C++ Python Wrappers: |
|
In that case, I would recommend moving the defaults into a constructor. I think having them at the declaration line will fail on at least some compilers. Oh, and I think we've been using lower-case for variables and using underscores between words rather than camelCase. Although looking through the code, it seems we haven't been very consistent about this either way. We should probably decide on a style for this and try to stick to it. e.g. The constructor to OpticalPsf has We have been pretty good I think at sticking to upper-case CamelCase for class names and lower-case camelCase for functions and methods. Just the style for variables seems to be a bit of a mix. |
which I think is okay, isn't it, or perhaps the functions would be better as findAdaptiveMom and estimateShearHSM? (I mean, ignoring the modifications I said I would make - I'm only asking about naming conventions for functions and classes vs. for the args) Were you concerned about the members of HSMShapeData, which are
?? I confess that here I was following one particular example, and I see that we're quite inconsistent throughout... not that we're going to go through and change tons of existing code, but I agree we should choose a convention for code that gets written from now onwards. |
I was referring to the members of HSMShapeData. For free functions, I tend to prefer the initial capital as you had it, which is different from the LSST standard we were nominally following (poorly apparently). So how should we decide a style to follow? Vote? You and Barney talk and dictate something? I'll just put out my own preference as a straw man for discussion:
|
Ooops yes, that is bad of me Mike; I think I do like the underscore at the Python level, I'll change those... On 24 Apr 2012, at 11:14, Rachel Mandelbaum wrote:
Barnaby Rowe Jet Propulsion Laboratory Department of Physics & Astronomy |
+1 for Mike's proposal, Rachel if you agree shall we put that in credo.txt? On 24 Apr 2012, at 11:35, Mike Jarvis wrote:
Barnaby Rowe Jet Propulsion Laboratory Department of Physics & Astronomy |
Hmmm, you're right, I wasn't distinguishing between free vs. member functions. In that case, I could leave the functions and args the same, and just change the members of HSMShapeData. I just checked credo.txt and unless I've missed something, we are rather vague on this where we should be explicit. Your proposal seems okay to me, but let's get some input from others. And we should keep in mind the rule we already agreed on, to violate camelCase (or CamelCase) for abbreviations like PSF, CCD, etc. (so Psfcorr.* should be PSFCorr.*, will fix on this branch). To add to your list above, file names should be CamelCase for consistency with SBProfile conventions... I think this is something that we did already agree on explicitly, but it's good to have everything listed all together. |
Sorry, Barney, I didn't see your message before I posted mine. I can make that change in credo.txt on master in a few minutes... |
…nts code, to be filled in ASAP (#38)
#38 - python interface for moments and shape measurement code
Now that we have our new Image class (#12), we will want to make a python interface to the hsm code using the Image class, and eliminate the cfitsio dependency from GalSim entirely.
I've tentatively assigned this to myself, as I am the one who knows the hsm code best, but I have a lot to learn about making a python interface and will probably be pinging Barney and Jim for help. Should be a good learning experience (and won't hold up our achieving the first project milestone if I'm slow).
The text was updated successfully, but these errors were encountered: