Example usage for org.apache.commons.math3.exception.util DummyLocalizable DummyLocalizable

List of usage examples for org.apache.commons.math3.exception.util DummyLocalizable DummyLocalizable

Introduction

In this page you can find the example usage for org.apache.commons.math3.exception.util DummyLocalizable DummyLocalizable.

Prototype

public DummyLocalizable(final String source) 

Source Link

Document

Simple constructor.

Usage

From source file:de.netsat.orekit.util.ZipJarCrawler.java

/** {@inheritDoc} */
public boolean feed(final Pattern supported, final DataLoader visitor) throws OrekitException {

    try {//ww  w .  j a  va  2  s  . c o  m

        // open the raw data stream
        Archive archive = null;
        ;
        try {
            if (file != null) {
                archive = new Archive(new FileInputStream(file));
            } else if (resource != null) {
                archive = new Archive(classLoader.getResourceAsStream(resource));
            } else {
                archive = new Archive(url.openConnection().getInputStream());
            }

            return feed(name, supported, visitor, archive);

        } finally {
            if (archive != null) {
                archive.close();
            }
        }

    } catch (IOException ioe) {
        throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
    } catch (ParseException pe) {
        throw new OrekitException(pe, new DummyLocalizable(pe.getMessage()));
    }

}

From source file:edu.stanford.cfuller.imageanalysistools.fitting.GaussianImageObject.java

/**
 * Fits this object to a 3-dimensional gaussian, and estimates error and goodness of fit.
 * @param p     The parameters for the current analysis.
 *///w w  w .  j  a va 2 s  . c  o  m
public void fitPosition(ParameterDictionary p) {

    if (this.sizeInPixels == 0) {
        this.nullifyImages();
        return;
    }

    this.fitParametersByChannel = new java.util.ArrayList<FitParameters>();
    this.fitR2ByChannel = new java.util.ArrayList<Double>();
    this.fitErrorByChannel = new java.util.ArrayList<Double>();
    this.nPhotonsByChannel = new java.util.ArrayList<Double>();

    GaussianFitter3D gf = new GaussianFitter3D();

    //System.out.println(this.parent.getDimensionSizes().getZ());

    int numChannels = 0;

    if (p.hasKey(NUM_WAVELENGTHS_PARAM)) {
        numChannels = p.getIntValueForKey(NUM_WAVELENGTHS_PARAM);
    } else {
        numChannels = this.parent.getDimensionSizes().get(ImageCoordinate.C);
    }

    for (int channelIndex = 0; channelIndex < numChannels; channelIndex++) {

        RealVector fitParameters = new ArrayRealVector(7, 0.0);

        double ppg = p.getDoubleValueForKey(PHOTONS_PER_LEVEL_PARAM);

        this.parentBoxMin.set(ImageCoordinate.C, channelIndex);
        this.parentBoxMax.set(ImageCoordinate.C, channelIndex + 1);

        this.boxImages();

        List<Double> x = new java.util.ArrayList<Double>();
        List<Double> y = new java.util.ArrayList<Double>();
        List<Double> z = new java.util.ArrayList<Double>();
        List<Double> f = new java.util.ArrayList<Double>();

        for (ImageCoordinate ic : this.parent) {
            x.add((double) ic.get(ImageCoordinate.X));
            y.add((double) ic.get(ImageCoordinate.Y));
            z.add((double) ic.get(ImageCoordinate.Z));
            f.add((double) parent.getValue(ic));
        }

        xValues = new double[x.size()];
        yValues = new double[y.size()];
        zValues = new double[z.size()];
        functionValues = new double[f.size()];

        double xCentroid = 0;
        double yCentroid = 0;
        double zCentroid = 0;
        double totalCounts = 0;

        for (int i = 0; i < x.size(); i++) {

            xValues[i] = x.get(i);
            yValues[i] = y.get(i);
            zValues[i] = z.get(i);
            functionValues[i] = f.get(i) * ppg;
            xCentroid += xValues[i] * functionValues[i];
            yCentroid += yValues[i] * functionValues[i];
            zCentroid += zValues[i] * functionValues[i];
            totalCounts += functionValues[i];
        }

        xCentroid /= totalCounts;
        yCentroid /= totalCounts;
        zCentroid /= totalCounts;

        //z sometimes seems to be a bit off... trying (20110415) to go back to max value pixel at x,y centroid

        int xRound = (int) Math.round(xCentroid);
        int yRound = (int) Math.round(yCentroid);

        double maxVal = 0;
        int maxInd = 0;

        double minZ = Double.MAX_VALUE;
        double maxZ = 0;

        for (int i = 0; i < x.size(); i++) {

            if (zValues[i] < minZ)
                minZ = zValues[i];
            if (zValues[i] > maxZ)
                maxZ = zValues[i];

            if (xValues[i] == xRound && yValues[i] == yRound) {
                if (functionValues[i] > maxVal) {
                    maxVal = functionValues[i];
                    maxInd = (int) zValues[i];
                }
            }
        }

        zCentroid = maxInd;

        //parameter ordering: amplitude, var x-y, var z, x/y/z coords, background

        //amplitude: find the max value; background: find the min value

        double maxValue = 0;

        double minValue = Double.MAX_VALUE;

        for (ImageCoordinate ic : this.parent) {

            if (parent.getValue(ic) > maxValue)
                maxValue = parent.getValue(ic);
            if (parent.getValue(ic) < minValue)
                minValue = parent.getValue(ic);

        }

        fitParameters.setEntry(0, (maxValue - minValue) * 0.95);
        fitParameters.setEntry(6, minValue + 0.05 * (maxValue - minValue));

        //positions

        fitParameters.setEntry(3, xCentroid);
        fitParameters.setEntry(4, yCentroid);
        fitParameters.setEntry(5, zCentroid);

        //variances

        final double limitedWidthxy = 200;
        final double limitedWidthz = 500;

        double sizex = limitedWidthxy / p.getDoubleValueForKey(PIXELSIZE_PARAM);
        double sizez = limitedWidthz / p.getDoubleValueForKey(SECTIONSIZE_PARAM);

        if (p.hasKey(Z_WIDTH_PARAM)) {
            sizez = p.getDoubleValueForKey(Z_WIDTH_PARAM);
        }

        if (p.hasKey(XY_WIDTH_PARAM)) {
            sizex = p.getDoubleValueForKey(XY_WIDTH_PARAM);
        }

        fitParameters.setEntry(1, sizex / 2);
        fitParameters.setEntry(2, sizez / 2);

        //amplitude and background are in arbitrary intensity units; convert to photon counts

        fitParameters.setEntry(0, fitParameters.getEntry(0) * ppg);
        fitParameters.setEntry(6, fitParameters.getEntry(6) * ppg);

        //System.out.println("guess: " + fitParameters);

        //do the fit

        fitParameters = gf.fit(this, fitParameters, ppg);

        //System.out.println("fit: " + fitParameters);

        FitParameters fp = new FitParameters();

        fp.setPosition(ImageCoordinate.X, fitParameters.getEntry(3));
        fp.setPosition(ImageCoordinate.Y, fitParameters.getEntry(4));
        fp.setPosition(ImageCoordinate.Z, fitParameters.getEntry(5));

        fp.setSize(ImageCoordinate.X, fitParameters.getEntry(1));
        fp.setSize(ImageCoordinate.Y, fitParameters.getEntry(1));
        fp.setSize(ImageCoordinate.Z, fitParameters.getEntry(2));

        fp.setAmplitude(fitParameters.getEntry(0));
        fp.setBackground(fitParameters.getEntry(6));

        fitParametersByChannel.add(fp);

        //calculate R2

        double residualSumSquared = 0;
        double mean = 0;
        double variance = 0;
        double R2 = 0;

        double n_photons = 0;

        for (int i = 0; i < this.xValues.length; i++) {

            residualSumSquared += Math.pow(GaussianFitter3D.fitResidual(functionValues[i], xValues[i],
                    yValues[i], zValues[i], fitParameters), 2);

            mean += functionValues[i];

            n_photons += functionValues[i] - fitParameters.getEntry(6);

        }

        mean /= functionValues.length;

        for (int i = 0; i < this.xValues.length; i++) {
            variance += Math.pow(functionValues[i] - mean, 2);
        }

        R2 = 1 - (residualSumSquared / variance);

        this.fitR2ByChannel.add(R2);

        this.unboxImages();

        //calculate fit error

        double s_xy = fitParameters.getEntry(1) * fitParameters.getEntry(1)
                * Math.pow(p.getDoubleValueForKey(PIXELSIZE_PARAM), 2);
        double s_z = fitParameters.getEntry(2) * fitParameters.getEntry(2)
                * Math.pow(p.getDoubleValueForKey(SECTIONSIZE_PARAM), 2);

        //s_z = 0; //remove!!

        double error = (2 * s_xy + s_z) / (n_photons - 1);// + 4*Math.sqrt(Math.PI) * Math.pow(2*s_xy,1.5)*Math.pow(fitParameters.getEntry(6),2)/(p.getDoubleValueForKey("pixelsize_nm")*n_photons*n_photons);

        double b = fitParameters.getEntry(6);
        double a = p.getDoubleValueForKey(PIXELSIZE_PARAM);
        double alpha = p.getDoubleValueForKey(SECTIONSIZE_PARAM);
        double sa_x = s_xy + Math.pow(a, 2) / 12;
        double sa_z = s_z + Math.pow(alpha, 2) / 12;

        //System.out.printf("b = %f, a = %f, alpha = %f, s_xy = %f, s_z = %f, n= %f\n", b, a, alpha, s_xy, s_z, n_photons);

        double error_x = sa_x / n_photons * (16.0 / 9.0 + 8 * Math.PI * sa_x * b * b
                / (n_photons * Math.pow(p.getDoubleValueForKey(PIXELSIZE_PARAM), 2)));
        double error_z = sa_z / n_photons * (16.0 / 9.0 + 8 * Math.PI * sa_z * b * b
                / (n_photons * Math.pow(p.getDoubleValueForKey(SECTIONSIZE_PARAM), 2)));

        double A = 1.0 / (2 * Math.sqrt(2) * Math.pow(Math.PI, 1.5) * Math.sqrt(sa_z) * sa_x);

        ErrIntFunc eif = new ErrIntFunc();

        eif.setParams(b, n_photons, A, sa_z, sa_x, a, alpha);

        LegendreGaussIntegrator lgi = new LegendreGaussIntegrator(5, 10, 1000);

        //integrate over 10*width of PSF in z 

        double size = 10 * Math.sqrt(sa_z);

        double intpart = 0;
        try {

            if (b < 0)
                throw new ConvergenceException(new DummyLocalizable("negative background!")); // a negative value for b seems to cause the integration to hang, preventing the program from progressing

            intpart = lgi.integrate(10000, eif, -size, size);

            double fullIntPart = intpart + Math.pow(2 * Math.PI, 1.5) * sa_x * A / Math.sqrt(sa_z);

            error_x = Math.sqrt(2 / (n_photons * sa_z / (2 * sa_z + sa_x) * fullIntPart));
            error_z = Math.sqrt(2 / (n_photons * sa_x / (2 * sa_z + sa_x) * fullIntPart));

        } catch (ConvergenceException e) {
            LoggingUtilities.getLogger().severe("Integration error: " + e.getMessage());
            error_x = -1;
            error_z = -1;
        }

        if (error_x > 0 && error_z > 0) {

            error = Math.sqrt(2 * error_x * error_x + error_z * error_z);

        } else {
            error = Double.NaN;
        }

        this.fitErrorByChannel.add(error);

        this.positionsByChannel.add(fitParameters.getSubVector(3, 3));

        this.nPhotonsByChannel.add(n_photons);

    }

    this.hadFittingError = false;
}

From source file:org.apache.kylin.cube.cuboid.algorithm.generic.BitsMutation.java

/**
 * Mutate the given chromosome. Randomly changes one gene.
 *
 * @param original the original chromosome.
 * @return the mutated chromosome./*from   w  w  w.j a  v  a  2 s.  c  o  m*/
 * @throws IllegalArgumentException if <code>original</code> is not an instance of {@link BitsChromosome}.
 */
public Chromosome mutate(Chromosome original) throws IllegalArgumentException {
    if (!(original instanceof BitsChromosome)) {
        throw new MathIllegalArgumentException(
                new DummyLocalizable("bits mutation only works on BitsChromosome"));
    }

    BitsChromosome origChrom = (BitsChromosome) original;
    BitSet newNey = (BitSet) origChrom.getRepresentation().clone();

    // randomly select a gene
    int geneIndex = GeneticAlgorithm.getRandomGenerator().nextInt(origChrom.getLength());
    // change it
    newNey.set(geneIndex, !newNey.get(geneIndex));

    Chromosome newChrom = origChrom.newBitsChromosome(newNey);
    return newChrom;
}

From source file:org.apache.kylin.cube.cuboid.algorithm.generic.BitsOnePointCrossover.java

/**
 * Performs one point crossover. A random crossover point is selected and the
 * first part from each parent is copied to the corresponding child, and the
 * second parts are copied crosswise./*from   w ww  . j av a2  s . c  om*/
 * <p>
 * Example:
 * <pre>
 * -C- denotes a crossover point
 *                   -C-                                 -C-
 * p1 = (1 0 1 0 0 1  | 0 1 1)    X    p2 = (0 1 1 0 1 0  | 1 1 1)
 *      \------------/ \-----/              \------------/ \-----/
 *            ||         (*)                       ||        (**)
 *            VV         (**)                      VV        (*)
 *      /------------\ /-----\              /------------\ /-----\
 * c1 = (1 0 1 0 0 1  | 1 1 1)    X    c2 = (0 1 1 0 1 0  | 0 1 1)
 * </pre>
 *
 * @param first  first parent (p1)
 * @param second second parent (p2)
 * @return pair of two children (c1,c2)
 * @throws IllegalArgumentException     if one of the chromosomes is
 *                                      not an instance of {@link BitsChromosome}
 * @throws MathIllegalArgumentException if the length of the two chromosomes is different
 */
@SuppressWarnings("unchecked") // OK because of instanceof checks
public ChromosomePair crossover(final Chromosome first, final Chromosome second)
        throws DimensionMismatchException, MathIllegalArgumentException {

    if (!(first instanceof BitsChromosome && second instanceof BitsChromosome)) {
        throw new MathIllegalArgumentException(
                new DummyLocalizable("bits one-point crossover only works on BitsChromosome"));
    }
    return crossover((BitsChromosome) first, (BitsChromosome) second);
}

From source file:org.orekit.data.ClasspathCrawler.java

/** {@inheritDoc} */
public boolean feed(final Pattern supported, final DataLoader visitor) throws OrekitException {

    try {// w ww .  ja  va2 s . c  o m
        OrekitException delayedException = null;
        boolean loaded = false;
        for (final String name : listElements) {
            try {

                if (visitor.stillAcceptsData()) {
                    if (ZIP_ARCHIVE_PATTERN.matcher(name).matches()) {

                        // browse inside the zip/jar file
                        final DataProvider zipProvider = new ZipJarCrawler(name);
                        loaded = zipProvider.feed(supported, visitor) || loaded;

                    } else {

                        // remove suffix from gzip files
                        final Matcher gzipMatcher = GZIP_FILE_PATTERN.matcher(name);
                        final String baseName = gzipMatcher.matches() ? gzipMatcher.group(1) : name;

                        if (supported.matcher(baseName).matches()) {

                            final InputStream stream = classLoader.getResourceAsStream(name);
                            final URI uri = classLoader.getResource(name).toURI();

                            // visit the current file
                            if (gzipMatcher.matches()) {
                                visitor.loadData(new GZIPInputStream(stream), uri.toString());
                            } else {
                                visitor.loadData(stream, uri.toString());
                            }

                            stream.close();
                            loaded = true;

                        }

                    }
                }

            } catch (OrekitException oe) {
                // maybe the next path component will be able to provide data
                // wait until all components have been tried
                delayedException = oe;
            } catch (URISyntaxException use) {
                // this should bever happen
                throw new OrekitException(use, LocalizedFormats.SIMPLE_MESSAGE, use.getMessage());
            }
        }

        if (!loaded && delayedException != null) {
            throw delayedException;
        }

        return loaded;

    } catch (IOException ioe) {
        throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
    } catch (ParseException pe) {
        throw new OrekitException(pe, new DummyLocalizable(pe.getMessage()));
    }

}

From source file:org.orekit.data.DataProvidersManagerTest.java

@Test
public void testListModification() throws OrekitException {
    System.setProperty(DataProvidersManager.OREKIT_DATA_PATH, getPath("regular-data"));
    CountingLoader crawler = new CountingLoader(false);
    DataProvidersManager manager = DataProvidersManager.getInstance();
    manager.clearProviders();//www . j  av a 2  s  .  c o m
    Assert.assertFalse(manager.isSupported(new DirectoryCrawler(new File(getPath("regular-data")))));
    Assert.assertTrue(manager.feed(".*", crawler));
    Assert.assertTrue(crawler.getCount() > 0);
    List<DataProvider> providers = manager.getProviders();
    Assert.assertEquals(1, providers.size());
    for (DataProvider provider : providers) {
        Assert.assertTrue(manager.isSupported(provider));
    }
    Assert.assertNotNull(manager.removeProvider(providers.get(0)));
    Assert.assertEquals(0, manager.getProviders().size());
    DataProvider provider = new DataProvider() {
        public boolean feed(Pattern supported, DataLoader visitor) throws OrekitException {
            return true;
        }
    };
    manager.addProvider(provider);
    Assert.assertEquals(1, manager.getProviders().size());
    manager.addProvider(provider);
    Assert.assertEquals(2, manager.getProviders().size());
    Assert.assertNotNull(manager.removeProvider(provider));
    Assert.assertEquals(1, manager.getProviders().size());
    Assert.assertNull(manager.removeProvider(new DataProvider() {
        public boolean feed(Pattern supported, DataLoader visitor) throws OrekitException {
            throw new OrekitException(new DummyLocalizable("oops!"));
        }
    }));
    Assert.assertEquals(1, manager.getProviders().size());
    Assert.assertNotNull(manager.removeProvider(manager.getProviders().get(0)));
    Assert.assertEquals(0, manager.getProviders().size());
}

From source file:org.orekit.data.DirectoryCrawler.java

/** {@inheritDoc} */
public boolean feed(final Pattern supported, final DataLoader visitor) throws OrekitException {
    try {/*from  w  w  w .  j  a v  a2 s .  c om*/
        return feed(supported, visitor, root);
    } catch (IOException ioe) {
        throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
    } catch (ParseException pe) {
        throw new OrekitException(pe, new DummyLocalizable(pe.getMessage()));
    }
}

From source file:org.orekit.data.FundamentalNutationArguments.java

/** Parse coefficients.
 * @param stream stream containing the IERS table
 * @param name name of the resource file (for error messages only)
 * @return list of coefficients arrays/*from   w  w w.  j a  v  a 2 s . c o  m*/
 * @exception OrekitException if stream is null or the table cannot be parsed
 */
private static List<double[]> parseCoefficients(final InputStream stream, final String name)
        throws OrekitException {

    if (stream == null) {
        throw new OrekitException(OrekitMessages.UNABLE_TO_FIND_FILE, name);
    }

    try {

        final DefinitionParser definitionParser = new DefinitionParser();

        // setup the reader
        final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        int lineNumber = 0;

        // look for the reference date and the 14 polynomials
        final int n = FundamentalName.values().length;
        final Map<FundamentalName, double[]> polynomials = new HashMap<FundamentalName, double[]>(n);
        for (String line = reader.readLine(); line != null; line = reader.readLine()) {
            lineNumber++;
            if (definitionParser.parseDefinition(line, lineNumber, name)) {
                polynomials.put(definitionParser.getParsedName(), definitionParser.getParsedPolynomial());
            }
        }

        final List<double[]> coefficients = new ArrayList<double[]>(n);
        coefficients.add(getCoefficients(FundamentalName.L, polynomials, name));
        coefficients.add(getCoefficients(FundamentalName.L_PRIME, polynomials, name));
        coefficients.add(getCoefficients(FundamentalName.F, polynomials, name));
        coefficients.add(getCoefficients(FundamentalName.D, polynomials, name));
        coefficients.add(getCoefficients(FundamentalName.OMEGA, polynomials, name));
        if (polynomials.containsKey(FundamentalName.L_ME)) {
            // IERS conventions 2003 and later provide planetary nutation arguments
            coefficients.add(getCoefficients(FundamentalName.L_ME, polynomials, name));
            coefficients.add(getCoefficients(FundamentalName.L_VE, polynomials, name));
            coefficients.add(getCoefficients(FundamentalName.L_E, polynomials, name));
            coefficients.add(getCoefficients(FundamentalName.L_MA, polynomials, name));
            coefficients.add(getCoefficients(FundamentalName.L_J, polynomials, name));
            coefficients.add(getCoefficients(FundamentalName.L_SA, polynomials, name));
            coefficients.add(getCoefficients(FundamentalName.L_U, polynomials, name));
            coefficients.add(getCoefficients(FundamentalName.L_NE, polynomials, name));
            coefficients.add(getCoefficients(FundamentalName.PA, polynomials, name));
        } else {
            // IERS conventions 1996 and earlier don't provide planetary nutation arguments
            final double[] zero = new double[] { 0.0 };
            while (coefficients.size() < n) {
                coefficients.add(zero);
            }
        }

        return coefficients;

    } catch (IOException ioe) {
        throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
    }

}

From source file:org.orekit.data.NetworkCrawler.java

/** {@inheritDoc} */
public boolean feed(final Pattern supported, final DataLoader visitor) throws OrekitException {

    try {//from   w ww .j  av  a 2  s  .  co  m
        OrekitException delayedException = null;
        boolean loaded = false;
        for (URL url : urls) {
            try {

                if (visitor.stillAcceptsData()) {
                    final String name = url.toURI().toString();
                    final String fileName = new File(url.getPath()).getName();
                    if (ZIP_ARCHIVE_PATTERN.matcher(fileName).matches()) {

                        // browse inside the zip/jar file
                        new ZipJarCrawler(url).feed(supported, visitor);
                        loaded = true;

                    } else {

                        // remove suffix from gzip files
                        final Matcher gzipMatcher = GZIP_FILE_PATTERN.matcher(fileName);
                        final String baseName = gzipMatcher.matches() ? gzipMatcher.group(1) : fileName;

                        if (supported.matcher(baseName).matches()) {

                            final InputStream stream = getStream(url);

                            // visit the current file
                            if (gzipMatcher.matches()) {
                                visitor.loadData(new GZIPInputStream(stream), name);
                            } else {
                                visitor.loadData(stream, name);
                            }

                            stream.close();
                            loaded = true;

                        }

                    }
                }

            } catch (OrekitException oe) {
                // maybe the next path component will be able to provide data
                // wait until all components have been tried
                delayedException = oe;
            }
        }

        if (!loaded && delayedException != null) {
            throw delayedException;
        }

        return loaded;

    } catch (URISyntaxException use) {
        throw new OrekitException(use, new DummyLocalizable(use.getMessage()));
    } catch (IOException ioe) {
        throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
    } catch (ParseException pe) {
        throw new OrekitException(pe, new DummyLocalizable(pe.getMessage()));
    }

}

From source file:org.orekit.data.PoissonSeriesParser.java

/** Parse a stream.
 * @param stream stream containing the IERS table
 * @param name name of the resource file (for error messages only)
 * @return parsed Poisson series/* ww  w.j av  a2  s  .com*/
 * @exception OrekitException if stream is null or the table cannot be parsed
 */
public PoissonSeries<T> parse(final InputStream stream, final String name) throws OrekitException {

    if (stream == null) {
        throw new OrekitException(OrekitMessages.UNABLE_TO_FIND_FILE, name);
    }

    // the degrees section header should read something like:
    // j = 0  Nb of terms = 1306
    // or something like:
    // j = 0  Number  of terms = 1037
    final Pattern degreeSectionHeaderPattern = Pattern
            .compile("^\\p{Space}*j\\p{Space}*=\\p{Space}*(\\p{Digit}+)"
                    + "[\\p{Alpha}\\p{Space}]+=\\p{Space}*(\\p{Digit}+)\\p{Space}*$");

    // regular lines are simply a space separated list of numbers
    final StringBuilder builder = new StringBuilder("^\\p{Space}*");
    for (int i = 0; i < fieldsPatterns.length; ++i) {
        builder.append("(");
        builder.append(fieldsPatterns[i]);
        builder.append(")");
        builder.append((i < fieldsPatterns.length - 1) ? "\\p{Space}+" : "\\p{Space}*$");
    }
    final Pattern regularLinePattern = Pattern.compile(builder.toString());

    try {

        // setup the reader
        final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        int lineNumber = 0;
        int expectedIndex = -1;
        int nTerms = -1;
        int count = 0;
        int degree = 0;

        // prepare the container for the parsed data
        PolynomialNutation<T> polynomial;
        if (polynomialParser == null) {
            // we don't expect any polynomial, we directly the the zero polynomial
            polynomial = new PolynomialNutation<T>(new double[0]);
        } else {
            // the dedicated parser will fill in the polynomial later
            polynomial = null;
        }
        final Map<Long, SeriesTerm<T>> series = new HashMap<Long, SeriesTerm<T>>();

        for (String line = reader.readLine(); line != null; line = reader.readLine()) {

            // replace unicode minus sign ('') by regular hyphen ('-') for parsing
            // such unicode characters occur in tables that are copy-pasted from PDF files
            line = line.replace('\u2212', '-');
            ++lineNumber;

            final Matcher regularMatcher = regularLinePattern.matcher(line);
            if (regularMatcher.matches()) {
                // we have found a regular data line

                if (expectedIndex > 0) {
                    // we are in a file were terms are numbered, we check the index
                    if (Integer.parseInt(regularMatcher.group(1)) != expectedIndex) {
                        throw new OrekitException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, name,
                                regularMatcher.group());
                    }
                }

                // get the Doodson multipliers as well as the Doodson number
                final int cTau = (firstDoodson < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstDoodson));
                final int cS = (firstDoodson < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstDoodson + 1));
                final int cH = (firstDoodson < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstDoodson + 2));
                final int cP = (firstDoodson < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstDoodson + 3));
                final int cNprime = (firstDoodson < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstDoodson + 4));
                final int cPs = (firstDoodson < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstDoodson + 5));
                final int nDoodson = (doodson < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(doodson).replaceAll("[.,]", ""));

                // get the tide multipler
                int cGamma = (gamma < 0) ? 0 : Integer.parseInt(regularMatcher.group(gamma));

                // get the Delaunay multipliers
                int cL = Integer.parseInt(regularMatcher.group(firstDelaunay));
                int cLPrime = Integer.parseInt(regularMatcher.group(firstDelaunay + 1));
                int cF = Integer.parseInt(regularMatcher.group(firstDelaunay + 2));
                int cD = Integer.parseInt(regularMatcher.group(firstDelaunay + 3));
                int cOmega = Integer.parseInt(regularMatcher.group(firstDelaunay + 4));

                // get the planetary multipliers
                final int cMe = (firstPlanetary < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstPlanetary));
                final int cVe = (firstPlanetary < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstPlanetary + 1));
                final int cE = (firstPlanetary < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstPlanetary + 2));
                final int cMa = (firstPlanetary < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstPlanetary + 3));
                final int cJu = (firstPlanetary < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstPlanetary + 4));
                final int cSa = (firstPlanetary < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstPlanetary + 5));
                final int cUr = (firstPlanetary < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstPlanetary + 6));
                final int cNe = (firstPlanetary < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstPlanetary + 7));
                final int cPa = (firstPlanetary < 0) ? 0
                        : Integer.parseInt(regularMatcher.group(firstPlanetary + 8));

                if (nDoodson > 0) {

                    // set up the traditional parameters corresponding to the Doodson arguments
                    cGamma = cTau;
                    cL = -cL;
                    cLPrime = -cLPrime;
                    cF = -cF;
                    cD = -cD;
                    cOmega = -cOmega;

                    // check Doodson number, Doodson multiplers and Delaunay multipliers consistency
                    if (nDoodson != doodsonToDoodsonNumber(cTau, cS, cH, cP, cNprime, cPs)
                            || nDoodson != delaunayToDoodsonNumber(cGamma, cL, cLPrime, cF, cD, cOmega)) {
                        throw new OrekitException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, name,
                                regularMatcher.group());
                    }

                }

                final long key = NutationCodec.encode(cGamma, cL, cLPrime, cF, cD, cOmega, cMe, cVe, cE, cMa,
                        cJu, cSa, cUr, cNe, cPa);

                // retrieved the term, or build it if it's the first time it is encountered in the file
                final SeriesTerm<T> term;
                if (series.containsKey(key)) {
                    // the term was already known, from another degree
                    term = series.get(key);
                } else {
                    // the term is a new one
                    term = SeriesTerm.buildTerm(cGamma, cL, cLPrime, cF, cD, cOmega, cMe, cVe, cE, cMa, cJu,
                            cSa, cUr, cNe, cPa);
                }

                boolean nonZero = false;
                for (int d = 0; d < sinCosColumns.length / 2; ++d) {
                    final double sinCoeff = parseCoefficient(regularMatcher, sinCosColumns[2 * d],
                            sinCosFactors[2 * d]);
                    final double cosCoeff = parseCoefficient(regularMatcher, sinCosColumns[2 * d + 1],
                            sinCosFactors[2 * d + 1]);
                    if (!Precision.equals(sinCoeff, 0.0, 1) || !Precision.equals(cosCoeff, 0.0, 1)) {
                        nonZero = true;
                        term.add(0, degree + d, sinCoeff, cosCoeff);
                        ++count;
                    }
                }
                if (nonZero) {
                    series.put(key, term);
                }

                if (expectedIndex > 0) {
                    // we are in a file were terms are numbered
                    // we must update the expected value for next term
                    ++expectedIndex;
                }

            } else {

                final Matcher headerMatcher = degreeSectionHeaderPattern.matcher(line);
                if (headerMatcher.matches()) {

                    // we have found a degree section header
                    final int nextDegree = Integer.parseInt(headerMatcher.group(1));
                    if ((nextDegree != degree + 1) && (degree != 0 || nextDegree != 0)) {
                        throw new OrekitException(OrekitMessages.MISSING_SERIE_J_IN_FILE, degree + 1, name,
                                lineNumber);
                    }

                    if (nextDegree == 0) {
                        // in IERS files split in sections, all terms are numbered
                        // we can check the indices
                        expectedIndex = 1;
                    }

                    if (nextDegree > 0 && count != nTerms) {
                        // the previous degree does not have the expected number of terms
                        throw new OrekitException(OrekitMessages.NOT_A_SUPPORTED_IERS_DATA_FILE, name);
                    }

                    // remember the number of terms the upcoming sublist should have
                    nTerms = Integer.parseInt(headerMatcher.group(2));
                    count = 0;
                    degree = nextDegree;

                } else if (polynomial == null) {
                    // look for the polynomial part
                    final double[] coefficients = polynomialParser.parse(line);
                    if (coefficients != null) {
                        polynomial = new PolynomialNutation<T>(coefficients);
                    }
                }

            }

        }

        if (polynomial == null || series.isEmpty()) {
            throw new OrekitException(OrekitMessages.NOT_A_SUPPORTED_IERS_DATA_FILE, name);
        }

        if (nTerms > 0 && count != nTerms) {
            // the last degree does not have the expected number of terms
            throw new OrekitException(OrekitMessages.NOT_A_SUPPORTED_IERS_DATA_FILE, name);
        }

        // build the series
        return new PoissonSeries<T>(polynomial, series);

    } catch (IOException ioe) {
        throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
    }

}