yt
yt copied to clipboard
Find output by its attribute
PR Summary
This provides the ability to quickly find the dataset that has the closest value to a given one (e.g. time or redshift). Example
import yt
# Load all RAMSES dataset in a folder - we assume here we have a cosmological simulation
ts = yt.load("/path/to/simulation/folder/output*")
# Get the snapshot that's as close as possible from z=2
ds = ts.get_by_redshift(2)
# Get the snapshot that's as close as possible from t=10Gyr after Big-Bang,
t = ts[0].quan(10, "Gyr")
ds = ts.get_by_time(t)
PR Checklist
- [x] New features are documented, with docstrings and narrative docs
- [x] Adds a test for any bugs fixed. Adds tests for new features.
Quick input:
- I think this is a great idea
- I'd prefer we avoid making it overly flexible: supporting the ability to search via arbitrary attributes may create unforeseen edge cases which will be impossible to test systematically. I think supporting search by time or redshift is sufficient for now, especially if it can be done in a way that doesn't involve typing the exact attribute names (IMO
current_time
is somewhat badly named, because its meaning seems excessively context-dependent)
Not sure I completely agree with @neutrinoceros about limiting the flexibility. The question the other day about flash datasets with particles would suggest there may be times when we don't know the attribute someone will be looking for.
Can you make it use "Price Is Right" rules? i.e., closest-without-going-over?
I am not sure I understand what you mean by "Price Is Right" rule. Anyways, in its current state, it is already possible to query a dataset by attribute, but the method is hidden (_get_by_attribute
), because “with great power comes great responsibility”.
Let me know what you think! I can always strip the leading _
to make it more user-facing, with an obvious comment in the docstring warning against misuses?
I mean, if I want the closet to z=1 but definitely on one side or the other, for instance. So having 0.99 take precedence over 1.01. (or even 0.95 over 1.001)
On Wed, Nov 1, 2023, 12:17 PM Corentin Cadiou @.***> wrote:
I am not sure I understand what you mean by "Price Is Right" rule. Anyways, in its current state, it is already possible to query a dataset by attribute, but the method is hidden (_get_by_attribute), because “with great power comes great responsibility”.
Let me know what you think! I can always strip the leading _ to make it more user-facing, with an obvious comment in the docstring warning against misuses?
— Reply to this email directly, view it on GitHub https://github.com/yt-project/yt/pull/4717#issuecomment-1789345795, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAVXOYJQUYAJMHRHRFESSDYCJ7ZHAVCNFSM6AAAAAA6S75QZ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBZGM2DKNZZGU . You are receiving this because you commented.Message ID: @.***>
Oh I see, yes, I'll implement a side
argument. To either get the output on the left or on the right!
I have nothing against that "the price is right rule", but I'd like to point out that left-to-right reading order isn't culturally neutral. I'd prefer that the interface be more inclusive.
@neutrinoceros I've implemented a "smaller", "larger" or "nearest" switch so that there is no ambiguity arising from left-to-right vs. right-to-left reading order. Thanks for pointing it out!
I think the new language is better. That being said, it's not necessarily true that RTL languages have different number line concepts:
https://math.stackexchange.com/questions/2618537/do-right-to-left-readers-also-reverse-mathematical-concepts-like-number-line
There's also some evidence that filmmaking conventions (such as progression from the left side of the screen to the right) are also commonly used outside of left-to-right languages.
I will say that with redshift the entire situation is odd because the numeric progression is reversed from temporal progression. And I did choose redshift as my example... So I guess this is on me!
@yt-fido test this please
@yt-fido test this please
@yt-fido test this please
pre-commit.ci autofix
@yt-fido test this please
@yt-fido Test this please
@yt-fido Test this please
@yt-fido Test this please