コード例 #1
0
ファイル: InstrumentFrame.cpp プロジェクト: DukhangLee/SKIRT
void InstrumentFrame::calibrateAndWriteDataFrames(int ell, QList<Array*> farrays, QStringList fnames)
{
    PeerToPeerCommunicator* comm = find<PeerToPeerCommunicator>();
    if (!comm->isRoot()) return;

    Units* units = find<Units>();
    WavelengthGrid* lambdagrid = find<WavelengthGrid>();

    // conversion from bolometric luminosities (units W) to monochromatic luminosities (units W/m)
    // --> divide by delta-lambda
    double dlambda = lambdagrid->dlambda(ell);

    // correction for the area of the pixels of the images; the units are now W/m/sr
    // --> divide by area
    double xpresang = 2.0*atan(_xpres/(2.0*_distance));
    double ypresang = 2.0*atan(_ypres/(2.0*_distance));
    double area = xpresang*ypresang;

    // calibration step 3: conversion of the flux per pixel from monochromatic luminosity units (W/m/sr)
    // to flux density units (W/m3/sr) by taking into account the distance
    // --> divide by fourpid2
    double fourpid2 = 4.0*M_PI*_distance*_distance;

    // conversion from program SI units (at this moment W/m3/sr) to the correct output units
    // --> multiply by unit conversion factor
    double unitfactor = units->osurfacebrightness(lambdagrid->lambda(ell), 1.);

    // perform the conversion, in place
    foreach (Array* farr, farrays)
    {
        (*farr) *= (unitfactor / (dlambda * area * fourpid2));
    }

    // write a FITS file for each array
    for (int q = 0; q < farrays.size(); q++)
    {
        QString filename = find<FilePaths>()->output(_instrument->instrumentName()
                                                     + "_" + fnames[q] + "_" + QString::number(ell) + ".fits");
        find<Log>()->info("Writing " + fnames[q] + " flux " + QString::number(ell)
                                                     + " to FITS file " + filename + "...");
        FITSInOut::write(filename, *(farrays[q]), _Nxp, _Nyp, 1,
                       units->olength(_xpres), units->olength(_ypres),
                       units->usurfacebrightness(), units->ulength());
    }
}
コード例 #2
0
ファイル: SED.cpp プロジェクト: wsaftly/SKIRT-1
void SED::write(const QString& filename) const
{
    WavelengthGrid* lambdagrid = find<WavelengthGrid>();
    Units* units = find<Units>();

    ofstream file(filename.toLocal8Bit().constData());
    file << setprecision(8) << scientific;
    for (int ell=0; ell<lambdagrid->Nlambda(); ell++)
    {
        double lambda = lambdagrid->lambda(ell);
        double dlambda = lambdagrid->dlambda(ell);
        file << units->owavelength(lambda)
             << '\t'
             << _Lv[ell]/dlambda*lambda
             << endl;
    }
    file.close();
}
コード例 #3
0
ファイル: PanDustSystem.cpp プロジェクト: DukhangLee/SKIRT
Array PanDustSystem::meanintensityv(int m) const
{
    WavelengthGrid* lambdagrid = find<WavelengthGrid>();
    Array Jv(lambdagrid->Nlambda());
    double fac = 4.0*M_PI*volume(m);
    for (int ell=0; ell<lambdagrid->Nlambda(); ell++)
    {
        double kappaabsrho = 0.0;
        for (int h=0; h<_Ncomp; h++)
        {
            double kappaabs = mix(h)->kappaabs(ell);
            double rho = density(m,h);
            kappaabsrho += kappaabs*rho;
        }
        double J = Labs(m,ell) / (kappaabsrho*fac) / lambdagrid->dlambda(ell);
        // guard against (rare) situations where both Labs and kappa*fac are zero
        Jv[ell] = std::isfinite(J) ? J : 0.0;
    }
    return Jv;
}
コード例 #4
0
ファイル: InstrumentFrame.cpp プロジェクト: djsavic/SKIRT
void InstrumentFrame::calibrateAndWriteDataFrames(int ell, QList<Array*> farrays, QStringList fnames)
{
    Units* units = find<Units>();
    WavelengthGrid* lambdagrid = find<WavelengthGrid>();

    // conversion from bolometric luminosities (units W) to monochromatic luminosities (units W/m)
    // --> divide by delta-lambda
    double dlambda = lambdagrid->dlambda(ell);

    // correction for the area of the pixels of the images; the units are now W/m/sr
    // --> divide by area
    double xpresang = 2.0*atan(_xpres/(2.0*_distance));
    double ypresang = 2.0*atan(_ypres/(2.0*_distance));
    double area = xpresang*ypresang;

    // calibration step 3: conversion of the flux per pixel from monochromatic luminosity units (W/m/sr)
    // to flux density units (W/m3/sr) by taking into account the distance
    // --> divide by fourpid2
    double fourpid2 = 4.0*M_PI*_distance*_distance;

    // conversion from program SI units (at this moment W/m3/sr) to the correct output units
    // --> multiply by unit conversion factor
    double unitfactor = units->osurfacebrightness(lambdagrid->lambda(ell), 1.);

    // Perform the conversion, in place
    foreach (Array* farr, farrays)
    {
        (*farr) *= (unitfactor / (dlambda * area * fourpid2));
    }

    // Write a FITS file for each array
    for (int q = 0; q < farrays.size(); q++)
    {
        QString filename = _instrument->instrumentName() + "_" + fnames[q] + "_" + QString::number(ell);
        QString description = fnames[q] + " flux " + QString::number(ell);

        // Create the image and save it
        Image image(this, _Nxp, _Nyp, 1, _xpres, _ypres, "surfacebrightness");
        image.saveto(this, *(farrays[q]), filename, description);
    }
}
コード例 #5
0
void PerspectiveInstrument::write()
{
    Units* units = find<Units>();
    WavelengthGrid* lambdagrid = find<WavelengthGrid>();
    int Nlambda = find<WavelengthGrid>()->Nlambda();

    // Put the data cube in a list of f-array pointers, as the sumResults function requires
    QList< Array* > farrays;
    farrays << &_ftotv;

    // Sum the flux arrays element-wise across the different processes
    sumResults(farrays);

    // Multiply each sample by lambda/dlamdba and by the constant factor 1/(4 pi s^2)
    // to obtain the surface brightness and convert to output units (such as W/m2/arcsec2)

    double front = 1. / (4.*M_PI*_s*_s);
    for (int ell=0; ell<Nlambda; ell++)
    {
        double lambda = lambdagrid->lambda(ell);
        double dlambda = lambdagrid->dlambda(ell);
        for (int i=0; i<_Nx; i++)
        {
            for (int j=0; j<_Ny; j++)
            {
                int m = i + _Nx*j + _Nx*_Ny*ell;
                _ftotv[m] = units->osurfacebrightness(lambda, _ftotv[m]*front/dlambda);
            }
        }
    }

    // Write a FITS file containing the data cube

    QString filename = _instrumentname + "_total";
    Image image(this, _Nx, _Ny, Nlambda, _s, _s, "surfacebrightness");
    image.saveto(this, _ftotv, filename, "total flux");
}
コード例 #6
0
void SingleFrameInstrument::calibrateAndWriteDataCubes(QList< Array*> farrays, QStringList fnames)
{
    WavelengthGrid* lambdagrid = find<WavelengthGrid>();
    int Nlambda = lambdagrid->Nlambda();

    // calibration step 1: conversion from bolometric luminosities (units W) to monochromatic luminosities (units W/m)

    for (int ell=0; ell<Nlambda; ell++)
    {
        double dlambda = lambdagrid->dlambda(ell);
        for (int i=0; i<_Nxp; i++)
        {
            for (int j=0; j<_Nyp; j++)
            {
                int m = i + _Nxp*j + _Nxp*_Nyp*ell;
                foreach (Array* farr, farrays)
                {
                    (*farr)[m] /= dlambda;
                }
            }
        }
    }

    // calibration step 2: correction for the area of the pixels of the images; the units are now W/m/sr

    double xpresang = 2.0*atan(_xpres/(2.0*_distance));
    double ypresang = 2.0*atan(_ypres/(2.0*_distance));
    double area = xpresang*ypresang;
    foreach (Array* farr, farrays)
    {
        (*farr) /= area;
    }

    // calibration step 3: conversion of the flux per pixel from monochromatic luminosity units (W/m/sr)
    // to flux density units (W/m3/sr) by taking into account the distance

    double fourpid2 = 4.0*M_PI*_distance*_distance;
    foreach (Array* farr, farrays)
    {
        (*farr) /= fourpid2;
    }

    // conversion from program SI units (at this moment W/m3/sr) to the correct output units;
    // we use lambda*flambda for the surface brightness (in units like W/m2/arcsec2)

    Units* units = find<Units>();
    for (int ell=0; ell<Nlambda; ell++)
    {
        double lambda = lambdagrid->lambda(ell);
        for (int i=0; i<_Nxp; i++)
        {
            for (int j=0; j<_Nyp; j++)
            {
                int m = i + _Nxp*j + _Nxp*_Nyp*ell;
                foreach (Array* farr, farrays)
                {
                    (*farr)[m] = units->obolsurfacebrightness(lambda*(*farr)[m]);
                }
            }
        }
    }