@@ -312,6 +312,8 @@ def textfileargs(params, textfile=None):
312312 params['convert_rv_package_templates'] = params.get('convert_rv_package_templates', 'True')
313313 # Added 20210323:
314314 params['split_wavelength_solutions_at'] = params.get('split_wavelength_solutions_at', '[]')
315+ # Added 20210423:
316+ params['logging_em_lines_shift'] = params.get('logging_em_lines_shift', 'wavelength_solution_emmission_lines_shift_on_detector.png')
315317
316318
317319
@@ -3513,9 +3515,9 @@ def find_shift_images(params, im, im_ref, sci_traces, w_mult, cal_tr_poly, extra
35133515 ' borders due to next order [{2},{3}]) .').format(round(popt[1],2), round(popt[2],2),
35143516 min(range_shifts), max(range_shifts), params['extraction_shift'] )
35153517 shift, width = 0.0, 0.0
3516- elif popt[2 ] < max_allowed[0] or popt[2 ] > max_allowed[1]:
3518+ elif popt[1 ] < max_allowed[0] or popt[1 ] > max_allowed[1]:
35173519 comment = (' The calculated values (shift = {0} px, width = {1} px) were outside of the'+\
3518- ' allowed range ({3 }).').format(round(popt[1],2), round(popt[2],2), max_allowed )
3520+ ' allowed range ({2 }).').format(round(popt[1],2), round(popt[2],2), max_allowed )
35193521 shift, width = 0.0, 0.0
35203522 elif not extract: # keep everything if not extracting
35213523 shift, width, comment = round(popt[1],3), round(popt[2],3), ''
@@ -4062,9 +4064,9 @@ def shift_wavelength_solution(params, aspectra, wave_sol_dict, reference_lines_d
40624064 2: wavelength from wavelength solution
40634065 3: pixel of [2]
40644066 4: round of [3]
4065- 5: center of fitted gauss - px
4067+ 5: center of fitted gauss in px
40664068 6: shift: [5] -[3]
4067- 7: width of fitted gauss - px
4069+ 7: width of fitted gauss in px
40684070 8: when was it last fitted
40694071 9: index in reference catalogue
40704072 10: wavelength from reference catalogue
@@ -4247,6 +4249,8 @@ def shift_wavelength_solution(params, aspectra, wave_sol_dict, reference_lines_d
42474249 objname_txt = objname.rsplit(os.sep,1)[-1] # If the name contains a / there will be a problem
42484250 fname = '{0}_{1}.{2}'.format(params['logging_em_lines_gauss_width_form'].rsplit('.',1)[0], objname_txt, params['logging_em_lines_gauss_width_form'].rsplit('.',1)[-1])
42494251 plot_wavelength_solution_width_emmission_lines(fname, ass, data_sub, [1,5,7]) # order at 1, pixel at 5, gauss width at 7
4252+ fname = '{0}_{1}.{2}'.format(params['logging_em_lines_shift'].rsplit('.',1)[0], objname_txt, params['logging_em_lines_shift'].rsplit('.',1)[-1])
4253+ plot_wavelength_solution_width_emmission_lines(fname, ass, data_sub, [1,5,6], title='Shift') # order at 1, pixel at 5, shift at 6
42504254 fname = '{0}_{1}.{2}'.format(params['logging_arc_line_identification_residuals_hist'].rsplit('.',1)[0], objname_txt, params['logging_arc_line_identification_residuals_hist'].rsplit('.',1)[-1])
42514255 plot_hist_residuals_wavesol(fname, data_sub, [1,5,2,6] ) # Order, pixel, wavelength, shift
42524256 fname = '{0}_{1}.{2}'.format(params['logging_em_lines_bisector'].rsplit('.',1)[0], objname_txt, params['logging_em_lines_bisector'].rsplit('.',1)[-1])
@@ -4863,6 +4867,7 @@ def invert_polyval(poly, xx, yy, poly0=0, prec=0.05):
48634867 :param yy: float, find the x-value to this value
48644868 :param poly0: zeropoint of the polynomial, to subtract from the xx values
48654869 :param prec: precision of the values in xx, standard: 50 milli-pixel
4870+ :return xx_inv:
48664871 """
48674872 yfit = np.polyval(poly, xx-poly0)
48684873 index = np.argmin(np.abs( yy - yfit ))
@@ -5478,7 +5483,6 @@ def save_single_files(params, obnames, im_name, im_head, im_head_bluefirst, spec
54785483 save_multispec(fspectra[::-1,:], params['path_extraction_single']+im_name+'_blaze_bluefirst', im_head_iraf_format_bluefirst, bitpix=params['extracted_bitpix'])
54795484 if doo.get('norm',False) and doo.get('blue',False):
54805485 save_multispec(cspectra[::-1,:], params['path_extraction_single']+im_name+'_norm_bluefirst', im_head_iraf_format_bluefirst, bitpix=params['extracted_bitpix'])
5481-
54825486 if doo.get('harps',False):
54835487 # Harps format
54845488 im_head_harps_format = copy.copy(im_head_bluefirst)
@@ -6318,11 +6322,11 @@ def plot_wavelength_solution_form(fname, traces_def, wavelength_solution):
63186322
63196323def plot_wavelength_solution_width_emmission_lines(fname, specs, data, indexes, step=20, title='Gaussian width'):
63206324 """
6321- Creates a map of the Gaussian width of the emmission lines
6325+ Creates a map of the Gaussian width of the emmission lines - Adapted so that other information than Gauss width can be plotted
63226326 :param fname: Filename to which the image is saved
63236327 :param specs: 1d list with two integers: shape of the extracted spectrum, first entry gives the number of orders and the second the number of pixel
63246328 :param data: 2d array of floats with the data to plot
6325- :param indexes: list of int, position of the relevant columns: order, wavelength , gauss
6329+ :param indexes: list of int, position of the relevant columns: order, pixel , gauss
63266330 """
63276331 [oo, xx, gg] = indexes
63286332 gauss_ima = np.empty((specs[0], int(specs[1]/step)+1)) * np.nan
@@ -6396,19 +6400,22 @@ def plot_wavelength_solution_spectrum(params, spec1, spec2, fname, wavelength_so
63966400 labels = ['long exp','short exp']
63976401 x_title = 'Wavelength [Angstroms]'
63986402 y_title = 'extracted flux [ADU]'
6399- titel_f = 'Order {0}, real Order {1}\nmarked (proportional to line strength) are the identified reference lines (red, {2} lines) and\na subset of the omitted reference lines (green, showing the brightes {3} out of {4} lines)'
6403+ titel_f = ('Order {0}, real Order {1}\nmarked (proportional to line strength) are' +\
6404+ ' the identified reference lines (red, {2} lines) and\n' +\
6405+ 'a subset of the omitted reference lines (green, showing the brightes {3} out of {4} lines)')
64006406
64016407 if plot_log:
64026408 y_title = 'log10 ( {0} )'.format(y_title)
64036409 spec1 = adjust_data_log(spec1)
64046410 spec2 = adjust_data_log(spec2)
64056411 reference_catalog = np.array(sorted(reference_catalog, key=operator.itemgetter(1), reverse=True )) # Sort by intensity in reverse order
6412+ xarr = np.arange(spec1.shape[1])
64066413 wavelengths, dummy = create_wavelengths_from_solution(params, wavelength_solution, spec1)
64076414 # multiple pdf pages from https://matplotlib.org/examples/pylab_examples/multipage_pdf.html
64086415 with PdfPages(fname) as pdf:
64096416 for order in range(wavelength_solution.shape[0]):
64106417 x_range = wavelengths[ order, ~np.isnan(spec1[order,:]) ]
6411- if len( x_range) < 10: # the reference trace cod fall completely out of the CCD
6418+ if x_range.shape[0] < 10: # the reference trace cod fall completely out of the CCD
64126419 continue
64136420 good_values = np.where((reference_catalog[:,0] >= np.min(x_range)) & (reference_catalog[:,0] <= np.max(x_range)) )[0] # lines in the right wavelength range
64146421 reference_lines = reference_catalog[good_values,:] # possible reference lines in the order
@@ -6465,6 +6472,22 @@ def plot_wavelength_solution_spectrum(params, spec1, spec2, fname, wavelength_so
64656472
64666473 axes.set_ylim(ymin,ymax)
64676474 axes.set_xlim(xmin-0.01*x_range,xmax+0.01*x_range)
6475+
6476+ # Add top x-axis
6477+ with warnings.catch_warnings():
6478+ warnings.simplefilter('ignore', np.RankWarning)
6479+ poly_inv = np.polyfit(wavelengths[order,:], xarr, wavelength_solution.shape[1]-2-1) # fit x(y), might cause rank warning,
6480+ def wave_to_px(wave):
6481+ """Convert wavelength to pixel"""
6482+ px = np.polyval(poly_inv, wave)
6483+ return px
6484+ def px_to_wave(px):
6485+ """Conver pixel to wavelength"""
6486+ wave = np.polyval(wavelength_solution[order, 2:], px - wavelength_solution[order,1])
6487+ return wave
6488+ secax_x = frame.secondary_xaxis('top', functions=(wave_to_px, px_to_wave))
6489+ #secax_x.set_xlabel('x [px]')
6490+
64686491 fig.set_size_inches(16.2, 10)
64696492 #plt.savefig('{0}.png'.format(order), bbox_inches='tight')
64706493 pdf.savefig() # saves the current figure into a pdf page
0 commit comments