-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add albedo correction #161
base: main
Are you sure you want to change the base?
Conversation
I have found IDL code used in 2005 to generate Green Matrices for OSPEX and put it on github: |
I have added the changes we made to the albedo model during the workshop. For now we made the model "unitless" until we resolve the astropy model unit problems with SRM. All the units-related lines are commented so it can be easily updated. |
b9217db
to
6ee7756
Compare
A very minor edit to the evaluate step in the Albedo class which allows unit handling to work with Scipy fitting. This was previously not working at the point of calling get_albedo_matrix, simply adding in self.theta here solves the problem.
The model can now be applied to a spectrum which can be fit by the astropy fitting routines with units handled correctly. However there is still an issue with fitting theta as a free parameter, practically this isnt an issue, however should in principle work.
The code has been restrcutred such that Astropy fitting is now fully functional and all required funtionality is contained within the class rather than externally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the main reason to separate things is to make them testable with these change it will be harder to test so I wonder are they necessary?
@lru_cache | ||
def _get_green_matrix(self, theta: float) -> RegularGridInterpolator: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why move onto the object?
|
||
self.energy_edges = kwargs.pop("energy_edges") | ||
|
||
self._get_green_matrix(theta) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think this is needed as already cached by the decorators
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can remove the decorator then? referencing in the init step seems to be more inline with the Astropy API. From looking over the Astropy API all model classes have their reliant functions handled internally, the previous method was encountering issues with fitting theta as a free parameter, I think at least in part because of the functions being defined outside of the class, although I could be wrong about that. Either way, this version solves that issue and fully functions with the Astropy fitters, and seemingly produces correct results, also it is more in line with the Astropy model class API. I guess it comes back to the main question of to what degree we want to align ourselves with the API
In OSPEX/drm_correct_albedo.pro, the anisotropy parameter is “a coefficient showing the ratio of the flux in observer direction to the flux downwards." A smaller value means more of an effect from albedo. A value of 1000 means very little effect. if anisotropy=1 (default) the source is isotropic. However, in the paper, the coefficient α that accounts for anisotropy of the source in the Eddington approximation – that is, "distinct but constant specific intensities in the downward and in the upward hemispheres, in the ratio α” i.e. the anisotropy described as the reciprocal of the anisotropy parameter in the OSPEX. Should the description state the definition of "α" was assumed as in OSPEX? class Albedo(FittableModel): |
I have reverted the code back to its state before the previous commit with some small edits, the functions are now defined outside of the class and the class is used a wrapper, therefore the tests should now work, is it ok for me to push these changes? The albedo model is now functional with astropy fitters. |
Go for it, sounds good |
The functions have been moved out of the class which now functions as a wrapper. The lru_cache method is applied to both the _calculate_albedo_matrix and _get_green_matrix functions, the outputs when fitting are identical with or without the decorators, and the code runs much quicker this way.
if hasattr(theta, "unit"): | ||
theta = Quantity(theta.value,theta.unit) | ||
else: | ||
theta = theta*u.deg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if hasattr(theta, "unit"): | |
theta = Quantity(theta.value,theta.unit) | |
else: | |
theta = theta*u.deg | |
if not isinstance(theta, Quantity) | |
theta = theta*u.deg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey it looks like y'all are making good progress on this, i am gonna put a couple style suggestions along these lines if that's ok. feel free to reject them if you want but yea
Fixes errors in the test process. Co-authored-by: Shane Maloney <[email protected]>
PR Description
A a function to read in precomputed greens table and return spectrum with albedo correction, would close #128
spec | albedo
(still waiting on proper units support in astroy for this work Should the model composition operator,|
, support units changing astropy/astropy#17302)Recreated Fig 2 upper from the paper