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

Coordinate transforms don't support arrays of times #126

Open
3 tasks
samaloney opened this issue Jun 5, 2024 · 0 comments
Open
3 tasks

Coordinate transforms don't support arrays of times #126

samaloney opened this issue Jun 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@samaloney
Copy link
Member

samaloney commented Jun 5, 2024

For the coordinates API needs to support the data or obs times can be arrays but currently this doesn't work for the implemented transform from STIXImaging to HPC

The current code is focused on imaging need to adapt for coordinate transform which should be reversible - not sure the mean approach works here should only interpolate but do in vectorised manner. Related to #52.

  • Add test for single data coord many times
  • Add test for array of data and one time
  • Add test for array of data and array of times

Works

hpc = ff.flare_location[0].transform_to(frame='helioprojective')

Doesn't

hpc = ff.flare_location.transform_to(frame='helioprojective')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File ~/.virtualenvs/stixpy/lib/python3.11/site-packages/astropy/time/core.py:707, in TimeBase.__hash__(self)
    705         loc = loc.x.to_value(u.m), loc.y.to_value(u.m), loc.z.to_value(u.m)
--> 707     return hash((self.jd1, self.jd2, self.scale, loc))
    709 except TypeError:

TypeError: unhashable type: 'numpy.ndarray'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
Cell In[36], line 1
----> 1 hpc = ff.flare_location.transform_to(frame='helioprojective')

File ~/.virtualenvs/stixpy/lib/python3.11/site-packages/astropy/coordinates/sky_coordinate.py:692, in SkyCoord.transform_to(self, frame, merge_attributes)
    688 generic_frame = GenericFrame(frame_kwargs)
    690 # Do the transformation, returning a coordinate frame of the desired
    691 # final type (not generic).
--> 692 new_coord = trans(self.frame, generic_frame)
    694 # Finally make the new SkyCoord object from the `new_coord` and
    695 # remaining frame_kwargs that are not frame_attributes in `new_coord`.
    696 for attr in set(new_coord.frame_attributes) & set(frame_kwargs.keys()):

File ~/.virtualenvs/stixpy/lib/python3.11/site-packages/astropy/coordinates/transformations.py:1574, in CompositeTransform.__call__(self, fromcoord, toframe)
   1571             frattrs[inter_frame_attr_nm] = attr
   1573     curr_toframe = t.tosys(**frattrs)
-> 1574     curr_coord = t(curr_coord, curr_toframe)
   1576 # this is safe even in the case where self.transforms is empty, because
   1577 # coordinate objects are immutable, so copying is not needed
   1578 return curr_coord

File ~/.virtualenvs/stixpy/lib/python3.11/site-packages/astropy/coordinates/transformations.py:949, in FunctionTransform.__call__(self, fromcoord, toframe)
    948 def __call__(self, fromcoord, toframe):
--> 949     res = self.func(fromcoord, toframe)
    950     if not isinstance(res, self.tosys):
    951         raise TypeError(
    952             f"the transformation function yielded {res} but "
    953             f"should have been of type {self.tosys}"
    954         )

File ~/Projects/stixpy/stixpy/coordinates/transforms.py:218, in stixim_to_hpc(stxcoord, hpcframe)
    213 r"""
    214 Transform STIX Imaging coordinates to given HPC frame
    215 """
    216 logger.debug("STIX: %s", stxcoord)
--> 218 rot_matrix, solo_pos_heeq = _get_rotation_matrix_and_position(stxcoord.obstime)
    219 solo_heeq = HeliographicStonyhurst(solo_pos_heeq, representation_type="cartesian", obstime=stxcoord.obstime)
    221 # Transform from STIX imaging to SOLO HPC

File ~/Projects/stixpy/stixpy/coordinates/transforms.py:40, in _get_rotation_matrix_and_position(obstime)
     29 def _get_rotation_matrix_and_position(obstime):
     30     r"""
     31     Return rotation matrix STIX Imaging to SOLO HPC and position of SOLO in HEEQ.
     32
   (...)
     38     -------
     39     """
---> 40     roll, solo_position_heeq, spacecraft_pointing = get_hpc_info(obstime)
     42     # Generate the rotation matrix using the x-convention (see Goldstein)
     43     # Rotate +90 clockwise around the first axis
     44     # STIX is mounted on the -Y panel (SOLO_SRF) need to rotate to from STIX frame to SOLO_SRF
     45     rot_to_solo = np.array([[1, 0, 0], [0, 0, -1], [0, 1, 0]])

File ~/Projects/stixpy/stixpy/coordinates/transforms.py:73, in get_hpc_info(start_time, end_time)
     58 def get_hpc_info(start_time, end_time=None):
     59     r"""
     60     Get STIX pointing and SO location from L2 aspect files.
     61
   (...)
     71
     72     """
---> 73     aux = _get_aux_data(start_time, end_time=end_time)
     74     if end_time is None:
     75         end_time = start_time

File ~/.virtualenvs/stixpy/lib/python3.11/site-packages/astropy/time/core.py:717, in TimeBase.__hash__(self)
    714 else:
    715     raise
--> 717 raise TypeError(f"unhashable type: '{self.__class__.__name__}' {reason}")

TypeError: unhashable type: 'Time' (must be scalar)
@samaloney samaloney added the bug Something isn't working label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant