Skip to content

Commit

Permalink
fix ghost
Browse files Browse the repository at this point in the history
  • Loading branch information
iltommi committed Jan 10, 2025
1 parent 391263c commit 531b4ad
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 109 deletions.
141 changes: 107 additions & 34 deletions plugins/Ghost_fringes/Ghost_fringes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,57 +67,139 @@ void Ghost_fringes::guessCarrier() {
}
}

// void Ghost_fringes::doGhost () {
// nPhysD *imageShot=getPhysFromCombo(shot);
// if (imageShot) {
// saveDefaults();

// QElapsedTimer timer;
// timer.start();

// unsigned int dx=imageShot->getW();
// unsigned int dy=imageShot->getH();

// physC imageFFT = imageShot->ft2(PHYS_FORWARD);
// std::vector<int> xx(dx), yy(dy);

// for (unsigned int i=0;i<dx;i++)
// xx[i]=(i+(dx+1)/2)%dx-(dx+1)/2; // swap and center
// for (unsigned int i=0;i<dy;i++)
// yy[i]=(i+(dy+1)/2)%dy-(dy+1)/2;

// double cr = cos((angleCarrier->value()) * _phys_deg);
// double sr = sin((angleCarrier->value()) * _phys_deg);

// // double lambda=sqrt(pow(cr*dx,2)+pow(sr*dy,2))/(M_PI*widthCarrier->value());
// double thick_norm= resolution->value()/M_PI;
// double lambda_norm=M_PI*widthCarrier->value()/sqrt(pow(cr*dx,2)+pow(sr*dy,2));
// // DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> " << lambda_norm << " " << thick_norm << " : " << sqrt(pow(cr*dx,2)+pow(sr*dy,2)));

// nPhysD *myfilter=new nPhysD(dx,dy,0.0,"Filter");
// nPhysD *myspectrum=new nPhysD(dx,dy,0.0,"Spectrum");
// for (unsigned int x=0;x<dx;x++) {
// for (unsigned int y=0;y<dy;y++) {
// double xr = xx[x]*cr - yy[y]*sr;
// double yr = xx[x]*sr + yy[y]*cr;
// // double e_tot = 1.0-exp(-pow(yr,2)/lambda)/(1.0+exp(lambda-std::abs(xr)));
// double e_tot = 1.0-exp(-pow(yr/thick_norm,2))*exp(-pow(std::abs(xr)*lambda_norm-M_PI, 2));
// myfilter->set(x,y,e_tot);
// myspectrum->set(x,y,imageFFT.point(x,y).mod());
// imageFFT.set(x,y,imageFFT.point(x,y) * e_tot);
// }
// }
// myfilter->TscanBrightness();
// myspectrum->TscanBrightness();
// myfilter->fftshift();
// myspectrum->fftshift();

// imageFFT = imageFFT.ft2(PHYS_BACKWARD);

// nPhysD *deepcopy=new nPhysD(*imageShot);
// deepcopy->setShortName("deghost");
// deepcopy->setName("deghost("+imageShot->getName()+")");

// QRect geom=maskRegion->path().boundingRect().toRect();



// QPolygonF regionPoly=maskRegion->poly(1);
// regionPoly=regionPoly.translated(imageShot->get_origin().x(),imageShot->get_origin().y());
// std::vector<vec2f> vecPoints(regionPoly.size());
// for(int k=0;k<regionPoly.size();k++) {
// vecPoints[k]=vec2f(regionPoly[k].x(),regionPoly[k].y());
// }

// for(int i=geom.left();i<geom.right(); i++) {
// for(int j=geom.top();j<geom.bottom(); j++) {
// vec2f pp(i,j);
// if (point_inside_poly(pp,vecPoints)==true) {
// deepcopy->set(i,j, imageFFT.point(i,j).mod()/(dx*dy));
// // deepcopy->set(i,j, imageFFT.point(i,j).real()/(dx*dy));
// }
// }
// }
// deepcopy->TscanBrightness();

// if (erasePrevious->isChecked()) {
// filter=nparent->replacePhys(myfilter,filter,true);
// spectrum=nparent->replacePhys(myspectrum,spectrum,true);
// ghostBusted=nparent->replacePhys(deepcopy,ghostBusted,true);
// } else {
// filter=myfilter;
// nparent->addShowPhys(filter);
// spectrum=myspectrum;
// nparent->addShowPhys(spectrum);
// ghostBusted=deepcopy;
// nparent->addShowPhys(ghostBusted);
// }

// erasePrevious->setEnabled(true);
// statusbar->showMessage(QString(tr("Time: %1 msec")).arg(timer.elapsed()));

// }
// }

void Ghost_fringes::doGhost () {
nPhysD *imageShot=getPhysFromCombo(shot);
if (imageShot) {
saveDefaults();

QElapsedTimer timer;
timer.start();
size_t dx=imageShot->getW();
size_t dy=imageShot->getH();

unsigned int dx=imageShot->getW();
unsigned int dy=imageShot->getH();

physC imageFFT = imageShot->ft2(PHYS_FORWARD);
std::vector<int> xx(dx), yy(dy);

for (unsigned int i=0;i<dx;i++)
for (size_t i=0;i<dx;i++)
xx[i]=(i+(dx+1)/2)%dx-(dx+1)/2; // swap and center
for (unsigned int i=0;i<dy;i++)
for (size_t i=0;i<dy;i++)
yy[i]=(i+(dy+1)/2)%dy-(dy+1)/2;

double cr = cos((angleCarrier->value()) * _phys_deg);
double sr = sin((angleCarrier->value()) * _phys_deg);

// double lambda=sqrt(pow(cr*dx,2)+pow(sr*dy,2))/(M_PI*widthCarrier->value());
double thick_norm= resolution->value()/M_PI;
double lambda_norm=M_PI*widthCarrier->value()/sqrt(pow(cr*dx,2)+pow(sr*dy,2));
// DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> " << lambda_norm << " " << thick_norm << " : " << sqrt(pow(cr*dx,2)+pow(sr*dy,2)));
double lambda=sqrt(pow(cr*dx,2)+pow(sr*dy,2))/(M_PI*widthCarrier->value());

DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << lambda);

nPhysD *myfilter=new nPhysD(dx,dy,0.0,"Filter");
nPhysD *myspectrum=new nPhysD(dx,dy,0.0,"Spectrum");
for (unsigned int x=0;x<dx;x++) {
for (unsigned int y=0;y<dy;y++) {

for (size_t x=0;x<dx;x++) {
for (size_t y=0;y<dy;y++) {
double xr = xx[x]*cr - yy[y]*sr;
double yr = xx[x]*sr + yy[y]*cr;
// double e_tot = 1.0-exp(-pow(yr,2)/lambda)/(1.0+exp(lambda-std::abs(xr)));
double e_tot = 1.0-exp(-pow(yr/thick_norm,2))*exp(-pow(std::abs(xr)*lambda_norm-M_PI, 2));
myfilter->set(x,y,e_tot);
myspectrum->set(x,y,imageFFT.point(x,y).mod());
double e_tot = 1.0-exp(-pow(yr,2))/(1.0+exp(lambda-std::abs(xr)));
imageFFT.set(x,y,imageFFT.point(x,y) * e_tot);
}
}
myfilter->TscanBrightness();
myspectrum->TscanBrightness();
myfilter->fftshift();
myspectrum->fftshift();

imageFFT = imageFFT.ft2(PHYS_BACKWARD);

nPhysD *deepcopy=new nPhysD(*imageShot);
deepcopy->setShortName("deghost");
deepcopy->setName("deghost("+imageShot->getName()+")");

QRect geom=maskRegion->path().boundingRect().toRect();


Expand All @@ -134,29 +216,20 @@ void Ghost_fringes::doGhost () {
vec2f pp(i,j);
if (point_inside_poly(pp,vecPoints)==true) {
deepcopy->set(i,j, imageFFT.point(i,j).mod()/(dx*dy));
// deepcopy->set(i,j, imageFFT.point(i,j).real()/(dx*dy));
}
}
}
deepcopy->TscanBrightness();

if (erasePrevious->isChecked()) {
filter=nparent->replacePhys(myfilter,filter,true);
spectrum=nparent->replacePhys(myspectrum,spectrum,true);
ghostBusted=nparent->replacePhys(deepcopy,ghostBusted,true);
} else {
filter=myfilter;
nparent->addShowPhys(filter);
spectrum=myspectrum;
nparent->addShowPhys(spectrum);
nparent->addShowPhys(deepcopy);
ghostBusted=deepcopy;
nparent->addShowPhys(ghostBusted);
}

erasePrevious->setEnabled(true);
statusbar->showMessage(QString(tr("Time: %1 msec")).arg(timer.elapsed()));

}
}
}


17 changes: 9 additions & 8 deletions plugins/Visar/Visar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ Visar::Visar(neutrino *parent) : nGenericPan(parent),
sopRect = new nRect(this,1);
sopRect->changeToolTip("SOP region");
sopRect->setRect(QRectF(0,0,100,100));
connect(actionRect3, SIGNAL(triggered()), sopRect, SLOT(togglePadella()));

connect(actionRect3, &QAction::triggered, sopRect, &nRect::togglePadella);
sopPlot->xAxis->setLabel(tr("Time"));
sopPlot->yAxis->setLabel(tr("Counts"));
sopPlot->yAxis2->setLabel(tr("Temperature"));
Expand Down Expand Up @@ -130,10 +129,10 @@ Visar::Visar(neutrino *parent) : nGenericPan(parent),
connect(actionCopy, SIGNAL(triggered()), this, SLOT(export_clipboard()));
connect(actionCopyImage, SIGNAL(triggered()), this, SLOT(copy_image()));

connect(etalon_thickness, SIGNAL(valueChanged(double)), this, SLOT(calculate_etalon()));
connect(etalon_dn_over_dlambda, SIGNAL(valueChanged(double)), this, SLOT(calculate_etalon()));
connect(etalon_n0, SIGNAL(valueChanged(double)), this, SLOT(calculate_etalon()));
connect(etalon_lambda, SIGNAL(valueChanged(double)), this, SLOT(calculate_etalon()));
connect(etalon_thickness, &QDoubleSpinBox::valueChanged, this, &Visar::calculate_etalon);
connect(etalon_dn_over_dlambda, &QDoubleSpinBox::valueChanged, this, &Visar::calculate_etalon);
connect(etalon_n0, &QDoubleSpinBox::valueChanged, this, &Visar::calculate_etalon);
connect(etalon_lambda, &QDoubleSpinBox::valueChanged, this, &Visar::calculate_etalon);

connect(nparent, SIGNAL(bufferChanged(nPhysD*)), this, SLOT(setObjectVisibility(nPhysD*)));

Expand Down Expand Up @@ -432,12 +431,14 @@ void Visar::calculate_etalon() {
double c=_phys_cspeed;

double delta= -1e-3*lam*n0/(n0*n0-1)*dn_dl;
double deplace= e*(1-1/n0);
double tau=2*e/c*(n0-1.0/n0);

double sens=lam*1e-9/(2*tau*(1+delta)); // km/s

qDebug() << "delta tau sens" << delta << tau << sens;
etalon_sensitivity->setValue(sens);
qDebug() << "delta tau sens deplace" << delta << tau << sens << deplace;
visar_sensitivity->setText(QString::number(sens));
mirror_displacement->setText(QString::number(deplace));

}

Expand Down
Loading

0 comments on commit 531b4ad

Please sign in to comment.