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

Add basic Affine Grid Coordinates to xarray Datasets #35

Merged
merged 6 commits into from
Apr 15, 2024

Conversation

sjperkins
Copy link
Member

Closes #27

This PR adds basic Affine coordinates to xarray Datasets. This is similar to the galsim's AffineTransform.

This linear transformation only approximates more complex WCS coordinate systems, but may be useful for developers to reason about their data cubes

xarrayfits/grid.py Outdated Show resolved Hide resolved
elif result := self.ctype[dim]:
return result
else:
return None
Copy link
Member Author

@sjperkins sjperkins Apr 5, 2024

Choose a reason for hiding this comment

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

Tries to find the axis CNAME first, else falls back to CTYPE

tests/test_xarrayfits.py Outdated Show resolved Hide resolved
Copy link

@landmanbester landmanbester left a comment

Choose a reason for hiding this comment

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

Couple of niggles but I don't see any showstoppers here. Happy to approve but I would also like to close the loop with ratt-ru/tigger#146 so let's keep fits viewers in mind as well

@sjperkins
Copy link
Member Author

Couple of niggles but I don't see any showstoppers here. Happy to approve but I would also like to close the loop with ratt-ru/tigger#146 so let's keep fits viewers in mind as well

We could open a separate issue regarding Tigger integration?

@landmanbester
Copy link

Couple of niggles but I don't see any showstoppers here. Happy to approve but I would also like to close the loop with ratt-ru/tigger#146 so let's keep fits viewers in mind as well

We could open a separate issue regarding Tigger integration?

Yeah, totally separate just wanted to link it

Comment on lines +181 to +218
def test_multiple_unnamed_hdus(multiple_hdu_file):
"""Test hdu requests with hdu indexes"""
(ds,) = xds_from_fits(multiple_hdu_file, hdus=0)
assert len(ds.data_vars) == 1
assert ds.hdu.shape == (10, 10)
assert ds.hdu.dims == ("X", "Y")

(ds,) = xds_from_fits(multiple_hdu_file, hdus=[0, 2])
assert len(ds.data_vars) == 2

assert ds.hdu0.shape == (10, 10)
assert ds.hdu0.dims == ("hdu0-X", "hdu0-Y")

assert ds.hdu2.shape == (30, 40, 50)
assert ds.hdu2.dims == ("hdu2-X", "hdu2-Y", "hdu2-FREQ")


def test_multiple_named_hdus(multiple_hdu_file):
"""Test hdu requests with named hdus"""
(ds,) = xds_from_fits(multiple_hdu_file, hdus={0: "beam"})
assert ds.beam.dims == ("X", "Y")
assert ds.beam.shape == (10, 10)

(ds,) = xds_from_fits(multiple_hdu_file, hdus=["beam"])
assert ds.beam.dims == ("X", "Y")
assert ds.beam.shape == (10, 10)

(ds,) = xds_from_fits(multiple_hdu_file, hdus={0: "beam", 2: "3C147"})
assert ds.beam.dims == ("beam-X", "beam-Y")
assert ds.beam.shape == (10, 10)
assert ds["3C147"].dims == ("3C147-X", "3C147-Y", "3C147-FREQ")
assert ds["3C147"].shape == (30, 40, 50)

(ds,) = xds_from_fits(multiple_hdu_file, hdus=["beam", "3C147"])
assert ds.beam.dims == ("beam-X", "beam-Y")
assert ds.beam.shape == (10, 10)
assert ds["3C147"].dims == ("3C147-X", "3C147-Y", "3C147-FREQ")
assert ds["3C147"].shape == (10, 20, 30)
Copy link
Member Author

Choose a reason for hiding this comment

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

@o-smirnov @landmanbester Sorry, I didn't highlight everything in my previous comment. This illustrates the naming schemas for hdus and dimensions.

Copy link

@o-smirnov o-smirnov left a comment

Choose a reason for hiding this comment

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

Excellent, all looks very neat and friendly now!

@sjperkins
Copy link
Member Author

Note that the signature for xds_from_fits changes:

  • prefix is no longer a valid argument
  • It's folded into the hdus argument.

@o-smirnov I think you're the only one impacted by this.

I should create some proper documentation for this.

@sjperkins sjperkins merged commit ca06461 into master Apr 15, 2024
7 checks passed
@sjperkins sjperkins deleted the xarray-coords branch April 15, 2024 10:28
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.

propagate CNAMEx into axis names
3 participants