private void ExportMagnitudes(FilterResponse filterResponse, List<AbsFluxSpectra> spectra, List<AbsFluxSpectra> standardSpectras, StringBuilder output)
        {
            EnsureReferenceSums(filterResponse, standardSpectras);

            output.Append(filterResponse.Designation);
            for (int j = 0; j < spectra.Count; j++)
            {
                output.Append(",");
                double magError;
                double syntheticMag = ComputeSyntheticMag(filterResponse, spectra[j], out magError);
                output.Append(syntheticMag.ToString("0.000") + " +/- " + magError.ToString("0.000"));
            }
            output.AppendLine();
        }
        private double ComputeSyntheticMag(FilterResponse filterResponse, AbsFluxSpectra spectra, out double magError)
        {
            double targetSum = 0;
            double prevNonNaNVal = 0;

            foreach (int wavelength in filterResponse.Response.Keys)
            {
                double responseCoeff = filterResponse.Response[wavelength];

                double targetVal = InterpolateValue(spectra.ResolvedWavelengths, spectra.AbsoluteFluxes, wavelength);
                if (!double.IsNaN(targetVal)) prevNonNaNVal = targetVal;

                targetSum += prevNonNaNVal * responseCoeff;
            }

            var allMags = new List<double>();
            foreach (double conv in m_SynthetizedReferneceFluxMagnitudes.Keys)
            {
                double mag = m_SynthetizedReferneceFluxMagnitudes[conv] + 2.5 * Math.Log10(conv / targetSum);
                allMags.Add(mag);
            }

            // First itteration
            double averageMag = allMags.Average();
            double threeSigma = 3 * Math.Sqrt(allMags.Select(x => (averageMag - x) * (averageMag - x)).Sum()) / (allMags.Count - 1);
            allMags = allMags.Where(x => (Math.Abs(x - averageMag) <= threeSigma)).ToList();

            // Second itteration after removing outliers
            averageMag = allMags.Average();
            magError = m_AverageAbsFluxFitMagError + Math.Sqrt(allMags.Select(x => (averageMag - x) * (averageMag - x)).Sum()) / (allMags.Count - 1);
            return averageMag;
        }
Exemple #3
0
        private double GetReferenceMagnitude(FilterResponse filterResponse, CalSpecStar star)
        {
            switch (filterResponse.Band)
            {
            case PhotometricBand.B:
                return(star.MagB);

            case PhotometricBand.V:
                return(star.MagV);

            case PhotometricBand.R:
                return(star.MagR);

            case PhotometricBand.Sloan_g:
                return(star.Mag_g);

            case PhotometricBand.Sloan_r:
                return(star.Mag_r);

            case PhotometricBand.Sloan_i:
                return(star.Mag_i);

            default:
                return(star.MagV);
            }
        }
Exemple #4
0
 private void SaveFilterResponse(FilterResponse data, BinaryWriter wrt)
 {
     wrt.Write(data.Designation);
     wrt.Write(data.Response.Count);
     foreach (int key in data.Response.Keys)
     {
         wrt.Write(key);
         wrt.Write(data.Response[key]);
     }
 }
Exemple #5
0
        private void EnsureReferenceSums(FilterResponse filterResponse, List <AbsFluxSpectra> standardSpectras)
        {
            m_SynthetizedReferneceFluxMagnitudes.Clear();
            var standardAbsFluxFitMagErrors = new List <double>();

            foreach (CalSpecStar star in CalSpecDatabase.Instance.Stars)
            {
                AbsFluxSpectra fittedSpectra = standardSpectras.FirstOrDefault(x => x.m_CalSpecStar.CalSpecStarId == star.CalSpecStarId);
                if (fittedSpectra == null)
                {
                    continue;
                }

                List <double> wavelengths = fittedSpectra.ResolvedWavelengths;
                List <double> fluxes      = fittedSpectra.AbsoluteFluxes;
                List <double> residuals   = fittedSpectra.Residuals;

                double referenceSum  = 0;
                double prevNonNaNVal = 0;

                double residualSum           = 0;
                double prevNonNaNResidualVal = 0;

                foreach (int wavelength in filterResponse.Response.Keys)
                {
                    double responseCoeff = filterResponse.Response[wavelength];

                    double val = InterpolateValue(wavelengths, fluxes, wavelength);

                    if (!double.IsNaN(val))
                    {
                        prevNonNaNVal = val;
                    }
                    referenceSum += prevNonNaNVal * responseCoeff;

                    double residualVal = InterpolateValue(wavelengths, residuals, wavelength);

                    if (!double.IsNaN(residualVal))
                    {
                        prevNonNaNResidualVal = residualVal;
                    }
                    residualSum += prevNonNaNResidualVal * responseCoeff;
                }

                standardAbsFluxFitMagErrors.Add(Math.Abs(Math.Log10((referenceSum + residualSum) / referenceSum)));

                m_SynthetizedReferneceFluxMagnitudes.Add(referenceSum, GetReferenceMagnitude(filterResponse, star));
            }

            // NOTE: Is this a good way to estimate the error?
            m_AverageAbsFluxFitMagError = standardAbsFluxFitMagErrors.Average();             // / Math.Sqrt(standardAbsFluxFitMagErrors.Count);
        }
Exemple #6
0
        private void ExportMagnitudes(FilterResponse filterResponse, List <AbsFluxSpectra> spectra, List <AbsFluxSpectra> standardSpectras, StringBuilder output)
        {
            EnsureReferenceSums(filterResponse, standardSpectras);

            output.Append(filterResponse.Designation);
            for (int j = 0; j < spectra.Count; j++)
            {
                output.Append(",");
                double magError;
                double syntheticMag = ComputeSyntheticMag(filterResponse, spectra[j], out magError);
                output.Append(syntheticMag.ToString("0.000") + " +/- " + magError.ToString("0.000"));
            }
            output.AppendLine();
        }
Exemple #7
0
        private FilterResponseDatabase(BinaryReader reader)
        {
            Johnson_V = LoadFilterResponse(reader);
            Johnson_B = LoadFilterResponse(reader);
            Johnson_R = LoadFilterResponse(reader);
            Johnson_U = LoadFilterResponse(reader);
            Johnson_I = LoadFilterResponse(reader);

            SLOAN_u = LoadFilterResponse(reader);
            SLOAN_g = LoadFilterResponse(reader);
            SLOAN_r = LoadFilterResponse(reader);
            SLOAN_i = LoadFilterResponse(reader);
            SLOAN_z = LoadFilterResponse(reader);
        }
Exemple #8
0
        private FilterResponse LoadFilterResponse(BinaryReader rdr)
        {
            var rv = new FilterResponse();

            rv.Designation = rdr.ReadString();
            int count = rdr.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                int    wavelength = rdr.ReadInt32();
                double response   = rdr.ReadDouble();

                rv.Response.Add(wavelength, response);
            }

            return(rv);
        }
Exemple #9
0
        private double ComputeSyntheticMag(FilterResponse filterResponse, AbsFluxSpectra spectra, out double magError)
        {
            double targetSum     = 0;
            double prevNonNaNVal = 0;

            foreach (int wavelength in filterResponse.Response.Keys)
            {
                double responseCoeff = filterResponse.Response[wavelength];

                double targetVal = InterpolateValue(spectra.ResolvedWavelengths, spectra.AbsoluteFluxes, wavelength);
                if (!double.IsNaN(targetVal))
                {
                    prevNonNaNVal = targetVal;
                }

                targetSum += prevNonNaNVal * responseCoeff;
            }

            var allMags = new List <double>();

            foreach (double conv in m_SynthetizedReferneceFluxMagnitudes.Keys)
            {
                double mag = m_SynthetizedReferneceFluxMagnitudes[conv] + 2.5 * Math.Log10(conv / targetSum);
                allMags.Add(mag);
            }

            // First itteration
            double averageMag = allMags.Average();
            double threeSigma = 3 * Math.Sqrt(allMags.Select(x => (averageMag - x) * (averageMag - x)).Sum()) / (allMags.Count - 1);

            allMags = allMags.Where(x => (Math.Abs(x - averageMag) <= threeSigma)).ToList();

            // Second itteration after removing outliers
            averageMag = allMags.Average();
            magError   = m_AverageAbsFluxFitMagError + Math.Sqrt(allMags.Select(x => (averageMag - x) * (averageMag - x)).Sum()) / (allMags.Count - 1);
            return(averageMag);
        }
        private void EnsureReferenceSums(FilterResponse filterResponse, List<AbsFluxSpectra> standardSpectras)
        {
            m_SynthetizedReferneceFluxMagnitudes.Clear();
            var standardAbsFluxFitMagErrors = new List<double>();

            foreach (CalSpecStar star in CalSpecDatabase.Instance.Stars)
            {
                AbsFluxSpectra fittedSpectra = standardSpectras.FirstOrDefault(x => x.m_CalSpecStar.CalSpecStarId == star.CalSpecStarId);
                if (fittedSpectra == null) continue;

                List<double> wavelengths = fittedSpectra.ResolvedWavelengths;
                List<double> fluxes = fittedSpectra.AbsoluteFluxes;
                List<double> residuals = fittedSpectra.Residuals;

                double referenceSum = 0;
                double prevNonNaNVal = 0;

                double residualSum = 0;
                double prevNonNaNResidualVal = 0;

                foreach (int wavelength in filterResponse.Response.Keys)
                {
                    double responseCoeff = filterResponse.Response[wavelength];

                    double val = InterpolateValue(wavelengths, fluxes, wavelength);

                    if (!double.IsNaN(val)) prevNonNaNVal = val;
                    referenceSum += prevNonNaNVal * responseCoeff;

                    double residualVal = InterpolateValue(wavelengths, residuals, wavelength);

                    if (!double.IsNaN(residualVal)) prevNonNaNResidualVal = residualVal;
                    residualSum += prevNonNaNResidualVal * responseCoeff;
                }

                standardAbsFluxFitMagErrors.Add(Math.Abs(Math.Log10((referenceSum + residualSum)/referenceSum)));

                m_SynthetizedReferneceFluxMagnitudes.Add(referenceSum, GetReferenceMagnitude(filterResponse, star));
            }

            // NOTE: Is this a good way to estimate the error?
            m_AverageAbsFluxFitMagError = standardAbsFluxFitMagErrors.Average(); // / Math.Sqrt(standardAbsFluxFitMagErrors.Count);
        }
 private double GetReferenceMagnitude(FilterResponse filterResponse, CalSpecStar star)
 {
     switch (filterResponse.Band)
     {
         case PhotometricBand.B:
             return star.MagB;
         case PhotometricBand.V:
             return star.MagV;
         case PhotometricBand.R:
             return star.MagR;
         case PhotometricBand.Sloan_g:
             return star.Mag_g;
         case PhotometricBand.Sloan_r:
             return star.Mag_r;
         case PhotometricBand.Sloan_i:
             return star.Mag_i;
         default:
             return star.MagV;
     }
 }
        private FilterResponseDatabase(BinaryReader reader)
        {
            Johnson_V = LoadFilterResponse(reader);
            Johnson_B = LoadFilterResponse(reader);
            Johnson_R = LoadFilterResponse(reader);
            Johnson_U = LoadFilterResponse(reader);
            Johnson_I = LoadFilterResponse(reader);

            SLOAN_u = LoadFilterResponse(reader);
            SLOAN_g = LoadFilterResponse(reader);
            SLOAN_r = LoadFilterResponse(reader);
            SLOAN_i = LoadFilterResponse(reader);
            SLOAN_z = LoadFilterResponse(reader);
        }
 private void SaveFilterResponse(FilterResponse data, BinaryWriter wrt)
 {
     wrt.Write(data.Designation);
     wrt.Write(data.Response.Count);
     foreach (int key in data.Response.Keys)
     {
         wrt.Write(key);
         wrt.Write(data.Response[key]);
     }
 }
        private FilterResponse LoadFilterResponse(BinaryReader rdr)
        {
            var rv = new FilterResponse();
            rv.Designation = rdr.ReadString();
            int count = rdr.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                int wavelength = rdr.ReadInt32();
                double response = rdr.ReadDouble();

                rv.Response.Add(wavelength, response);
            }

            return rv;
        }