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

asdftool repr for Time objects #1686

Closed
tddesjardins opened this issue Nov 15, 2023 · 5 comments · Fixed by #1687
Closed

asdftool repr for Time objects #1686

tddesjardins opened this issue Nov 15, 2023 · 5 comments · Fixed by #1687

Comments

@tddesjardins
Copy link

Using asdftool info <file> on an ASDF file containing astropy.time.Time objects produces the following (excerpted) output:

  │ │ ├─type (str): WFI_IMAGE
  │ │ ├─start_time (Time) # UTC exposure start time
  │ │ ├─mid_time (Time) # UTC exposure mid time
  │ │ ├─end_time (Time) # UTC exposure end time

Is it possible to add some kind of repr to this to display the time (maybe in ISOT or some other format?).

@braingram
Copy link
Contributor

Thanks for opening the issue.

Would you give the source branch for #1687 a try? The output should be improved for Time objects:

  │ │ ├─start_time (Time): 2021-01-01T00:00:00.000
  │ │ ├─mid_time (Time): 2021-01-01T00:01:16.020
  │ │ ├─end_time (Time): 2021-01-01T00:02:32.040

However I went with a hopefully general solution so it's possible (and likely) that other objects will also now display values (whatever is returned from str(foo)).

@tddesjardins
Copy link
Author

tddesjardins commented Nov 16, 2023

That certainly did something! I'm seeing a little odd behavior though, which I don't think was expected. Running it on a Roman file I have did this:

  │ ├─exposure (TaggedDict)
  │ │ ├─id (int): 1
  │ │ ├─type (str): WFI_IMAGE
  │ │ ├─start_time (TaggedDict)
  │ │ │ ├─base_format (str): datetime
  │ │ │ └─value (str): 2027-09-12T13:30:22.000
  │ │ ├─mid_time (TaggedString): 2021-01-01T00:01:09.940
  │ │ ├─end_time (TaggedString): 2021-01-01T00:02:19.880

So they're not rendering as (Time) anymore, but as (TaggedString). And the meta.exposure section now shows as (TaggedDict). You can see it also seems to have dropped the descriptions from the schema in the rendered tree. And for some reason, start_time is showing as a dictionary while mid_time and end_time are not? But they're all astropy.time.Time objects. Comparison to the same section with the v2.15.1 of asdf:

  │ ├─exposure (Exposure) # Exposure information

  │ │ ├─id (int): 1 # Exposure id number within visit
  │ │ ├─type (str): WFI_IMAGE
  │ │ ├─start_time (Time) # UTC exposure start time
  │ │ ├─mid_time (Time) # UTC exposure mid time
  │ │ ├─end_time (Time) # UTC exposure end time

@braingram
Copy link
Contributor

Thanks for testing this.

Was the first example run with a installed version of roman_datamodels compatible with the file? Without that package asdf will not know how to interpret things like exposure (without asdf-astropy asdf won't know how to interpret Time)? When asdf doesn't know how to convert an object, it is returned as a Tagged object which explains why you're seeing the TaggedDict TaggedString etc.

@tddesjardins
Copy link
Author

Ah, okay, you're right. Good catch! Okay, looks good to me in that case! Thanks, Brett!

@braingram
Copy link
Contributor

Excellent! Thanks again for testing it and please do let me know if you notice anything else. I do see the exposure formatting is a bit odd (even in the 2.15 output). I think that's due to the rad schema but also should probably be sanitized by asdf to not add the line break. I'll give it a look and aim to address it in perhaps both rad and asdf.

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 a pull request may close this issue.

2 participants