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

Expanding "operation" keyword #119

Merged
merged 6 commits into from
Nov 23, 2023

Conversation

Adnan-Ali-Ahmad
Copy link
Collaborator

This allows the user to call any numpy operation when performing thick maps. It is particularly useful in star formation when doing column densities of cells belonging to the disk only, as it requires us to call nansum instead of sum since the non-disk cells are masked. Below is an example of this:

mach_1p0_column_density_vis_01858

@@ -338,10 +338,10 @@ def map(*layers,
ndim=ndim)

# Apply operation along depth
binned = getattr(binned, operation)(axis=1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm starting to think that operation shouldn't be a string but just a callable. Then you would pass whatever function you want, it could even be a custom function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How would the map function handle units in that case?

Copy link
Collaborator

@nvaytet nvaytet Nov 17, 2023

Choose a reason for hiding this comment

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

I don't think we are handling the units well at the moment, so maybe we can come up with a better idea?
We are only doing something special if the operation is a sum.
See also #72

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should just have a special top-level function for computing column densities, instead of relying on a special case of the thick map.

It would just be a thin wrapper around the map function, but this would make what happens to the units less ambiguous/hidden?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can give it a go in the coming weeks.
I'll close this PR and open a new one if that's okay with you.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alternatively, we can always merge this one for now and improve the mechanism later, since this is not breaking anything, just making you able to use nansum if you wish.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, let's do that in the meantime.


# Handle thick maps
if thick and (operation == "sum"):
if thick and ((operation == "sum") or (operation == "nansum")):
Copy link
Collaborator

Choose a reason for hiding this comment

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

You will need to update the docstring to the map function though.

not ``None``. Possible values are ``'sum'``, ``'mean'``, ``'min'``, and
``'max'``. Default is ``'sum'``.
not ``None``. Possible values are ``'sum'``, ``'nansum'``,
``'mean'``, ``'min'``, and ``'max'``. Default is ``'sum'``.
Copy link
Collaborator

Choose a reason for hiding this comment

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

You may want to add nanmean, nanmin and nanmax while you're at it?

Copy link
Collaborator

@nvaytet nvaytet left a comment

Choose a reason for hiding this comment

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

Ideally, we would have some unit tests to check that all the new functions don't produce an error..., but that is for later.

@nvaytet nvaytet merged commit d04b36d into osyris-project:main Nov 23, 2023
1 check passed
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