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

Creation of IRISMapCubeSequence class #83

Merged
merged 8 commits into from
May 16, 2018

Conversation

BaptistePellorceAstro
Copy link
Contributor

@BaptistePellorceAstro BaptistePellorceAstro commented May 7, 2018

Here the creation of the IRISMapCubeSequence class. See #72 for more informations.

"""
def __init__(self, data_list, meta=None, common_axis=0):
# Check that all SJI data are coming from the same OBS ID.
if len(np.unique([cube.meta["OBSID"] for cube in data_list])) != 1:
Copy link
Member

Choose a reason for hiding this comment

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

This could be rewritten as:

if any([cube.meta["OBSID"] for cube in data_list] != data_list[0].meta["OBSID"]):

The list might have to be an array. I'm not sure. Check this out.

Copy link
Contributor Author

@BaptistePellorceAstro BaptistePellorceAstro May 7, 2018

Choose a reason for hiding this comment

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

With this line, I get an error that I solve by doing :

if np.any([cube.meta["OBSID"] != data_list[0].meta["OBSID"] for cube in data_list]):

extra_coords=extra_coords, scaled=scaled))
hdulist.close()

return IRISMapCubeSequence(list_of_cubes, meta=meta, common_axis=0)
Copy link
Member

Choose a reason for hiding this comment

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

I think an IRISMapCubeSequence should only be returned if there is more than one file input. Otherwise, an IRISMapCube should be returned as before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, this is boring to use it with only one file (I am working with). I will modify it.

@DanRyanIrish
Copy link
Member

Thanks for this PR @BaptistePellorceAstro. I made a couple of minor initial comments.

This has brought up a larger issue in my mind. That is, how should the IRISMapCubeSequence behave as far as the user is concerned. In the case of spectrograph images, the sequence dimension has a physical meaning, i.e. the raster scan number. However, in the case of SJI images, the only reason have this sequence dimension is because of how the data is stored in different files. As far as the user cares, the sequence axis and time are axis are just different sized chunks of the same axis. Therefore, perhaps the IRISMapCubeSequence should always appear to the user as 3D.

In principle this could be done by rewriting the IRISMapCubeSequence.__getitem__ to simply call the index_as_cube property. The same is true of the dimensions and world_axis_physical_coords. They can be rewritten to call the cube_like_dimensions and cube_like_world_axis_physical_types. There may be complications with ensuring that we don't end up with circular calling that breaks it. But I'm sure there's a way around it. In fact, a previous implementation had worked this out. But then we removed it.

filename : `str`
File name to be read
filenames: `list` of `str` or `str`
Filename of filenames to be read. They must all be associated with the same
Copy link
Member

Choose a reason for hiding this comment

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

Typo: "of" should be "or"

@BaptistePellorceAstro
Copy link
Contributor Author

BaptistePellorceAstro commented May 8, 2018

Hi, as you said, I have some problems :

  • dimensions : The problem is that cube_like_dimensions is calling dimensions so I have a circular error. I succeed to solve it by changing the name of my function to dimensions2 for example. Do you have an idea to solve this bug ?

  • __getitem__ : For every tests I did, I have already this error __getitem__() missing 1 required positional argument: 'item'.

@@ -274,7 +274,7 @@ def __repr__(self):

def __getitem__(self, item):
return utils.sequence.slice_sequence(self, item)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use utils.sequence.slice_sequence(self, item) rather than index_as_cube because the last function is calling a lot of function that are not relevant (creating as many error as functions) and return the same result. What do you think about it ?

Copy link
Member

Choose a reason for hiding this comment

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

I think you should call index_as_cube. The extra checks it does make it more rigorous. We just need to get it working here. And I think simply calling utils.sequence.slice_sequence will not always be correct. The way you should call index_as_cube it is:

return self.index_as_cube[item]

Have you tried this? If so, what errors are you getting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now it works !

@DanRyanIrish
Copy link
Member

Hi @BaptistePellorceAstro. I just noticed how long ago you sent your first comment since I last looked at this. Apologies for the delay in replying. I've left a couple comments to get you going again. I'll also look into the cube_like_dimensions issue you asked about and get back to you.

@DanRyanIrish
Copy link
Member

@BaptistePellorceAstro, I think the solution to the dimensions issue will require a simple change to NDCubeSequence in the ndcube package:

  • Create a new hidden method, NDCubeSequence._dimensions, that is just a copy of the current dimensions method.
  • Rewrite NDCubeSequence.dimensions so it simply calls the hidden version _dimensions.
  • In NDCubeSequence.cube_like_dimensions replace calls to the self.dimensions method with calls to the hidden version self._dimensions.
  • Then, back in IRISpy, you should be able to rewrite dimensions with a call to cube_like_dimensions as there will no longer be circular calling.

Does this make sense?

@BaptistePellorceAstro
Copy link
Contributor Author

Thanks for your help, now everything is working. I opened a new PR in ndcube to solve the cycling bug.


@property
def cube_dimensions(self):
def dimensions(self):
return self.cube_like_dimensions

@property
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I think I told you to call this property world_axis_physical_coords. It was a typo. It should have the same name as the NDCubeSequence method which is world_axis_physical_types. My mistake. THis means it also needs changing in line 276 well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified

@@ -101,11 +103,14 @@ def __repr__(self):
#Conversion of the end date of OBS
endobs = self.meta.get("ENDOBS", None)
endobs = endobs.isoformat() if endobs else None
#Conversion of the instance start of OBS
instance_start = self.extra_coords["TIME"]["value"][0]
#Conversion of the instance start and end of OBS
Copy link
Member

Choose a reason for hiding this comment

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

Just so you know, the convention of comments is to use a space between the # and the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course, I just forget to add a space.

@DanRyanIrish
Copy link
Member

Hi @BaptistePellorceAstro. I think this PR is almost ready to merge! :) I just asked for a method name change that was originally my fault for giving you the wrong name. See above comment.

@BaptistePellorceAstro
Copy link
Contributor Author

If everything is OK for you, I am ready to merge.

@DanRyanIrish DanRyanIrish merged commit 528efa6 into sunpy:master May 16, 2018
@DanRyanIrish
Copy link
Member

Another merged PR! You're flying through them!

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