zkbt / chromatic

Tools for visualizing spectrosopic light curves, with flux as a function of wavelength and time.
MIT License
14 stars 4 forks source link

Error loading Eureka! files #208

Open catrionamurray opened 1 year ago

catrionamurray commented 1 year ago

Error loading in Eureka! S3 or S4 files:

rainbow = read_rainbow("jwst_data/S4_wasp39b_ap6_bg7_SpecData.h5")


NameError Traceback (most recent call last) Input In [8], in <cell line: 3>() 1 # rainbow = read_rainbow("jwst_data/jw02734002001_04101_00001-seg00_nis_x1dints.fits") 2 # hatp = read_rainbow("jwst_data/jw02734001001_04102_00001-seg00_nis_x1dints.fits") ----> 3 rainbow = read_rainbow("jwst_data/S4_wasp39b_ap6_bg7_SpecData.h5")

File ~/opt/anaconda3/lib/python3.9/site-packages/chromatic/rainbows/init.py:29, in read_rainbow(filepath, kw) 8 def read_rainbow(filepath, kw): 9 """ 10 A friendly wrapper to load time-series spectra and/or 11 multiwavelength light curves into a chromatic Rainbow (...) 27 The loaded data! 28 """ ---> 29 r = Rainbow(filepath, kw) 30 if "model" in r.fluxlike: 31 return RainbowWithModel(r._get_core_dictionaries())

File ~/opt/anaconda3/lib/python3.9/site-packages/chromatic/rainbows/rainbow.py:227, in Rainbow.init(self, filepath, format, wavelength, time, flux, uncertainty, wavelike, timelike, fluxlike, metadata, name, kw) 225 # then try to initialize from a file 226 elif isinstance(filepath, str) or isinstance(filepath, list): --> 227 self._initialize_from_file(filepath=filepath, format=format, kw) 229 # finally, tidy up by guessing the scales 230 self._guess_wscale()

File ~/opt/anaconda3/lib/python3.9/site-packages/chromatic/rainbows/rainbow.py:463, in Rainbow._initialize_from_file(self, filepath, format, kw) 461 # pick the appropriate reader 462 reader = guess_reader(filepath=filepath, format=format) --> 463 reader(self, filepath, kw) 465 # validate that something reasonable got populated 466 self._validate_core_dictionaries()

File ~/opt/anaconda3/lib/python3.9/site-packages/chromatic/rainbows/readers/eureka_specdata.py:66, in from_eureka_SpecData(rainbow, filepath, optimal) 64 rainbow.set_times_from_astropy(astropy_times, is_barycentric=True) 65 else: ---> 66 t_unit = u.Unit(dataset[t_key].attrs["time_units"]) 67 t_without_unit = dataset[k].data 68 rainbow.timelike["time"] = t_without_unit * t_unit

NameError: name 't_key' is not defined

catrionamurray commented 1 year ago

I believe this error could be fixed by replacing: t_unit = u.Unit(dataset[t_key].attrs["time_units"]) with t_unit = u.Unit(dataset[k].attrs["time_units"]) ?

catrionamurray commented 1 year ago

Though if I do that I now get this error:


ValueError Traceback (most recent call last) File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/units/format/generic.py:612, in Generic._do_parse(cls, s, debug) 609 try: 610 # This is a short circuit for the case where the string 611 # is just a single unit name --> 612 return cls._parse_unit(s, detailed_exception=False) 613 except ValueError as e:

File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/units/format/generic.py:511, in Generic._parse_unit(cls, s, detailed_exception) 510 else: --> 511 raise ValueError()

ValueError:

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last) File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/units/format/generic.py:479, in Generic._get_unit(cls, t) 478 try: --> 479 return cls._parse_unit(t.value) 480 except ValueError as e:

File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/units/format/generic.py:508, in Generic._parse_unit(cls, s, detailed_exception) 507 if detailed_exception: --> 508 raise ValueError( 509 f'{s} is not a valid unit. {did_you_mean(s, registry)}') 510 else:

ValueError: BMJD_TDB is not a valid unit.

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last) File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/units/core.py:2024, in _UnitMetaClass.call(self, s, represents, format, namespace, doc, parse_strict) 2023 try: -> 2024 return f.parse(s) 2025 except NotImplementedError:

File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/units/format/generic.py:597, in Generic.parse(cls, s, debug) 595 s = cls._regex_deg.sub(cls._convert_deg, s) --> 597 result = cls._do_parse(s, debug=debug) 598 # Check for excess solidi, but exclude fractional exponents (accepted)

File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/units/format/generic.py:615, in Generic._do_parse(cls, s, debug) 614 try: --> 615 return cls._parser.parse(s, lexer=cls._lexer, debug=debug) 616 except ValueError as e:

File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/utils/parsing.py:115, in ThreadSafeParser.parse(self, *args, *kwargs) 114 with self._lock: --> 115 return self.parser.parse(args, **kwargs)

File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/extern/ply/yacc.py:333, in LRParser.parse(self, input, lexer, debug, tracking, tokenfunc) 332 else: --> 333 return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)

File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/extern/ply/yacc.py:1063, in LRParser.parseopt_notrack(self, input, lexer, debug, tracking, tokenfunc) 1062 if not lookaheadstack: -> 1063 lookahead = get_token() # Get the next token 1064 else:

File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/extern/ply/lex.py:350, in Lexer.token(self) 348 self.lexpos = lexpos --> 350 newtok = func(tok) 352 # Every function must return a token, if nothing, we just move to next token

File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/units/format/generic.py:152, in Generic._make_lexer..t_UNIT(t) 151 "%|([YZEPTGMkhdcmu\N{MICRO SIGN}npfazy]?'((?!\d)\w)+')|((?!\d)\w)+" --> 152 t.value = cls._get_unit(t) 153 return t

File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/units/format/generic.py:485, in Generic._get_unit(cls, t) 483 return registry.aliases[t.value] --> 485 raise ValueError( 486 f"At col {t.lexpos}, {str(e)}")

ValueError: At col 0, BMJD_TDB is not a valid unit.

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last) Input In [4], in <cell line: 3>() 1 # rainbow = read_rainbow("jwst_data/jw02734002001_04101_00001-seg00_nis_x1dints.fits") 2 # hatp = read_rainbow("jwst_data/jw02734001001_04102_00001-seg00_nis_x1dints.fits") ----> 3 rainbow = read_rainbow("jwst_data/S3_wasp39b_ap6_bg7_SpecData.h5")

File ~/opt/anaconda3/lib/python3.9/site-packages/chromatic/rainbows/init.py:29, in read_rainbow(filepath, kw) 8 def read_rainbow(filepath, kw): 9 """ 10 A friendly wrapper to load time-series spectra and/or 11 multiwavelength light curves into a chromatic Rainbow (...) 27 The loaded data! 28 """ ---> 29 r = Rainbow(filepath, kw) 30 if "model" in r.fluxlike: 31 return RainbowWithModel(r._get_core_dictionaries())

File ~/opt/anaconda3/lib/python3.9/site-packages/chromatic/rainbows/rainbow.py:227, in Rainbow.init(self, filepath, format, wavelength, time, flux, uncertainty, wavelike, timelike, fluxlike, metadata, name, kw) 225 # then try to initialize from a file 226 elif isinstance(filepath, str) or isinstance(filepath, list): --> 227 self._initialize_from_file(filepath=filepath, format=format, kw) 229 # finally, tidy up by guessing the scales 230 self._guess_wscale()

File ~/opt/anaconda3/lib/python3.9/site-packages/chromatic/rainbows/rainbow.py:463, in Rainbow._initialize_from_file(self, filepath, format, kw) 461 # pick the appropriate reader 462 reader = guess_reader(filepath=filepath, format=format) --> 463 reader(self, filepath, kw) 465 # validate that something reasonable got populated 466 self._validate_core_dictionaries()

File ~/opt/anaconda3/lib/python3.9/site-packages/chromatic/rainbows/readers/eureka_specdata.py:66, in from_eureka_SpecData(rainbow, filepath, optimal) 64 rainbow.set_times_from_astropy(astropy_times, is_barycentric=True) 65 else: ---> 66 t_unit = u.Unit(dataset[k].attrs["time_units"]) 67 t_without_unit = dataset[k].data 68 rainbow.timelike["time"] = t_without_unit * t_unit

File ~/opt/anaconda3/lib/python3.9/site-packages/astropy/units/core.py:2046, in _UnitMetaClass.call(self, s, represents, format, namespace, doc, parse_strict) 2037 msg = ("'{}' did not parse as {}unit: {} " 2038 "If this is meant to be a custom unit, " 2039 "define it with 'u.def_unit'. To have it " (...) 2043 "https://docs.astropy.org/en/latest/units/combining_and_defining.html" 2044 .format(s, format_clause, str(e))) 2045 if parse_strict == 'raise': -> 2046 raise ValueError(msg) 2047 elif parse_strict == 'warn': 2048 warnings.warn(msg, UnitsWarning)

ValueError: 'BMJD_TDB' did not parse as unit: At col 0, BMJD_TDB is not a valid unit. If this is meant to be a custom unit, define it with 'u.def_unit'. To have it recognized inside a file reader or other code, enable it with 'u.add_enabled_units'. For details, see https://docs.astropy.org/en/latest/units/combining_and_defining.html

catrionamurray commented 1 year ago

This could be due to me having an older version of Eureka! (v5)? It works if I also change "BJD_TDB" to "BMJD_TDB" but I'm not sure which is correct in the newest Eureka!

zkbt commented 1 year ago

@catrionamurray has fix for her particular version of Eureka. Let's:

catrionamurray commented 1 year ago

Fix for >=v0.5 here https://github.com/zkbt/chromatic/pull/209