Radial Profile from a .fits image - python

I have been trying to plot a radial profile of a fits image using a modified script I found on-line. I always get y axis units which are completely different to what's expected. I'm not even sure what the y axis units are. I have attached the fits file and a profile I keep getting and the correct radial profile I plotted using another program.
I am very new to python so I have no idea why this keeps happening. Any help to fix this will be so greatly appreciated.
This is the code I've been using:
import numpy as np
import pyfits
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
def azimuthalAverage(image, center=None):
"""
Calculate the azimuthally averaged radial profile.
image - The 2D image
center - The [x,y] pixel coordinates used as the center. The default is
None, which then uses the center of the image (including
fracitonal pixels).
"""
# Calculate the indices from the image
y, x = np.indices(image.shape)
if not center:
center = np.array([(x.max()-x.min())/2.0, (y.max()-y.min())/2.0])
r = np.hypot(x - center[0], y - center[1])
# Get sorted radii
ind = np.argsort(r.flat)
r_sorted = r.flat[ind]
i_sorted = image.flat[ind]
# Get the integer part of the radii (bin size = 1)
r_int = r_sorted.astype(int)
# Find all pixels that fall within each radial bin.
deltar = r_int[1:] - r_int[:-1] # Assumes all radii represented
rind = np.where(deltar)[1] # location of changed radius
nr = rind[1:] - rind[:-1] # number of radius bin
# Cumulative sum to figure out sums for each radius bin
csim = np.cumsum(i_sorted, dtype=float)
tbin = csim[rind[1:]] - csim[rind[:-1]]
radial_prof = tbin / nr
print center
print i_sorted
print radial_prof
return radial_prof
#read in image
hdulist = pyfits.open('cit6ndf2fitsexample.fits')
scidata = np.array(hdulist[0].data)[0,:,:]
center = None
radi = 10
rad = azimuthalAverage(scidata, center)
plt.xlabel('radius(pixels?)', fontsize=12)
plt.ylabel('image intensity', fontsize=12)
plt.xlim(0,10)
plt.ylim(0, 3.2)
plt.plot(rad[radi:])
plt.savefig('testfig1.png')
plt.show()
Profile with wrong y axis units
Profile with expected correct units created using Celtech Aperture Photometry Tool.

from astropy.io import fits
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import AutoMinorLocator
minorLocator = AutoMinorLocator()
def radial_profile(data, center):
x, y = np.indices((data.shape))
r = np.sqrt((x - center[0])**2 + (y - center[1])**2)
r = r.astype(np.int)
tbin = np.bincount(r.ravel(), data.ravel())
nr = np.bincount(r.ravel())
radialprofile = tbin / nr
return radialprofile
fitsFile = fits.open('testfig.fits')
img = fitsFile[0].data[0]
img[np.isnan(img)] = 0
#center = np.unravel_index(img.argmax(), img.shape)
center = (-fitsFile[0].header['LBOUND2']+1, -fitsFile[0].header['LBOUND1']+1)
rad_profile = radial_profile(img, center)
fig, ax = plt.subplots()
plt.plot(rad_profile[0:22], 'x-')
ax.xaxis.set_minor_locator(minorLocator)
plt.tick_params(which='both', width=2)
plt.tick_params(which='major', length=7)
plt.tick_params(which='minor', length=4, color='r')
plt.grid()
ax.set_ylabel(fitsFile[0].header['Label'] + " (" + fitsFile[0].header['BUNIT'] + ")")
ax.set_xlabel("Pixels")
plt.grid(which="minor")
plt.show()
EDIT:
I added a commented line for retrieving the center from the headers. But you would have to test more fits files before choosing to use argmax or the header info to find the center.
First part of the header info:
SIMPLE = T / file does conform to FITS standard
BITPIX = -64 / number of bits per data pixel
NAXIS = 3 / number of data axes
NAXIS1 = 259 / length of data axis 1
NAXIS2 = 261 / length of data axis 2
NAXIS3 = 1 / length of data axis 3
EXTEND = T / FITS dataset may contain extensions
COMMENT FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H
LBOUND1 = -133 / Pixel origin along axis 1
LBOUND2 = -128 / Pixel origin along axis 2
LBOUND3 = 1 / Pixel origin along axis 3
OBJECT = 'CIT 6 ' / Title of the dataset
LABEL = 'Flux Density' / Label of the primary array
BUNIT = 'mJy/arcsec**2' / Units of the primary array
DATE = '2015-12-18T06:45:40' / file creation date (YYYY-MM-DDThh:mm:ss UT)
ORIGIN = 'East Asian Observatory' / Origin of file
BSCALE = 1.0 / True_value = BSCALE * FITS_value + BZERO
BZERO = 0.0 / True_value = BSCALE * FITS_value + BZERO
HDUCLAS1= 'NDF ' / Starlink NDF (hierarchical n-dim format)
HDUCLAS2= 'DATA ' / Array component subclass
HDSTYPE = 'NDF ' / HDS data type of the component
TELESCOP= 'JCMT ' / Name of Telescope

Related

Resample (increase the pixel size) a satellite image using a Gaussian filter in Python

I have a satellite image (Landsat 8, panchromatic band) at 15m pixel size. My goal is to upscale the image (i.e., change the pixel size) at 460m using a Gaussian filter with sigma = 0.5. Is there a function in python that can do this (i.e., increase the pixel size using a Gaussian filter)? I don't have an example to show as I couldn't find how can I do this in python. Here is the image.
Check Pyresample it has resample_gauss
This function allows you to specify sigma, radius_of_influence and other parameters.
In your case as you want to decrease the resolution of the input image, you just need to define the output height and width based on the target resolution and the area extent.
Please check the above link for details.
Pyresample is best to do it, but it works with WGS only. Here is my implementation with pyresample, gdal and pyproj:
from osgeo import gdal, osr
import pyresample as pr
import numpy as np
from pyresample.geometry import AreaDefinition
import pyproj
# Get the initial details
file_in = "your_file.tif"
file_out = "output_file.tif"
new_res = 460.0
epsg = 7767 #EPSG of your tiff
radius_of_influence = new_res
pixel = 1
sigmas = new_res * pixel
# Open the raster
ds = gdal.Open(file_in, gdal.GA_ReadOnly)
rb_ = ds.GetRasterBand(1)
img_arr = rb_.ReadAsArray()
gt_ = ds.GetGeoTransform()
# Get raster dimension
x_min = gt_[0]
x_size = gt_[1]
y_min = gt_[3]
y_size = gt_[5]
x_max = x_min + np.shape(img_arr)[1] * x_size
y_max = y_min + np.shape(img_arr)[0] * y_size
area_extent_old = (x_min, y_max, x_max, y_min)
# Compute new dimensions
new_width = int((x_max - x_min) / new_res)
new_height = int((y_max - y_min) / new_res)
x_max_new = x_min + (new_width * new_res)
y_max_new = y_min + (new_height * new_res)
area_extent = (x_min, y_max_new, x_max_new, y_min)
# Compute the latitudes and longitudes mesh for Swath definition (only 4326 EPSG available)
x = np.linspace(x_min, x_max, np.shape(img_arr)[1])
y = np.linspace(y_min, y_max, np.shape(img_arr)[0])
xv, yv = np.meshgrid(x, y)
lats, lons = np.copy(xv), np.copy(yv)
to_proxy_transformer = pyproj.Transformer.from_crs(f"epsg:{epsg}", 'epsg:4326')
for i in range(np.shape(img_arr)[1]):
for j in range(np.shape(img_arr)[0]):
lats[j, i], lons[j, i] = to_proxy_transformer.transform(xv[j, i], yv[j, i])
# Define Area definition and Swath definition for pyresample
projection = f"+init=EPSG:{epsg}"
area_id = 'my_area'
description = 'somewhere'
proj_id = 'my_area'
swath_def = pr.geometry.SwathDefinition(lons=lons, lats=lats)
area_def = AreaDefinition(area_id, description, proj_id, projection, new_width, -new_height, area_extent)
# Perform the resampling
values = pr.kd_tree.resample_gauss(source_geo_def=swath_def, data=img_arr, target_geo_def=area_def, radius_of_influence=radius_of_influence, sigmas=sigmas, fill_value=False)
# Define new tif parameters
img_params_ = {}
img_params_["cols"] = values.shape[1]
img_params_["rows"] = values.shape[0]
img_params_["px_width"] = (area_def.area_extent[2] - area_def.area_extent[0]) / img_params_["cols"]
img_params_["px_height"] = (area_def.area_extent[1] - area_def.area_extent[3]) / img_params_["rows"]
img_params_["origin_x"] = area_def.area_extent[0]
img_params_["origin_y"] = area_def.area_extent[3]
# Write the geotiff file
driver = gdal.GetDriverByName("GTiff")
out_raster = driver.Create(file_out, img_params_["cols"], img_params_["rows"], 1, gdal.GDT_Float32)
out_raster.SetGeoTransform((img_params_["origin_x"], img_params_["px_width"], 0, img_params_["origin_y"], 0, img_params_["px_height"]))
out_band = out_raster.GetRasterBand(1)
out_band.SetNoDataValue(0.0)
out_band.WriteArray(np.array(values))
out_raster_srs = osr.SpatialReference()
out_raster_srs.ImportFromEPSG(epsg)
out_raster.SetProjection(out_raster_srs.ExportToWkt())
# Flush the memory
out_band.FlushCache()
out_band.ComputeStatistics(False)
out_band = None
out_raster = None

matplotlib bar plot looks cutoff

i have a list of values representing 8 distributions.
When i run this code:
for pidx in range(len(names)):
name = names[pidx]
ber = stm_df.loc[x, name].tolist()
mx_ber = max([mx_ber] + ber)
mn_ber = min([mn_ber] + ber)
ber[0] = 0
sr = pd.Series(ber,x)
sr = sr[sr > 0]
rect = axes[1].plot(sr.index, sr.values)
It looks as it should:
But, when i change from ".plot" to ".bar" they all look cutoff
Code:
for pidx in range(len(names)):
name = names[pidx]
ber = stm_df.loc[x, name].tolist()
mx_ber = max([mx_ber] + ber)
mn_ber = min([mn_ber] + ber)
ber[0] = 0
sr = pd.Series(ber,x)
sr = sr[sr > 0]
rect = axes[1].bar(sr.index, sr.values)
Results:
Everything else is the same.
What is going on?
If your goal is to color the area under your distribution curve, I would recommend using plt.fill_between as below.
# Color area under curve
from matplotlib import pyplot as plt
import numpy as np
# Get x values of the curve (a sine wave in this case)
time = np.arange(0, 10, 0.1);
# Amplitude of the sine wave across time
amplitude = np.sin(time)
# Plot a curve with time and amplitude
plt.plot(time, amplitude, color='black')
# title
plt.title('Sine wave')
# x axis label
plt.xlabel('Time')
# y axis label
plt.ylabel('Amplitude')
# add midline
plt.axhline(y=0, color='k')¨
# fill area between midline across time and amplitude
plt.fill_between(time, amplitude, color='cyan')
plt.show()
In your example, this would mean simply adding plt.fill_between(sr.index, sr.values, color=f'C{pidx}).
for pidx in range(len(names)):
name = names[pidx]
ber = stm_df.loc[x, name].tolist()
mx_ber = max([mx_ber] + ber)
mn_ber = min([mn_ber] + ber)
ber[0] = 0
sr = pd.Series(ber,x)
sr = sr[sr > 0]
rect = axes[1].plot(sr.index, sr.values)
plt.fill_between(sr.index, sr.values, color=f'C{pidx})
It is hard to say with the info at hand, but I believe that the height parameter of your bar() may not be properly configured. The height should be configured as the max point of each distribution.

python plot line link wrong point

As you can see matplotlib link few wrong points using plt.plot.
data file
How can I improve my curve ?
Can I give him the minimum interval beween two points ?
Will sorting my points help me get a good curve ?
I can sort my x-axis points but y-axis seems more complicated.
Thank you.
import numpy as np
from matplotlib import pyplot as plt
File = "crown" + str(0) + str(0.01)
data = np.loadtxt(File)
data = data.reshape((len(data),3))
print(data)
R0 = 10.
theta = np.arctan2(data[:,1],data[:,0]) #calcul of theta
print(theta)
Radius = np.sqrt(data[:,1]**2 + data[:,0]**2)
Mradius = Radius - np.mean(Radius)
Mradius = Mradius/R0
n = len(theta) # length
Radiushat = np.fft.fft(Mradius,n) #fft of the Radius
PSD = Radiushat * np.conj(Radiushat)/n #Power spectral density
delta = 0.0001
k = (1/(delta*n)) * np.arange(n) #wavenumber
indice = np.where(PSD==np.max(PSD)) #find position indice max PSD array
#print(k[indice][0]) #k_{max}
L = np.arange(1,np.floor(n/2), dtype='int')
# filtered the signal
"""
indices = PSD > np.max(PSD)/3.
PDSclean = PSD * indices
Radiushatclean = indices * Radiushat
ffilt = np.fft.ifft(Radiushatclean)"""
fig,axs = plt.subplots(2,1)
plt.sca(axs[0])
plt.plot(theta,Radius,label="Crown")
ticks = [-np.pi, -np.pi/2., 0, np.pi/2., np.pi]
ticks_labels = ['-π', '-π/2', '0', 'π/2', 'π']
plt.xticks(ticks, ticks_labels)
"""plt.plot(theta,ffilt, label="Filtered")"""
plt.xlabel("theta")
plt.ylabel("R/R(t=0)")
plt.legend()
plt.title('k_{max}=%.2f' % (k[indice][0]))
plt.sca(axs[1])
plt.plot(k[L],PSD[L]/np.max(PSD))
plt.xlim(0,k[L[-1]])
plt.xlabel("k")
plt.ylabel("PSD")
fig.tight_layout()
plt.show()

Problem with 2D mapping graphs using matplotlib

I am plotting 2D images of energy and density distribution. There is always a slight misalignment in the mapping where the very first "columns" seem to go to the last columns during the plot.
I have attach link to for data test file.
Data files
Here is the plot :
Is there anything to prevent this ?
The partial code in plotting is as follows:
import numpy as np
import matplotlib.pyplot as plt
import pylab as pyl
import scipy.stats as ss
import matplotlib.ticker as ticker
import matplotlib.transforms as tr
#%matplotlib inline
pi = 3.1415
n = 5e24 # density plasma
m = 9.109e-31
eps = 8.85e-12
e = 1.6021725e-19
c = 3e8
wp=np.sqrt(n*e*e/(m*eps))
kp = np.sqrt(n*e*e/(m*eps))/c #plasma wavenumber
case=400
## decide on the target range of analysis for multiples
start= 20500
end = 21500
gap = 1000
## Multiples plots
def target_range (start, end, gap):
while start<= end:
yield start
start += gap
for step in target_range(start, end, gap):
fdata =np.genfromtxt('./beam_{}'.format(step)).reshape(-1,6)
## dimension, dt, and superpaticle
xBoxsize = 50e-6 #window size
yBoxsize = 80e-6 #window size
xbind = 10
ybind = 1
dx = 4e-8 #cell size
dy = 4e-7 #cell size
dz = 1e-6 #assume to be same as dy
dt = 1.3209965456e-16
sptcl = 1.6e10
xsub = 0e-6
xmax = dt*step*c
xmin = xmax - xBoxsize
ysub = 1e-7
ymin = ysub #to make our view window
ymax = yBoxsize - ysub
xbins = int((xmax - xmin)/(dx*xbind))
ybins = int((ymax - ymin)/(dy*ybind))
#zbins = int((zmax - zmin)/dz) #option for 3D
# To make or define "data_arr" as a matrix with 2D array size 'xbins x ybins'
data_arr = np.zeros((2,xbins,ybins), dtype=np.float)
for line in fdata:
x = int((line[0]-xmin)/(dx*xbind))
y = int((line[1]-ymin)/(dy*ybind))
#z = int((line[2]-zmin)/dz)
if x >= xbins: x = xbins - 1
if y >= ybins: y = ybins - 1
#if z >= zbins: z = zbins - 1
data_arr[0, x, y] = data_arr[0,x, y] + 1 #cummulative adding up the number of particles
energy_total = np.sqrt(1+ line[2]*line[2]/(c*c)+line[3]*line[3]/(c*c))/0.511
data_arr[1, x, y] += energy_total
#array 1 tells us the energy while array 0 tells us the particles
## make average energy , total energy/particle number
np.errstate(divide='ignore',invalid='ignore')
en_arr = np.true_divide(data_arr[1],data_arr[0]) # total energy/number of particles
en_arr[en_arr == np.inf] = 0
en_arr = np.nan_to_num(en_arr)
en_arr = en_arr.T
## This part is real density of the distribution
data_arr[0]= data_arr[0] * sptcl/dx/dy #in m-3
d = data_arr[0].T
## Plot and save density and energy distribution figures
den_dist=plt.figure(1)
plt.imshow(d,origin='lower', aspect = 'auto',cmap =plt.get_cmap('gnuplot'),extent =(xmin/1e-3,xmax/1e-3,ymin/1e-6,ymax/1e-6))
plt.title('Density_dist [m-3]_{}'.format(step))
plt.xlabel('distance[mm]')
plt.ylabel('y [um]')
plt.colorbar()
plt.show()
den_dist.savefig("./Qen_distribution_{}.png".format(step),format ='png')
#note:cmap: rainbow, hot,jet,gnuplot,plasma
energy_dist=plt.figure(2)
plt.imshow(en_arr, origin ='lower',aspect = 'auto', cmap =plt.get_cmap('jet'),extent =(xmin/1e-3,xmax/1e-3,ymin/1e-6,ymax/1e-6))
plt.title ('Energy_dist [MeV]_{} '.format(step))
plt.xlabel('distance[mm]')
plt.ylabel('y [um]')
plt.colorbar()
plt.show()
energy_dist.savefig("./Qenergy_distribution_{}.png".format(step),format ='png')

Inverse Wavelet Transform [/xpost signalprocessing]

Main Problem: How can the scipy.signal.cwt() function be inversed.
I have seen where Matlab has an inverse continuous wavelet transform function which will return the original form of the data by inputting the wavelet transform, although you can filter out the slices you don't want.
MATALAB inverse cwt funciton
Since scipy doesn't appear to have the same function, I have been trying to figure out how to get the data back in the same form, while removing the noise and background.
How do I do this?
I tried squaring it to remove negative values, but this gives me values way to large and not quite right.
Here is what I have been trying:
# Compute the wavelet transform
widths = range(1,11)
cwtmatr = signal.cwt(xy['y'], signal.ricker, widths)
# Maybe we multiple by the original data? and square?
WT_to_original_data = (xy['y'] * cwtmatr)**2
And here is a fully compilable short script to show you the type of data I am trying to get and what I have etc.:
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
# Make some random data with peaks and noise
def make_peaks(x):
bkg_peaks = np.array(np.zeros(len(x)))
desired_peaks = np.array(np.zeros(len(x)))
# Make peaks which contain the data desired
# (Mid range/frequency peaks)
for i in range(0,10):
center = x[-1] * np.random.random() - x[0]
amp = 60 * np.random.random() + 10
width = 10 * np.random.random() + 5
desired_peaks += amp * np.e**(-(x-center)**2/(2*width**2))
# Also make background peaks (not desired)
for i in range(0,3):
center = x[-1] * np.random.random() - x[0]
amp = 40 * np.random.random() + 10
width = 100 * np.random.random() + 100
bkg_peaks += amp * np.e**(-(x-center)**2/(2*width**2))
return bkg_peaks, desired_peaks
x = np.array(range(0, 1000))
bkg_peaks, desired_peaks = make_peaks(x)
y_noise = np.random.normal(loc=30, scale=10, size=len(x))
y = bkg_peaks + desired_peaks + y_noise
xy = np.array( zip(x,y), dtype=[('x',float), ('y',float)])
# Compute the wavelet transform
# I can't figure out what the width is or does?
widths = range(1,11)
# Ricker is 2nd derivative of Gaussian
# (*close* to what *most* of the features are in my data)
# (They're actually Lorentzians and Breit-Wigner-Fano lines)
cwtmatr = signal.cwt(xy['y'], signal.ricker, widths)
# Maybe we multiple by the original data? and square?
WT = (xy['y'] * cwtmatr)**2
# plot the data and results
fig = plt.figure()
ax_raw_data = fig.add_subplot(4,3,1)
ax = {}
for i in range(0, 11):
ax[i] = fig.add_subplot(4,3, i+2)
ax_desired_transformed_data = fig.add_subplot(4,3,12)
ax_raw_data.plot(xy['x'], xy['y'], 'g-')
for i in range(0,10):
ax[i].plot(xy['x'], WT[i])
ax_desired_transformed_data.plot(xy['x'], desired_peaks, 'k-')
fig.tight_layout()
plt.show()
This script will output this image:
Where the first plot is the raw data, the middle plots are the wavelet transforms and the last plot is what I want to get out as the processed (background and noise removed) data.
Does anyone have any suggestions? Thank you so much for the help.
I ended up finding a package which provides an inverse wavelet transform function called mlpy. The function is mlpy.wavelet.uwt. This is the compilable script I ended up with which may interest people if they are trying to do noise or background removal:
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
import mlpy.wavelet as wave
# Make some random data with peaks and noise
############################################################
def gen_data():
def make_peaks(x):
bkg_peaks = np.array(np.zeros(len(x)))
desired_peaks = np.array(np.zeros(len(x)))
# Make peaks which contain the data desired
# (Mid range/frequency peaks)
for i in range(0,10):
center = x[-1] * np.random.random() - x[0]
amp = 100 * np.random.random() + 10
width = 10 * np.random.random() + 5
desired_peaks += amp * np.e**(-(x-center)**2/(2*width**2))
# Also make background peaks (not desired)
for i in range(0,3):
center = x[-1] * np.random.random() - x[0]
amp = 80 * np.random.random() + 10
width = 100 * np.random.random() + 100
bkg_peaks += amp * np.e**(-(x-center)**2/(2*width**2))
return bkg_peaks, desired_peaks
# make x axis
x = np.array(range(0, 1000))
bkg_peaks, desired_peaks = make_peaks(x)
avg_noise_level = 30
std_dev_noise = 10
size = len(x)
scattering_noise_amp = 100
scat_center = 100
scat_width = 15
scat_std_dev_noise = 100
y_scattering_noise = np.random.normal(scattering_noise_amp, scat_std_dev_noise, size) * np.e**(-(x-scat_center)**2/(2*scat_width**2))
y_noise = np.random.normal(avg_noise_level, std_dev_noise, size) + y_scattering_noise
y = bkg_peaks + desired_peaks + y_noise
xy = np.array( zip(x,y), dtype=[('x',float), ('y',float)])
return xy
# Random data Generated
#############################################################
xy = gen_data()
# Make 2**n amount of data
new_y, bool_y = wave.pad(xy['y'])
orig_mask = np.where(bool_y==True)
# wavelet transform parameters
levels = 8
wf = 'h'
k = 2
# Remove Noise first
# Wave transform
wt = wave.uwt(new_y, wf, k, levels)
# Matrix of the difference between each wavelet level and the original data
diff_array = np.array([(wave.iuwt(wt[i:i+1], wf, k)-new_y) for i in range(len(wt))])
# Index of the level which is most similar to original data (to obtain smoothed data)
indx = np.argmin(np.sum(diff_array**2, axis=1))
# Use the wavelet levels around this region
noise_wt = wt[indx:indx+1]
# smoothed data in 2^n length
new_y = wave.iuwt(noise_wt, wf, k)
# Background Removal
error = 10000
errdiff = 100
i = -1
iter_y_dict = {0:np.copy(new_y)}
bkg_approx_dict = {0:np.array([])}
while abs(errdiff)>=1*10**-24:
i += 1
# Wave transform
wt = wave.uwt(iter_y_dict[i], wf, k, levels)
# Assume last slice is lowest frequency (background approximation)
bkg_wt = wt[-3:-1]
bkg_approx_dict[i] = wave.iuwt(bkg_wt, wf, k)
# Get the error
errdiff = error - sum(iter_y_dict[i] - bkg_approx_dict[i])**2
error = sum(iter_y_dict[i] - bkg_approx_dict[i])**2
# Make every peak higher than bkg_wt
diff = (new_y - bkg_approx_dict[i])
peak_idxs_to_remove = np.where(diff>0.)[0]
iter_y_dict[i+1] = np.copy(new_y)
iter_y_dict[i+1][peak_idxs_to_remove] = np.copy(bkg_approx_dict[i])[peak_idxs_to_remove]
# new data without noise and background
new_y = new_y[orig_mask]
bkg_approx = bkg_approx_dict[len(bkg_approx_dict.keys())-1][orig_mask]
new_data = diff[orig_mask]
##############################################################
# plot the data and results
fig = plt.figure()
ax_raw_data = fig.add_subplot(121)
ax_WT = fig.add_subplot(122)
ax_raw_data.plot(xy['x'], xy['y'], 'g')
for bkg in bkg_approx_dict.values():
ax_raw_data.plot(xy['x'], bkg[orig_mask], 'k')
ax_WT.plot(xy['x'], new_data, 'y')
fig.tight_layout()
plt.show()
And here is the output I am getting now:
As you can see, there is still a problem with the background removal (it shifts to the right after each iteration), but it is a different question which I will address here.

Categories

Resources