All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.powsybl.python.glsk.GlskDocumentContext Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2022, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * SPDX-License-Identifier: MPL-2.0
 */
package com.powsybl.python.glsk;

import com.powsybl.commons.PowsyblException;
import com.powsybl.glsk.ucte.UcteGlskDocument;
import com.powsybl.iidm.network.Network;
import com.powsybl.sensitivity.WeightedSensitivityVariable;

import java.io.FileInputStream;
import java.io.IOException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Bertrand Rix {@literal }
 */
public class GlskDocumentContext {

    private UcteGlskDocument document;

    public void load(String filename) {
        try (FileInputStream fis = new FileInputStream(filename)) {
            document = UcteGlskDocument.importGlsk(fis);
        } catch (IOException e) {
            throw new PowsyblException(e.getMessage());
        }
    }

    public List getInjectionIdForCountry(Network n, String country, Instant instant) {
        return new ArrayList<>(document.getZonalGlsks(n, instant).getData(country).getVariablesById().keySet());
    }

    public Instant getInjectionFactorStart() {
        return document.getGSKTimeInterval().getStart();
    }

    public Instant getInjectionFactorEnd() {
        return document.getGSKTimeInterval().getEnd();
    }

    public List getInjectionFactorForCountryTimeinterval(Network n, String country, Instant instant) {
        return document.getZonalGlsks(n, instant).getData(country).getVariablesById()
                .values().stream().map(WeightedSensitivityVariable::getWeight).collect(Collectors.toList());
    }

    public List getCountries() {
        return document.getZones();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy