-
Notifications
You must be signed in to change notification settings - Fork 257
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
Propose gifti data API #789
Comments
Hi @htwangtw, thanks for starting this conversation. I definitely agree that GIFTI could stand a friendlier API. I like I'll sketch out a bit more of what I'm thinking for this method (let me know what you think): class GiftiImage:
def agg_data(self, intent_code=None):
# Allow multiple intents to specify the order
# e.g., agg_data(('pointset', 'triangle')) ensures consistent order
if isinstance(intent_code, tuple):
return tuple(self.agg_data(intent_code=code) for code in intent_code)
# If only one type of data array, use that intent code.
# The idea here would be to allow agg_data() == agg_data('time_series') for time series files
darrays = self.darrays if intent_code is None else self.get_arrays_from_intent(intent_code)
all_data = tuple(da.data for da in darrays)
if intent_codes.niistring[intent_code] == "NIFTI_INTENT_TIME_SERIES":
return np.column_stack(all_data)
# Possibly other sensible things to do for other intents
return all_data And to think of some constructors: class GiftiImage:
@classmethod
def new_timeseries(cls, data):
...
@classmethod
def new_surface(cls, coordinates, triangle):
... These seem like the common file types I see in the wild, so even without a complete set of constructors for the officially listed file types, I think these would be a great improvement. I haven't thought through a I also wonder if it would make sense to add properties for querying whether an image looks like a canonical type, for example: @property
def is_surface(self):
return sorted(da.intent for da in darrays) == [intent_codes['pointset'], intent_codes['triangle']] |
Hey @effigies It makes sense to have a new name. I like It will help a lot to a property check for surface image. From my understanding, the workbench only reads [pointset, triangle] as the valid order. We can have a property check for both the constructor and the I am not certain if I should call it Another thought I had after thinking about the header class more is that not knowing the intent code is more a problem in file writing than reading. Perhaps we can focus on the |
I think this is true from a practical perspective, but we should be prepared to handle GIFTI files with arbitrarily many ill-advised
True, but nibabel will generally allow you to shoot yourself in the foot. I think we should make it easy to do the compatible thing, but if we go out of our way to make it hard to do silly things, there's a greater risk of disabling weird but legitimate uses.
I'd say let's have the constructor create the For
👍 Sounds good. Would you care to start a PR? |
I am working with HCP Conte69 surface data in resolution that's not supported in the official HCP pipeline. I mostly work with surf.gii, shape.gii, func.gii and cifti format. I will focus on gifti in this issue as cifti is a different file format. I found the nibabel gifti function a bit difficult to use for read/write the actual data. I would like to propose a new API aiming at more intuitive access to the data and save new output.
The most important information for me as a user is
Header-like method to access information of in point 1 to 3
The current
GiftiImage.print_summary()
method will give you all the metadata, but the only useful information is the metadata in the intents. Currently, you have to access the darrays first to get more useful information.GiftiImage.darrays[0].print_summary()
Some
I would like to have a header that can access the information about the intents.
Something like this:
Access data
For
.func.gii
and other metric files, it would be nice to concatenate all darrys for timeseires data throughget_data()
.For any kind of mesh (
surf.gii
), the method will return a tuple of corrdinates and faces.The preliminary idea is as follow:
Creating gifti files
Currently I replace the data in exisitng gifti files to create new image. It would be helpful if I can just pass a dictionary with the intents as keys and the data as the entry to create a new file.
For surface mesh (
surf.gii
), the user can pass a tuple of (coords, faces) and the funciton will translate that into data arrays. For timeseries data or other metric data (func.gii
,shape.gii
, and so on), we can have a np array of the size time x faces and parse each timepoint as a darray to fit the gifti format.The text was updated successfully, but these errors were encountered: