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

Targeted HDU/Data creation from Java data objects #488

Closed
attipaci opened this issue Sep 15, 2023 · 1 comment · Fixed by #491 or #525
Closed

Targeted HDU/Data creation from Java data objects #488

attipaci opened this issue Sep 15, 2023 · 1 comment · Fixed by #491 or #525
Assignees
Labels
enhancement A new feature and/or an improved capability
Milestone

Comments

@attipaci
Copy link
Collaborator

attipaci commented Sep 15, 2023

In 1.18 we have deprecated the [...]HDU.encapsulate(Object) methods, because they were not safe beyond internal use by the library itself. However, some similar methods could be useful for the targeted creation of specific types of HDUs from data, rather than using the automatic HDU wrapping by FitsFactory.makeHDU(). For example, a float[][] array may constitute data for a 2D image, or else it may be a column major table data (for either a BinaryTable or an AsciiTable). Fits.makeHDU() will always wrap that data into an ImageHDU, but sometimes that's not the intended way to represent such an array.

Here are some ideas for new methods:

  1. static <Data-subclass>.from(Object) methods to wrap data into particular Data subclasses, when it can be done in an unambiguous way. (BinaryTable has disambiguated fromRowMajor(Object[][]) and fromColumnMajor(Object[]) methods instead, and AsciiTable should as well...)
  2. Data.toHDU() method to then encapsulate a data object into a corresponding HDU, whose header is populated with the mandatory minimal description of the data automatically.

As such, you could have:

   float[][] values = ...

   ImageHDU im = ImageData.from(values).toHDU();
   BinaryTableHDU btab = BinaryTable.fromColumnMajor(values).toHDU();
@attipaci attipaci added the enhancement A new feature and/or an improved capability label Sep 15, 2023
@attipaci attipaci added this to the 1.19.0 milestone Sep 15, 2023
@attipaci attipaci self-assigned this Sep 15, 2023
@attipaci attipaci changed the title Reinstate static [...]HDU.encapsulate() methods with improved implementation Targeted HDU/Data creation from Java objects Sep 15, 2023
@attipaci attipaci changed the title Targeted HDU/Data creation from Java objects Targeted HDU/Data creation from Java data objects Sep 15, 2023
@attipaci
Copy link
Collaborator Author

It turns out that ImageData had no checks for what object it was created with. The constructor worked with no complaints with any Java object. This is clearly not a good idea. We should introduce checking that the object is a proper primitive numerical array (possibly multi-dimensional)...

@attipaci attipaci linked a pull request Dec 19, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature and/or an improved capability
Projects
None yet
1 participant