ers-transit / informal-bug-and-suggestion-tracking

This is a placeholder for discussing simulated data and/or pipeline Issues connected to the ers-transit Data Challenge events.
0 stars 0 forks source link

`astropy` can’t handle variance unit of `(MJy/sr)^2` in `x1dints` files #1

Open zkbt opened 2 years ago

zkbt commented 2 years ago

This might be a super fussy and unimportant thing, but I figured I'd bring it up.

While reading a Stage 2 x1dints file, I’m trying to be clever by assigning astropy units according to what’s listed in the FITS ‘unit’ associated with each column. This complains for name = 'SB_VAR_POISSON'; format = 'D'; unit = '(MJy/sr)^2' which seems like a reasonable variance unit, if its being compared to a quantity in MJy/sr, but the astropy Unit can’t parse that string. A simple example of how this breaks:

import astropy.units as u

# these first two are fine
u.Unit('MJy/sr')
u.Unit('MJy^2/sr^2')

# this one complains
u.Unit('(MJy/sr)^2')

I think I have a workaround for my own code trying to do this, but just defining a custom unit with

# define a units associated with that string
variance_unit = u.def_unit('(MJy/sr)^2', u.MJy**2/u.sr**2)
u.add_enabled_units(variance_unit)

# now this is OK
u.Unit('(MJy/sr)^2')

But, maybe it'd simplify things for other folks if these units could be directly parsed into astropy. So, my questions:

AarynnCarter commented 2 years ago

Hey @zkbt, this is from the pipeline, and not the simulated data. Specifically, see line 2863 in the extract1d/extract.py file in the JWST pipeline python package. It seems like there's also instances in the ifu.py file (line 186-193) under the same subdirectory.

My suggestion would be to make a JWST Help Desk request and outline why switching to an astropy compatible unit would be better. I suppose you could also just submit a pull request to the Github (https://github.com/spacetelescope/jwst), but I don't know how open they are to that.