mattyowl / RSSMOSPipeline

Pipeline for reducing both longslit and multi-object spectroscopic data from the Robert Stobie Spectrograph on SALT.
https://rssmospipeline.readthedocs.io
GNU General Public License v3.0
4 stars 2 forks source link

How can I modify the RSS MOSS pipeline code to extract the spectrum at a specific pixel position? #22

Closed PKSejake closed 1 year ago

PKSejake commented 1 year ago

Hi Matt.

How can I modify the RSS MOSS pipeline code to extract the spectrum at a specific pixel position? I run the pipeline on the G4Jy source, and no matter how much I decrease the longslit-threshold, there is still no slit defined for my target. Below is the screenshot of the fits image with the slits regions. My target is just underneath the slit 6 region.

Screenshot 2023-02-07 at 12 52 36

Regards Katlego

mattyowl commented 1 year ago

Hi Katlego,

The routine that decides where to extract traces from longslit data is here:

https://github.com/mattyowl/RSSMOSPipeline/blob/8b18f0076e477ad95109510e48770a754786dae9/RSSMOSPipeline/RSSMOSTools.py#L676

Maybe it could be as simple as making some of the parameters this routine takes adjustable via command line arguments - in a similar way to the threshold parameter. If you add something that fixes your problem, please make a pull request and I'll merge it in.

Alternatively, if you can send me an archive with your data in it, I can fiddle around and fix the problem for this case.

Cheers Matt

mattyowl commented 1 year ago

Ok - I've checked in an update to the master branch that should help, I think - please give it a go to make sure it's doing what you want and let me know. I don't think you should need to change the default threshold value.

The fix should just improve the peak finding for locating the object traces in longslit data - the problem in your data is a large gradient across the image which was throwing it off. I've added a filtering step that flattens the background (only when it's looking for object traces) that should fix it.

If this works for you, I'll make a new tagged release after doing a bit more testing on data I have.

Cheers Matt

PKSejake commented 1 year ago

Hi Matt,

I'm reinstalling the pipeline, but I'm getting an error about astLib.

Building wheels for collected packages: astLib Building wheel for astLib (setup.py) ... error ERROR: Command errored out with exit status 1: command: /Users/preciouskatlegosejake/opt/anaconda3/envs/rss_moss_env/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/v2/tqzjtbh94c3cfh9hk88500fh0000gn/T/pip-install-u9xmqawz/astlib_92ef139cda93416eb969e6360fe2dab9/setup.py'"'"'; file='"'"'/private/var/folders/v2/tqzjtbh94c3cfh9hk88500fh0000gn/T/pip-install-u9xmqawz/astlib_92ef139cda93416eb969e6360fe2dab9/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/v2/tqzjtbh94c3cfh9hk88500fh0000gn/T/pip-wheel-0eml01no cwd: /private/var/folders/v2/tqzjtbh94c3cfh9hk88500fh0000gn/T/pip-install-u9xmqawz/astlib_92ef139cda93416eb969e6360fe2dab9/ Complete output (25 lines): running bdist_wheel running build running build_py creating build creating build/lib.macosx-10.9-x86_64-3.6 creating build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astCalc.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astPlots.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astSED.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/init.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astCoords.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astStats.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astWCS.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astImages.py -> build/lib.macosx-10.9-x86_64-3.6/astLib creating build/lib.macosx-10.9-x86_64-3.6/PyWCSTools copying PyWCSTools/wcscon.py -> build/lib.macosx-10.9-x86_64-3.6/PyWCSTools copying PyWCSTools/init.py -> build/lib.macosx-10.9-x86_64-3.6/PyWCSTools copying PyWCSTools/wcs.py -> build/lib.macosx-10.9-x86_64-3.6/PyWCSTools creating build/lib.macosx-10.9-x86_64-3.6/astLib/data copying astLib/data/bohlin2006_Vega.sed -> build/lib.macosx-10.9-x86_64-3.6/astLib/data copying astLib/data/sun_reference_stis_001.ascii -> build/lib.macosx-10.9-x86_64-3.6/astLib/data running build_ext gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -I/Users/preciouskatlegosejake/opt/anaconda3/envs/rss_moss_env/include -arch x86_64 -I/Users/preciouskatlegosejake/opt/anaconda3/envs/rss_moss_env/include -arch x86_64 -c iget.c -o iget.o xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun error: command 'gcc' failed with exit status 1

ERROR: Failed building wheel for astLib Running setup.py clean for astLib Failed to build astLib Installing collected packages: six, python-dateutil, pyparsing, pillow, numpy, kiwisolver, cycler, scipy, matplotlib, astropy, astLib, RSSMOSPipeline Running setup.py install for astLib ... error ERROR: Command errored out with exit status 1: command: /Users/preciouskatlegosejake/opt/anaconda3/envs/rss_moss_env/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/v2/tqzjtbh94c3cfh9hk88500fh0000gn/T/pip-install-u9xmqawz/astlib_92ef139cda93416eb969e6360fe2dab9/setup.py'"'"'; file='"'"'/private/var/folders/v2/tqzjtbh94c3cfh9hk88500fh0000gn/T/pip-install-u9xmqawz/astlib_92ef139cda93416eb969e6360fe2dab9/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /private/var/folders/v2/tqzjtbh94c3cfh9hk88500fh0000gn/T/pip-record-mj_856pk/install-record.txt --single-version-externally-managed --compile --install-headers /Users/preciouskatlegosejake/opt/anaconda3/envs/rss_moss_env/include/python3.6m/astLib cwd: /private/var/folders/v2/tqzjtbh94c3cfh9hk88500fh0000gn/T/pip-install-u9xmqawz/astlib_92ef139cda93416eb969e6360fe2dab9/ Complete output (25 lines): running install running build running build_py creating build creating build/lib.macosx-10.9-x86_64-3.6 creating build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astCalc.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astPlots.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astSED.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/init.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astCoords.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astStats.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astWCS.py -> build/lib.macosx-10.9-x86_64-3.6/astLib copying astLib/astImages.py -> build/lib.macosx-10.9-x86_64-3.6/astLib creating build/lib.macosx-10.9-x86_64-3.6/PyWCSTools copying PyWCSTools/wcscon.py -> build/lib.macosx-10.9-x86_64-3.6/PyWCSTools copying PyWCSTools/init.py -> build/lib.macosx-10.9-x86_64-3.6/PyWCSTools copying PyWCSTools/wcs.py -> build/lib.macosx-10.9-x86_64-3.6/PyWCSTools creating build/lib.macosx-10.9-x86_64-3.6/astLib/data copying astLib/data/bohlin2006_Vega.sed -> build/lib.macosx-10.9-x86_64-3.6/astLib/data copying astLib/data/sun_reference_stis_001.ascii -> build/lib.macosx-10.9-x86_64-3.6/astLib/data running build_ext gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -I/Users/preciouskatlegosejake/opt/anaconda3/envs/rss_moss_env/include -arch x86_64 -I/Users/preciouskatlegosejake/opt/anaconda3/envs/rss_moss_env/include -arch x86_64 -c iget.c -o iget.o xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun error: command 'gcc' failed with exit status 1

ERROR: Command errored out with exit status 1: /Users/preciouskatlegosejake/opt/anaconda3/envs/rss_moss_env/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/v2/tqzjtbh94c3cfh9hk88500fh0000gn/T/pip-install-u9xmqawz/astlib_92ef139cda93416eb969e6360fe2dab9/setup.py'"'"'; file='"'"'/private/var/folders/v2/tqzjtbh94c3cfh9hk88500fh0000gn/T/pip-install-u9xmqawz/astlib_92ef139cda93416eb969e6360fe2dab9/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /private/var/folders/v2/tqzjtbh94c3cfh9hk88500fh0000gn/T/pip-record-mj_856pk/install-record.txt --single-version-externally-managed --compile --install-headers /Users/preciouskatlegosejake/opt/anaconda3/envs/rss_moss_env/include/python3.6m/astLib Check the logs for full command output.

Regards Katlego

mattyowl commented 1 year ago

Guessing you have a Mac. See:

https://astlib.readthedocs.io/en/latest/usage.html#installation-on-recent-versions-of-macos

For some reason, fairly recent Macs pretend they have GCC when they don't.

PKSejake commented 1 year ago

Hi Matt,

The changes you made worked. I can now get the spectrum for my target. But I still had to reduce the longslit-threshold to 0.5.

Regards Katlego

mattyowl commented 1 year ago

Melissa Morris has added a new -F flag that allows one to specify slit (or object) locations manually - perhaps that may work for your case also? This uses the new -F flag, and is in the master branch.