asdf-format/asdf

asdftool repr for Time objects

Closed this issue · 5 comments

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?).

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)).

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

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.

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

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.