samuelyeewl / specmatch-emp

Empirical SpecMatch
9 stars 8 forks source link

All orders #39

Open petigura opened 5 years ago

petigura commented 5 years ago

Opening pull request for getting all_orders branch into master

samuelyeewl commented 5 years ago

Hi Erik,

I'm wondering if you've used this branch recently? I recall testing this a while ago but I'll want to make sure it works before merging it into the main branch, so any feedback would be useful. I'm also trying to locate the results from the cross-validation tests I carried out for each order.

Cheers, Sam

petigura commented 5 years ago

Hey Sam!

I opened up the PR to compare the branches. So far, I haven't been able to get it to run on my computer, but I also haven't had to time try to debug it.

[specmatch-emp]$ smemp specmatch j339.307
Reading library from /Users/petigura/.specmatchemp/library.h5
Shifting spectrum
Traceback (most recent call last):
  File "/Users/petigura/anaconda2/bin/smemp", line 11, in <module>
    load_entry_point('SpecMatch-Emp==0.3', 'console_scripts', 'smemp')()
  File "/Users/petigura/code/specmatch-emp/specmatchemp/cli.py", line 159, in main
    args.func(args)
  File "/Users/petigura/code/specmatch-emp/specmatchemp/cli.py", line 32, in specmatch_spectrum
    suffix=args.suffix, lib_subset=lib_subset)
  File "/Users/petigura/code/specmatch-emp/specmatchemp/core.py", line 84, in specmatch_spectrum
    sm.shift()
  File "/Users/petigura/code/specmatch-emp/specmatchemp/specmatch.py", line 151, in shift
    store=self.shift_data)
  File "/Users/petigura/code/specmatch-emp/specmatchemp/shift.py", line 35, in bootstrap_shift
    print("Shifting spectrum {0}".format(targ.name))
AttributeError: 'list' object has no attribute 'name'

Looking at the code base, it looks like the only options are to run it on all the segments.

SPECMATCH_REGIONS = [(5000, 5100), (5100, 5200), (5200, 5300),
                     (5300, 5400), (5400, 5500), (5500, 5600),
                     (5600, 5700), (5700, 5800), (5800, 5900),
                     (5900, 6000), (6000, 6100), (6100, 6200),
                     (6200, 6275), (6320, 6420),
                     # Red chip
                     (6550, 6650), (6675, 6775), (6800, 6860),
                     (6940, 7040), (7080, 7180), (7220, 7330),
                     (7370, 7480), (7520, 7590), (7700, 7810),
                     (7865, 7960)
                     ]

It would be super helpful to have the capability for the user to specify the wavelength range over which specmatch-emp is run. For example, for spectra with iodine cell in, we'd want to run it on lambda = 6550-8000 only.

samuelyeewl commented 5 years ago

I've taken a look at the code and I think I had started implementing this feature but stopped partway. Shifting over all chips should work, and if one wanted to run specmatch on just lambda > 6550, you should be able to run it just specifying ijXXX.XXXX.fits (let me know if this doesn't work).

The wavelength regions specified in SPECMATCH_REGIONS were (if I recall correctly) chosen to be roughly 100 angstroms in width but avoiding regions with forests of telluric lines.

A caveat: In the red chip, several of those wavelength regions give very poor results, particularly in distinguishing subgiants from the dwarfs. I managed to find a subset of wavelength regions that give results comparable to the rj chip (106 K in Teff, 18% in Rstar, 0.09 dex in FeH), but I'll need to find the code where I recorded which wavelength ranges were chosen.

petigura commented 5 years ago

So it looks like it almost works. I had to make a small modification to how the inlib argument is treated. Did you find those segments that performed well for the ij chip?

[specmatch-emp]$ smemp specmatch ~/.cpsutils/mir3/iodfitsdb/ij122.742.fits -p -o ./test/ --debug
Reading library from /Users/petigura/.specmatchemp/library.h5
> /Users/petigura/code/specmatch-emp/specmatchemp/core.py(45)specmatch_spectrum()
-> if os.path.exists(specpath):
(Pdb) c
Reading library from /Users/petigura/.specmatchemp/library.h5
Shifting spectrum
Shifting spectrum ij122.742
Attempting shift to spectrum NSO, median cross-correlation peak = 0.32
Best reference for shifting: NSO
Shifting entire spectrum
Matching spectrum
Matching region (6550, 6650)
Matching region (6675, 6775)
Matching region (6800, 6860)
Matching region (6940, 7040)
Matching region (7080, 7180)
Matching region (7220, 7330)
Matching region (7370, 7480)
Matching region (7520, 7590)
Matching region (7700, 7810)
Matching region (7865, 7959.992050938369)
Creating linear combinations
Linear combinations in region (6550, 6650)
Linear combinations in region (6675, 6775)
Linear combinations in region (6800, 6860)
Linear combinations in region (6940, 7040)
Linear combinations in region (7080, 7180)
Linear combinations in region (7220, 7330)
Linear combinations in region (7370, 7480)
Linear combinations in region (7520, 7590)
Linear combinations in region (7700, 7810)
Linear combinations in region (7865, 7959.992050938369)
SpecMatch Results for ij122.742
Derived Parameters
------------------
Teff: 5607 +/- 110 K
Radius: 1.546 +/- 0.180 Rsun
[Fe/H]: -0.02 +/- 0.09 dex
created ./test/ij122.742/ij122.742_results.txt
Saving SpecMatch object to HDF file
created ./test/ij122.742/ij122.742_sm.hdf
/Users/petigura/anaconda2/lib/python2.7/site-packages/numpy/lib/nanfunctions.py:1259: RuntimeWarning: Mean of empty slice
  return np.nanmean(a, axis, out=out, keepdims=keepdims)
Traceback (most recent call last):
  File "/Users/petigura/anaconda2/bin/smemp", line 11, in <module>
    load_entry_point('SpecMatch-Emp', 'console_scripts', 'smemp')()
  File "/Users/petigura/code/specmatch-emp/specmatchemp/cli.py", line 159, in main
    args.func(args)
  File "/Users/petigura/code/specmatch-emp/specmatchemp/cli.py", line 32, in specmatch_spectrum
    suffix=args.suffix, lib_subset=lib_subset)
  File "/Users/petigura/code/specmatch-emp/specmatchemp/core.py", line 45, in specmatch_spectrum
    if os.path.exists(specpath):
  File "/Users/petigura/code/specmatch-emp/specmatchemp/core.py", line 181, in plot_shifts
    sm.plot_shifted_spectrum(wavlim=wavlim)
  File "/Users/petigura/code/specmatch-emp/specmatchemp/specmatch.py", line 774, in plot_shifted_spectrum
    if (target.w[0] > shift_ref.w[0]) \
IndexError: index 0 is out of bounds for axis 0 with size 0