<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Fussing with Slit Tracing [v1]
Step1:  To run this Notebook, you must have an environmental variable pointed at the PYPIT Development suite
And you will need to have downloaded and unpacked the 'Cooked' set of files
Step2:  Checking edges
Launch an RC Ginga viewer in your terminal
ginga --modules=RC
Point at a PYPIT MasterTrace frame
Step3:  PYPYIT Script
pypit_chk_edges $PYPIT_DEV/Cooked/Trace/MasterTrace_KeckLRISr_150420_402
The image and the traces should show in the Ginga viewer
Using the TraceSlits class
Load
Step4:  Show
Step5:  Add a Slit
There will be cases when one needs to manually add a slit
This frame is missing a slit due to 2 alignment star boxes
Here are ways to add one
Internal (with the TraceSlits class)
Step6:  PYPIT script (coming someday, especially if requested)
Remove a slit
There are edge cases (e.g. ghost images) that lead to erroneous slits
Here is a way to remove one
Internal
Step7:  Re-run Tracing (only recommended for Developers)
Step8:  Load
Step9:  Run
<ASSISTANT_TASK:>
Python Code:
# imports
import os
from pypit import traceslits
Explanation: Fussing with Slit Tracing [v1]
End of explanation
print(os.getenv('PYPIT_DEV'))
Explanation: To run this Notebook, you must have an environmental variable pointed at the PYPIT Development suite
And you will need to have downloaded and unpacked the 'Cooked' set of files
End of explanation
mstrace_root = os.getenv('PYPIT_DEV')+'Cooked/Trace/MasterTrace_KeckLRISr_150420_402'
Explanation: Checking edges
Launch an RC Ginga viewer in your terminal
ginga --modules=RC
Point at a PYPIT MasterTrace frame
End of explanation
Tslits = traceslits.TraceSlits.from_master_files(mstrace_root)
Explanation: PYPYIT Script
pypit_chk_edges $PYPIT_DEV/Cooked/Trace/MasterTrace_KeckLRISr_150420_402
The image and the traces should show in the Ginga viewer
Using the TraceSlits class
Load
End of explanation
Tslits.show('edges')
Explanation: Show
End of explanation
#  left edge, right edge, row on image
add_user_slits = [[489,563,1024]]
# run_to_finish resets things in a proper manner
Tslits.add_user_slits(add_user_slits, run_to_finish=True)
# check -- S11 is the new one
Tslits.show('edges')
# write to disk (this will over-write so be careful)
new_root = os.path.basename(mstrace_root)+'_new'
Tslits.save_master(new_root)
Explanation: Add a Slit
There will be cases when one needs to manually add a slit
This frame is missing a slit due to 2 alignment star boxes
Here are ways to add one
Internal (with the TraceSlits class)
End of explanation
# Frame with extra slit
mstrace_root2 = os.getenv('PYPIT_DEV')+'Cooked/Trace/MasterTrace_KeckLRISr_20160110_A'
# Load
Tslits2 = traceslits.TraceSlits.from_master_files(mstrace_root2)
# Show
Tslits2.show('edges')
# Setup slit to remove --  xleft, yleft at yrow=nrow/2
rm_slits = [[229, 380]]
# Remove
Tslits2.remove_slit(rm_slits)
# Check
Tslits2.show('edges')
# write to disk (this will over-write so be careful)
new_root2 = os.path.basename(mstrace_root2)+'_new'
Tslits.save_master(new_root2)
Explanation: PYPIT script (coming someday, especially if requested)
Remove a slit
There are edge cases (e.g. ghost images) that lead to erroneous slits
Here is a way to remove one
Internal
End of explanation
mstrace_root3 = os.getenv('PYPIT_DEV')+'Cooked/Trace/MasterTrace_KeckLRISr_20160110_A'
Explanation: Re-run Tracing (only recommended for Developers)
End of explanation
Tslits2 = traceslits.TraceSlits.from_master_files(mstrace_root3)
Explanation: Load
End of explanation
tslit_dict = Tslits2.run()
tslit_dict
Explanation: Run
End of explanation
<END_TASK>