diff --git a/popt/cost_functions/ecalc_npv.py b/popt/cost_functions/ecalc_npv.py deleted file mode 100644 index f0804864..00000000 --- a/popt/cost_functions/ecalc_npv.py +++ /dev/null @@ -1,171 +0,0 @@ -"""Net present value.""" -import numpy as np -import csv -from pathlib import Path -import pandas as pd -import sys - -HERE = Path().cwd() # fallback for ipynb's -HERE = HERE.resolve() - - -def ecalc_npv(pred_data, **kwargs): - """ - Net present value cost function using eCalc to calculate emmisions - - Parameters - ---------- - pred_data : array_like - Ensemble of predicted data. - - **kwargs : dict - Other arguments sent to the npv function - - keys_opt : list - Keys with economic data. - - report : list - Report dates. - - Returns - ------- - objective_values : array_like - Objective function values (NPV) for all ensemble members. - """ - - from libecalc.application.energy_calculator import EnergyCalculator - from libecalc.common.time_utils import Frequency - from ecalc_cli.infrastructure.file_resource_service import FileResourceService - from libecalc.presentation.yaml.file_configuration_service import FileConfigurationService - from libecalc.presentation.yaml.model import YamlModel - - # Get the necessary input - keys_opt = kwargs.get('input_dict', {}) - report = kwargs.get('true_order', []) - - # Economic values - npv_const = dict(keys_opt['npv_const']) - if 'wem' not in npv_const: - npv_const['wem'] = 0 - if 'wel' not in npv_const: - npv_const['wel'] = 0 - - # Collect production data - Qop = [] - Qgp = [] - Qwp = [] - Qwi = [] - Dd = [] - T = [] - objective = [] - L = None - for i in np.arange(1, len(pred_data)): - - if not isinstance(pred_data[i],list): - pred_data[i] = [pred_data[i]] - if i == 1: - pred_data[i-1] = [pred_data[i-1]] - L = len(pred_data[i]) - for l in range(L): - Qop.append([]) - Qgp.append([]) - Qwp.append([]) - Qwi.append([]) - Qop[l].append(np.squeeze(pred_data[i][l]['FOPT']) - np.squeeze(pred_data[i - 1][l]['FOPT'])) - Qgp[l].append(np.squeeze(pred_data[i][l]['FGPT']) - np.squeeze(pred_data[i - 1][l]['FGPT'])) - Qwp[l].append(np.squeeze(pred_data[i][l]['FWPT']) - np.squeeze(pred_data[i - 1][l]['FWPT'])) - Qwi[l].append(np.squeeze(pred_data[i][l]['FWIT']) - np.squeeze(pred_data[i - 1][l]['FWIT'])) - Dd.append((report[1][i] - report[1][i - 1]).days) - T.append((report[1][i] - report[1][0]).days) - - Dd = np.array(Dd) - T = np.array(T) - for l in range(L): - - objective.append([]) - - # Write production data to .csv file for eCalc input, for each ensemble member - Qop[l] = np.array(Qop[l]).T - Qwp[l] = np.array(Qwp[l]).T - Qgp[l] = np.array(Qgp[l]).T - Qwi[l] = np.array(Qwi[l]).T - - if len(Qop[l].shape) == 1: - Qop[l] = np.expand_dims(Qop[l],0) - Qwp[l] = np.expand_dims(Qwp[l], 0) - Qgp[l] = np.expand_dims(Qgp[l], 0) - Qwi [l]= np.expand_dims(Qwi[l], 0) - - N = Qop[l].shape[0] - NT = Qop[l].shape[1] - values = [] - em_values = [] - el_values = [] - for n in range(N): - with open('ecalc_input.csv', 'w') as csvfile: - writer = csv.writer(csvfile, delimiter=',') - writer.writerow(['dd/mm/yyyy', 'GAS_PROD', 'OIL_PROD', 'WATER_INJ']) - for t in range(NT): - D = report[1][t] - writer.writerow([D.strftime("%d/%m/%Y"), Qgp[l][n, t]/Dd[t], Qop[l][n, t]/Dd[t], Qwi[l][n, t]/Dd[t]]) - - # Config - model_path = HERE / "ecalc_config.yaml" # "drogn.yaml" - configuration_service = FileConfigurationService(configuration_path=model_path) - resource_service = FileResourceService(working_directory=model_path.parent) - yaml_model = YamlModel( - configuration_service=configuration_service, - resource_service=resource_service, - output_frequency=Frequency.NONE, - ) - - # Compute energy, emissions - model = EnergyCalculator(graph=yaml_model.get_graph()) - consumer_results = model.evaluate_energy_usage(yaml_model.variables) - emission_results = model.evaluate_emissions(yaml_model.variables, consumer_results) - - # Extract - energy = results_as_df(yaml_model, consumer_results, lambda r: r.component_result.energy_usage) - energy_total = energy.sum(1).rename("emissions_total") - energy_total.to_csv(HERE / "energy.csv") - Qel = energy_total.values * Dd # total number of MWd (energy usage in MW * number of days) - el_values.append(Qel) - emissions = results_as_df(yaml_model, emission_results, lambda r: r['co2_fuel_gas'].rate) - emissions_total = emissions.sum(1).rename("emissions_total") - emissions_total.to_csv(HERE / "emissions.csv") - Qem = emissions_total.values * Dd # total number of tons - em_values.append(Qem) - - value = (Qop[l][n, :] * npv_const['wop'] + Qgp[l][n, :] * npv_const['wgp'] - Qwp[l][n, :] * npv_const['wwp'] - - Qwi[l][n, :] * npv_const['wwi'] - Qem * npv_const['wem'] - Qel * npv_const['wel']) / ( - (1 + npv_const['disc']) ** (T / 365)) - objective[l].append(np.sum(value)) - - # Save emissions and electrisity usage for later inspection - np.savez(f'em_values_level{l}.npz', em_values=np.array([em_values])) - np.savez(f'el_values_level{l}.npz', el_values=np.array([el_values])) - - objective[l] = np.array(objective[l]) / npv_const.get('obj_scaling', 1) - - return objective - - -def results_as_df(yaml_model, results, getter) -> pd.DataFrame: - """Extract relevant values, as well as some meta (`attrs`).""" - df = {} - attrs = {} - res = None - for id_hash in results: - res = results[id_hash] - res = getter(res) - component = yaml_model.get_graph().get_node(id_hash) - df[component.name] = res.values - attrs[component.name] = {'id_hash': id_hash, - 'kind': type(component).__name__, - 'unit': res.unit} - if res is None: - sys.exit('No emission results from eCalc!') - df = pd.DataFrame(df, index=res.timesteps) - df.index.name = "dates" - df.attrs = attrs - return df diff --git a/popt/cost_functions/ecalc_pareto_npv.py b/popt/cost_functions/ecalc_pareto_npv.py deleted file mode 100644 index 9375f9f4..00000000 --- a/popt/cost_functions/ecalc_pareto_npv.py +++ /dev/null @@ -1,174 +0,0 @@ -"""Net present value.""" -import numpy -import numpy as np -import csv -from pathlib import Path -import pandas as pd -import sys -import os - -HERE = Path().cwd() # fallback for ipynb's -HERE = HERE.resolve() - - -def ecalc_pareto_npv(pred_data, kwargs): - """ - Net present value cost function using eCalc to calculate emmisions - - Parameters - ---------- - pred_data : array_like - Ensemble of predicted data. - - **kwargs : dict - Other arguments sent to the npv function - - keys_opt : list - Keys with economic data. - - report : list - Report dates. - - Returns - ------- - objective_values : array_like - Objective function values (NPV) for all ensemble members. - """ - - from libecalc.application.energy_calculator import EnergyCalculator - from libecalc.common.time_utils import Frequency - from ecalc_cli.infrastructure.file_resource_service import FileResourceService - from libecalc.presentation.yaml.file_configuration_service import FileConfigurationService - from libecalc.presentation.yaml.model import YamlModel - - # Get the necessary input - keys_opt = kwargs.get('input_dict', {}) - report = kwargs.get('true_order', []) - - # Economic values - npv_const = dict(keys_opt['npv_const']) - - # Collect production data - Qop = [] - Qgp = [] - Qwp = [] - Qwi = [] - Dd = [] - T = [] - for i in np.arange(1, len(pred_data)): - - Qop.append(np.squeeze(pred_data[i]['fopt']) - np.squeeze(pred_data[i - 1]['fopt'])) - Qgp.append(np.squeeze(pred_data[i]['fgpt']) - np.squeeze(pred_data[i - 1]['fgpt'])) - Qwp.append(np.squeeze(pred_data[i]['fwpt']) - np.squeeze(pred_data[i - 1]['fwpt'])) - Qwi.append(np.squeeze(pred_data[i]['fwit']) - np.squeeze(pred_data[i - 1]['fwit'])) - Dd.append((report[1][i] - report[1][i - 1]).days) - T.append((report[1][i] - report[1][0]).days) - - # Write production data to .csv file for eCalc input, for each ensemble member - Qop = np.array(Qop).T - Qwp = np.array(Qwp).T - Qgp = np.array(Qgp).T - Qwi = np.array(Qwi).T - Dd = np.array(Dd) - T = np.array(T) - if len(Qop.shape) == 1: - Qop = np.expand_dims(Qop,0) - Qwp = np.expand_dims(Qwp, 0) - Qgp = np.expand_dims(Qgp, 0) - Qwi = np.expand_dims(Qwi, 0) - - N = Qop.shape[0] - NT = Qop.shape[1] - values = [] - pareto_values = [] - for n in range(N): - with open('ecalc_input.csv', 'w') as csvfile: - writer = csv.writer(csvfile, delimiter=',') - writer.writerow(['dd/mm/yyyy', 'GAS_PROD', 'OIL_PROD', 'WATER_INJ']) - for t in range(NT): - D = report[1][t] - writer.writerow([D.strftime("%d/%m/%Y"), Qgp[n, t]/Dd[t], Qop[n, t]/Dd[t], Qwi[n, t]/Dd[t]]) - - # Config - model_path = HERE / "ecalc_config.yaml" # "drogn.yaml" - configuration_service = FileConfigurationService(configuration_path=model_path) - resource_service = FileResourceService(working_directory=model_path.parent) - yaml_model = YamlModel( - configuration_service=configuration_service, - resource_service=resource_service, - output_frequency=Frequency.NONE, - ) - #yaml_model = YamlModel(path=model_path, output_frequency=Frequency.NONE) - # comps = {c.name: id_hash for (id_hash, c) in yaml_model.graph.components.items()} - - # Compute energy, emissions - # model = EnergyCalculator(energy_model=yaml_model, expression_evaluator=yaml_model.variables) - # consumer_results = model.evaluate_energy_usage() - # emission_results = model.evaluate_emissions() - model = EnergyCalculator(graph=yaml_model.get_graph()) - consumer_results = model.evaluate_energy_usage(yaml_model.variables) - emission_results = model.evaluate_emissions(yaml_model.variables, consumer_results) - - # Extract - # energy = results_as_df(yaml_model, consumer_results, lambda r: r.component_result.energy_usage) - emissions = results_as_df(yaml_model, emission_results, lambda r: r['co2_fuel_gas'].rate) - emissions_total = emissions.sum(1).rename("emissions_total") - emissions_total.to_csv(HERE / "emissions.csv") - Qem = emissions_total.values * Dd # total number of tons - - value1 = (Qop[n, :] * npv_const['wop'] + Qgp[n, :] * npv_const['wgp'] - Qwp[n, :] * npv_const['wwp'] - - Qwi[n, :] * npv_const['wwi'] - Qem * npv_const['wem']) / ( - (1 + npv_const['disc']) ** (T / 365)) - value1 = np.sum(value1) - if 'obj_scaling' in npv_const: - value1 /= npv_const['obj_scaling'] - - value2 = np.array([]) - if 'wemc' in npv_const: # multi-opjective with co2 cost correction - value2 = - Qem * npv_const['wemc'] / ((1 + npv_const['disc']) ** (T / 365)) - value2 = np.sum(value2) - if 'obj_scaling' in npv_const: - value2 /= npv_const['obj_scaling'] - elif 'w' in npv_const: # multi-objective with emission intensity - rho_o = 840.0 # oil density - rho_g = 1 # gas density - conv = 1000 # convert from kilo to tonne - value2 = np.sum(Qem*conv) / (np.sum(Qop[n, :]*rho_o + Qgp[n, :]*rho_g)/conv) # kg/toe - - pareto_values.append([np.sum(Qem), value1, value2]) - if 'w' in npv_const: - values.append((1-npv_const['w'])*value1 + npv_const['w']*value2) - else: - values.append(value1 + value2) # total objective function - - # Save emissions and both objective functions for later analysis - pareto_file = 'pareto_values.npz' - if os.path.exists(pareto_file): - pareto_iterations = np.load(pareto_file,allow_pickle=True)['pareto_iterations'][()] - else: - pareto_iterations = {} - num_eval = len(pareto_iterations) - pareto_iterations[str(num_eval)] = pareto_values - np.savez('pareto_values.npz', pareto_iterations=pareto_iterations) - - return np.array(values) - -def results_as_df(yaml_model, results, getter) -> pd.DataFrame: - """Extract relevant values, as well as some meta (`attrs`).""" - df = {} - attrs = {} - res = None - for id_hash in results: - res = results[id_hash] - res = getter(res) - component = yaml_model.get_graph().get_node(id_hash) - df[component.name] = res.values - attrs[component.name] = {'id_hash': id_hash, - 'kind': type(component).__name__, - 'unit': res.unit} - if res is None: - sys.exit('No emission results from eCalc!') - df = pd.DataFrame(df, index=res.timesteps) - df.index.name = "dates" - df.attrs = attrs - return df diff --git a/popt/cost_functions/npv.py b/popt/cost_functions/npv.py deleted file mode 100644 index f28ac2f9..00000000 --- a/popt/cost_functions/npv.py +++ /dev/null @@ -1,60 +0,0 @@ -"""Net present value.""" -import numpy as np - - -def npv(pred_data, **kwargs): - """ - Net present value cost function - - Parameters - ---------- - pred_data : array_like - Ensemble of predicted data. - - **kwargs : dict - Other arguments sent to the npv function - - keys_opt : list - Keys with economic data. - - - wop: oil price - - wgp: gas price - - wwp: water production cost - - wwi: water injection cost - - disc: discount factor - - obj_scaling: used to scale the objective function (negative since all methods are minimizers) - - report : list - Report dates. - - Returns - ------- - objective_values : numpy.ndarray - Objective function values (NPV) for all ensemble members. - """ - - # Get the necessary input - keys_opt = kwargs.get('input_dict',{}) - report = kwargs.get('true_order', []) - - # Economic values - npv_const = dict(keys_opt['npv_const']) - - values = [] - for i in np.arange(1, len(pred_data)): - Qop = np.squeeze(pred_data[i]['FOPT']) - np.squeeze(pred_data[i - 1]['FOPT']) - Qgp = np.squeeze(pred_data[i]['FGPT']) - np.squeeze(pred_data[i - 1]['FGPT']) - Qwp = np.squeeze(pred_data[i]['FWPT']) - np.squeeze(pred_data[i - 1]['FWPT']) - Qwi = np.squeeze(pred_data[i]['FWIT']) - np.squeeze(pred_data[i - 1]['FWIT']) - delta_days = (report[1][i] - report[1][0]).days - - val = (Qop * npv_const['wop'] + Qgp * npv_const['wgp'] - Qwp * npv_const['wwp'] - Qwi * npv_const['wwi']) / ( - (1 + npv_const['disc']) ** (delta_days / 365)) - - values.append(val) - - if 'obj_scaling' in npv_const: - return np.array(sum(values)) / npv_const['obj_scaling'] - else: - return np.array(sum(values)) - diff --git a/popt/cost_functions/ren_npv.py b/popt/cost_functions/ren_npv.py deleted file mode 100644 index 0035f4a1..00000000 --- a/popt/cost_functions/ren_npv.py +++ /dev/null @@ -1,69 +0,0 @@ -"Net present value cost function with injection from RENewable energy" - -import numpy as np - - -def ren_npv(pred_data, kwargs): - """ - Net present value cost function with injection from RENewable energy - - Parameters - ---------- - pred_data : ndarray - Ensemble of predicted data. - - **kwargs : dict - Other arguments sent to the npv function - - - keys_opt (list) - Keys with economic data. - - - report (list) - Report dates. - - Returns - ------- - objective_values : ndarray - Objective function values (NPV) for all ensemble members. - """ - - # Get the necessary input - keys_opt = kwargs.get('input_dict', {}) - report = kwargs.get('true_order', []) - - # Economic values - npv_const = dict(keys_opt['npv_const']) - - # Loop over timesteps - values = [] - for i in np.arange(1, len(pred_data)): - - Qop = np.squeeze(pred_data[i]['fopt']) - np.squeeze(pred_data[i - 1]['fopt']) - Qgp = np.squeeze(pred_data[i]['fgpt']) - np.squeeze(pred_data[i - 1]['fgpt']) - Qwp = np.squeeze(pred_data[i]['fwpt']) - np.squeeze(pred_data[i - 1]['fwpt']) - - Qrenwi = [] - Qwi = [] - for key in keys_opt['datatype']: - if 'wwit' in key: - if 'ren' in key: - Qrenwi.append(np.squeeze( - pred_data[i][key]) - np.squeeze(pred_data[i - 1][key])) - else: - Qwi.append(np.squeeze(pred_data[i][key]) - - np.squeeze(pred_data[i - 1][key])) - Qrenwi = np.sum(Qrenwi, axis=0) - Qwi = np.sum(Qwi, axis=0) - - delta_days = (report[1][i] - report[1][0]).days - val = (Qop * npv_const['wop'] + Qgp * npv_const['wgp'] - Qwp * npv_const['wwp'] - Qwi * npv_const['wwi'] - - Qrenwi * npv_const['wrenwi']) / ( - (1 + npv_const['disc']) ** (delta_days / 365)) - - values.append(val) - - if 'obj_scaling' in npv_const: - return sum(values) / npv_const['obj_scaling'] - else: - return sum(values) - diff --git a/popt/cost_functions/ren_npv_co2.py b/popt/cost_functions/ren_npv_co2.py deleted file mode 100644 index 53471387..00000000 --- a/popt/cost_functions/ren_npv_co2.py +++ /dev/null @@ -1,196 +0,0 @@ -''' Net Present Value with Renewable Power and co2 emissions ''' - -import pandas as pd -import numpy as np -import os -import yaml - -from pathlib import Path -from pqdm.processes import pqdm - -__all__ = ['ren_npv_co2'] - -HERE = Path().cwd() # fallback for ipynb's -HERE = HERE.resolve() - -def ren_npv_co2(pred_data, keys_opt, report, save_emissions=False): - ''' - Net Present Value with Renewable Power and co2 emissions (with eCalc) - - Parameters - ---------- - pred_data : array_like - Ensemble of predicted data. - - keys_opt : list - Keys with economic data. - - report : list - Report dates. - - Returns - ------- - objective_values : array_like - Objective function values (NPV) for all ensemble members. - ''' - - # some globals, for pqdm - global const - global kwargs - global report_dates - global sim_data - - # define a data getter - get_data = lambda i, key: pred_data[i+1][key].squeeze() - pred_data[i][key].squeeze() - - # ensemble size (ne), number of report-dates (nt) - nt = len(pred_data) - try: - ne = len(get_data(1,'fopt')) - except: - ne = 1 - - np.save('co2_emissions', np.zeros((ne, nt-1))) - - # Economic and other constatns - const = dict(keys_opt['npv_const']) - kwargs = dict(keys_opt['npv_kwargs']) - report_dates = report[1] - - # Load energy arrays. These arrays contain the excess windpower used for gas compression, - # and the energy from gas which is used in the water intection. - power_arrays = np.load(kwargs['power']+'.npz') - - sim_data = {'fopt': np.zeros((ne, nt-1)), - 'fgpt': np.zeros((ne, nt-1)), - 'fwpt': np.zeros((ne, nt-1)), - 'fwit': np.zeros((ne, nt-1)), - 'thp' : np.zeros((ne, nt-1)), - 'days': np.zeros(nt-1), - 'wind': power_arrays['wind'][:,:-1]} - - # loop over pred_data - for t in range(nt-1): - - for datatype in ['fopt', 'fgpt', 'fwpt', 'fwit']: - sim_data[datatype][:,t] = get_data(t, datatype) - - # days in time-step - sim_data['days'][t] = (report_dates[t+1] - report_dates[t]).days - - # get maximum well head pressure (for each ensemble member) - thp_keys = [k for k in keys_opt['datatype'] if 'wthp' in k] # assume only injection wells - thp_vals = [] - for key in thp_keys: - thp_vals.append(pred_data[t][key].squeeze()) - - sim_data['thp'][:,t] = np.max(np.array(thp_vals), axis=0) - - # calculate NPV values - npv_values = pqdm(array=range(ne), function=npv, n_jobs=keys_opt['parallel'], disable=True) - - if not save_emissions: - os.remove('co2_emissions.npy') - - # clear energy arrays - np.savez(kwargs['power']+'.npz', wind=np.zeros((ne, nt)), ren=np.zeros((ne,nt)), gas=np.zeros((ne,nt))) - - scaling = 1.0 - if 'obj_scaling' in const: - scaling = const['obj_scaling'] - - return np.asarray(npv_values)/scaling - - -def emissions(yaml_file="ecalc_config.yaml"): - - from libecalc.application.energy_calculator import EnergyCalculator - from libecalc.common.time_utils import Frequency - from libecalc.presentation.yaml.model import YamlModel - - # Config - model_path = HERE / yaml_file - yaml_model = YamlModel(path=model_path, output_frequency=Frequency.NONE) - - # Compute energy, emissions - model = EnergyCalculator(graph=yaml_model.graph) - consumer_results = model.evaluate_energy_usage(yaml_model.variables) - emission_results = model.evaluate_emissions(yaml_model.variables, consumer_results) - - # print power from pump - co2 = [] - for identity, component in yaml_model.graph.nodes.items(): - if identity in emission_results: - co2.append(emission_results[identity]['co2_fuel_gas'].rate.values) - - co2 = np.sum(np.asarray(co2), axis=0) - return co2 - - -def npv(n): - - days = sim_data['days'] - - # config eCalc - pd.DataFrame( {'dd-mm-yyyy' : report_dates[1:], - 'OIL_PROD' : sim_data['fopt'][n]/days, - 'GAS_PROD' : sim_data['fgpt'][n]/days, - 'WATER_INJ' : sim_data['fwit'][n]/days, - 'THP_MAX' : sim_data['thp'][n], - 'WIND_POWER' : sim_data['wind'][n]*(-1) - } ).to_csv(f'ecalc_input_{n}.csv', index=False) - - ecalc_yaml_file = kwargs['yamlfile']+'.yaml' - new_yaml = duplicate_yaml_file(filename=ecalc_yaml_file, member=n) - - #calc emissions - co2 = emissions(new_yaml)*days - - # save emissions - try: - en_co2 = np.load('co2_emissions.npy') - en_co2[n] = co2 - np.save('co2_emissions', en_co2) - except: - import time - time.sleep(1) - - #calc npv - gain = const['wop']*sim_data['fopt'][n] + const['wgp']*sim_data['fgpt'][n] - loss = const['wwp']*sim_data['fwpt'][n] + const['wwi']*sim_data['fwit'][n] + const['wem']*co2 - disc = (1+const['disc'])**(days/365) - - npv_value = np.sum( (gain-loss)/disc ) - - # delete dummy files - os.remove(new_yaml) - os.remove(f'ecalc_input_{n}.csv') - - return npv_value - - -def duplicate_yaml_file(filename, member): - - try: - # Load the YAML file - with open(filename, 'r') as yaml_file: - data = yaml.safe_load(yaml_file) - - input_name = data['TIME_SERIES'][0]['FILE'] - data['TIME_SERIES'][0]['FILE'] = input_name.replace('.csv', f'_{member}.csv') - - # Write the updated content to a new file - new_filename = filename.replace(".yaml", f"_{member}.yaml") - with open(new_filename, 'w') as new_yaml_file: - yaml.dump(data, new_yaml_file, default_flow_style=False) - - except FileNotFoundError: - print(f"File '{filename}' not found.") - - return new_filename - - - - - - diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..0dff01f7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,62 @@ +[build-system] +requires = ["setuptools>=61.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "PET" +version = "1.0" +description = "Python Ensemble Toolbox" +authors = [ + { name = "Data assimilation and optimization group" } +] +maintainers = [ + { name = "Kristian Fossum", email = "krfo@norceresearch.no" }, + { name = "Rolf J. Lorentzen", email = "rolo@norceresearch.no" } +] +license = { file = "LICENSE.txt" } +readme = "README.md" +requires-python = ">=3.8" +dependencies = [ + "numpy", + "scipy", + "matplotlib", + "h5py", + "mako", + "tqdm", + "PyWavelets", + "psutil", + "geostat @ git+https://github.com/Python-Ensemble-Toolbox/Geostatistics@main", + "pytest", + "pandas", + "p_tqdm", + #"mat73", + "opencv-python", + #"rips", + "tomli", + "tomli-w", + "pyyaml", + #"scikit-learn", + #"pylops" +] + +[project.optional-dependencies] +doc = [ + "mkdocs-material", + "mkdocstrings", + "mkdocstrings-python", + "mkdocs-gen-files", + "mkdocs-literate-nav", + "mkdocs-section-index", + "mkdocs-glightbox", + "mkdocs-jupyter", + "pybtex" +] + +[project.urls] +Homepage = "https://github.com/Python-Ensemble-Toolbox/PET" + +[tool.setuptools] +package-dir = {"" = "src"} + +[tool.setuptools.packages.find] +where = ["src"] \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index bf3626a9..00000000 --- a/setup.py +++ /dev/null @@ -1,50 +0,0 @@ -from setuptools import setup, find_packages - -EXTRAS = { - "doc": [ - "mkdocs-material", - "mkdocstrings", - "mkdocstrings-python", - "mkdocs-gen-files", - "mkdocs-literate-nav", - "mkdocs-section-index", - "mkdocs-glightbox", - "mkdocs-jupyter", - "pybtex", - ], -} - -setup( - name='PET', - version='1.0', - packages=find_packages(), #['pipt', 'popt', 'ensemble', 'simulator', 'input_output', 'misc'], - url='https://github.com/Python-Ensemble-Toolbox/PET', - license_files=('LICENSE.txt',), - author='', - author_email='krfo@norceresearch.no', - description='Python Ensemble Toolbox', - install_requires=[ - 'numpy', - 'scipy', - 'matplotlib', - 'h5py', - 'mako', - 'tqdm', - 'PyWavelets', - 'psutil', - 'geostat @ git+https://github.com/Python-Ensemble-Toolbox/Geostatistics@main', - 'pytest', - 'pandas', # libecalc 8.9.0 has requirement pandas<2,>=1 - 'p_tqdm', - 'mat73', - 'opencv-python', - 'rips', - 'tomli', - 'tomli-w', - 'pyyaml', - 'libecalc==8.23.1', # pin version to avoid frequent modifications - 'scikit-learn', - 'pylops' - - ] + EXTRAS['doc'], -) diff --git a/ensemble/__init__.py b/src/ensemble/__init__.py similarity index 100% rename from ensemble/__init__.py rename to src/ensemble/__init__.py diff --git a/ensemble/ensemble.py b/src/ensemble/ensemble.py similarity index 100% rename from ensemble/ensemble.py rename to src/ensemble/ensemble.py diff --git a/ensemble/logger.py b/src/ensemble/logger.py similarity index 100% rename from ensemble/logger.py rename to src/ensemble/logger.py diff --git a/input_output/__init__.py b/src/input_output/__init__.py similarity index 100% rename from input_output/__init__.py rename to src/input_output/__init__.py diff --git a/input_output/get_ecl_key_val.py b/src/input_output/get_ecl_key_val.py similarity index 100% rename from input_output/get_ecl_key_val.py rename to src/input_output/get_ecl_key_val.py diff --git a/input_output/organize.py b/src/input_output/organize.py similarity index 100% rename from input_output/organize.py rename to src/input_output/organize.py diff --git a/input_output/read_config.py b/src/input_output/read_config.py similarity index 100% rename from input_output/read_config.py rename to src/input_output/read_config.py diff --git a/misc/__init__.py b/src/misc/__init__.py similarity index 100% rename from misc/__init__.py rename to src/misc/__init__.py diff --git a/misc/ecl.py b/src/misc/ecl.py similarity index 100% rename from misc/ecl.py rename to src/misc/ecl.py diff --git a/misc/ecl_common.py b/src/misc/ecl_common.py similarity index 100% rename from misc/ecl_common.py rename to src/misc/ecl_common.py diff --git a/misc/grdecl.py b/src/misc/grdecl.py similarity index 100% rename from misc/grdecl.py rename to src/misc/grdecl.py diff --git a/misc/grid/__init__.py b/src/misc/grid/__init__.py similarity index 100% rename from misc/grid/__init__.py rename to src/misc/grid/__init__.py diff --git a/misc/grid/cornerpoint.py b/src/misc/grid/cornerpoint.py similarity index 100% rename from misc/grid/cornerpoint.py rename to src/misc/grid/cornerpoint.py diff --git a/misc/grid/sector.py b/src/misc/grid/sector.py similarity index 100% rename from misc/grid/sector.py rename to src/misc/grid/sector.py diff --git a/misc/grid/unstruct.py b/src/misc/grid/unstruct.py similarity index 100% rename from misc/grid/unstruct.py rename to src/misc/grid/unstruct.py diff --git a/misc/read_input_csv.py b/src/misc/read_input_csv.py similarity index 100% rename from misc/read_input_csv.py rename to src/misc/read_input_csv.py diff --git a/misc/system_tools/__init__.py b/src/misc/system_tools/__init__.py similarity index 100% rename from misc/system_tools/__init__.py rename to src/misc/system_tools/__init__.py diff --git a/misc/system_tools/environ_var.py b/src/misc/system_tools/environ_var.py similarity index 100% rename from misc/system_tools/environ_var.py rename to src/misc/system_tools/environ_var.py diff --git a/pipt/README.md b/src/pipt/README.md similarity index 100% rename from pipt/README.md rename to src/pipt/README.md diff --git a/pipt/__init__.py b/src/pipt/__init__.py similarity index 100% rename from pipt/__init__.py rename to src/pipt/__init__.py diff --git a/pipt/loop/__init__.py b/src/pipt/loop/__init__.py similarity index 100% rename from pipt/loop/__init__.py rename to src/pipt/loop/__init__.py diff --git a/pipt/loop/assimilation.py b/src/pipt/loop/assimilation.py similarity index 100% rename from pipt/loop/assimilation.py rename to src/pipt/loop/assimilation.py diff --git a/pipt/loop/ensemble.py b/src/pipt/loop/ensemble.py similarity index 100% rename from pipt/loop/ensemble.py rename to src/pipt/loop/ensemble.py diff --git a/pipt/misc_tools/__init__.py b/src/pipt/misc_tools/__init__.py similarity index 100% rename from pipt/misc_tools/__init__.py rename to src/pipt/misc_tools/__init__.py diff --git a/pipt/misc_tools/analysis_tools.py b/src/pipt/misc_tools/analysis_tools.py similarity index 100% rename from pipt/misc_tools/analysis_tools.py rename to src/pipt/misc_tools/analysis_tools.py diff --git a/pipt/misc_tools/cov_regularization.py b/src/pipt/misc_tools/cov_regularization.py similarity index 100% rename from pipt/misc_tools/cov_regularization.py rename to src/pipt/misc_tools/cov_regularization.py diff --git a/pipt/misc_tools/data_tools.py b/src/pipt/misc_tools/data_tools.py similarity index 100% rename from pipt/misc_tools/data_tools.py rename to src/pipt/misc_tools/data_tools.py diff --git a/pipt/misc_tools/ensemble_tools.py b/src/pipt/misc_tools/ensemble_tools.py similarity index 100% rename from pipt/misc_tools/ensemble_tools.py rename to src/pipt/misc_tools/ensemble_tools.py diff --git a/pipt/misc_tools/extract_tools.py b/src/pipt/misc_tools/extract_tools.py similarity index 100% rename from pipt/misc_tools/extract_tools.py rename to src/pipt/misc_tools/extract_tools.py diff --git a/pipt/misc_tools/qaqc_tools.py b/src/pipt/misc_tools/qaqc_tools.py similarity index 100% rename from pipt/misc_tools/qaqc_tools.py rename to src/pipt/misc_tools/qaqc_tools.py diff --git a/pipt/misc_tools/wavelet_tools.py b/src/pipt/misc_tools/wavelet_tools.py similarity index 100% rename from pipt/misc_tools/wavelet_tools.py rename to src/pipt/misc_tools/wavelet_tools.py diff --git a/pipt/pipt_init.py b/src/pipt/pipt_init.py similarity index 100% rename from pipt/pipt_init.py rename to src/pipt/pipt_init.py diff --git a/pipt/update_schemes/__init__.py b/src/pipt/update_schemes/__init__.py similarity index 100% rename from pipt/update_schemes/__init__.py rename to src/pipt/update_schemes/__init__.py diff --git a/pipt/update_schemes/enkf.py b/src/pipt/update_schemes/enkf.py similarity index 100% rename from pipt/update_schemes/enkf.py rename to src/pipt/update_schemes/enkf.py diff --git a/pipt/update_schemes/enrml.py b/src/pipt/update_schemes/enrml.py similarity index 100% rename from pipt/update_schemes/enrml.py rename to src/pipt/update_schemes/enrml.py diff --git a/pipt/update_schemes/es.py b/src/pipt/update_schemes/es.py similarity index 100% rename from pipt/update_schemes/es.py rename to src/pipt/update_schemes/es.py diff --git a/pipt/update_schemes/esmda.py b/src/pipt/update_schemes/esmda.py similarity index 100% rename from pipt/update_schemes/esmda.py rename to src/pipt/update_schemes/esmda.py diff --git a/pipt/update_schemes/gies/__init__.py b/src/pipt/update_schemes/gies/__init__.py similarity index 100% rename from pipt/update_schemes/gies/__init__.py rename to src/pipt/update_schemes/gies/__init__.py diff --git a/pipt/update_schemes/gies/gies_base.py b/src/pipt/update_schemes/gies/gies_base.py similarity index 100% rename from pipt/update_schemes/gies/gies_base.py rename to src/pipt/update_schemes/gies/gies_base.py diff --git a/pipt/update_schemes/gies/gies_rlmmac.py b/src/pipt/update_schemes/gies/gies_rlmmac.py similarity index 100% rename from pipt/update_schemes/gies/gies_rlmmac.py rename to src/pipt/update_schemes/gies/gies_rlmmac.py diff --git a/pipt/update_schemes/gies/rlmmac_update.py b/src/pipt/update_schemes/gies/rlmmac_update.py similarity index 100% rename from pipt/update_schemes/gies/rlmmac_update.py rename to src/pipt/update_schemes/gies/rlmmac_update.py diff --git a/pipt/update_schemes/multilevel.py b/src/pipt/update_schemes/multilevel.py similarity index 100% rename from pipt/update_schemes/multilevel.py rename to src/pipt/update_schemes/multilevel.py diff --git a/pipt/update_schemes/update_methods_ns/__init__.py b/src/pipt/update_schemes/update_methods_ns/__init__.py similarity index 100% rename from pipt/update_schemes/update_methods_ns/__init__.py rename to src/pipt/update_schemes/update_methods_ns/__init__.py diff --git a/pipt/update_schemes/update_methods_ns/approx_update.py b/src/pipt/update_schemes/update_methods_ns/approx_update.py similarity index 100% rename from pipt/update_schemes/update_methods_ns/approx_update.py rename to src/pipt/update_schemes/update_methods_ns/approx_update.py diff --git a/pipt/update_schemes/update_methods_ns/full_update.py b/src/pipt/update_schemes/update_methods_ns/full_update.py similarity index 100% rename from pipt/update_schemes/update_methods_ns/full_update.py rename to src/pipt/update_schemes/update_methods_ns/full_update.py diff --git a/pipt/update_schemes/update_methods_ns/hybrid_update.py b/src/pipt/update_schemes/update_methods_ns/hybrid_update.py similarity index 100% rename from pipt/update_schemes/update_methods_ns/hybrid_update.py rename to src/pipt/update_schemes/update_methods_ns/hybrid_update.py diff --git a/pipt/update_schemes/update_methods_ns/margIS_update.py b/src/pipt/update_schemes/update_methods_ns/margIS_update.py similarity index 100% rename from pipt/update_schemes/update_methods_ns/margIS_update.py rename to src/pipt/update_schemes/update_methods_ns/margIS_update.py diff --git a/pipt/update_schemes/update_methods_ns/subspace_update.py b/src/pipt/update_schemes/update_methods_ns/subspace_update.py similarity index 100% rename from pipt/update_schemes/update_methods_ns/subspace_update.py rename to src/pipt/update_schemes/update_methods_ns/subspace_update.py diff --git a/popt/README.md b/src/popt/README.md similarity index 100% rename from popt/README.md rename to src/popt/README.md diff --git a/popt/__init__.py b/src/popt/__init__.py similarity index 100% rename from popt/__init__.py rename to src/popt/__init__.py diff --git a/popt/cost_functions/__init__.py b/src/popt/cost_functions/__init__.py similarity index 100% rename from popt/cost_functions/__init__.py rename to src/popt/cost_functions/__init__.py diff --git a/popt/cost_functions/epf.py b/src/popt/cost_functions/epf.py similarity index 100% rename from popt/cost_functions/epf.py rename to src/popt/cost_functions/epf.py diff --git a/popt/cost_functions/quadratic.py b/src/popt/cost_functions/quadratic.py similarity index 100% rename from popt/cost_functions/quadratic.py rename to src/popt/cost_functions/quadratic.py diff --git a/popt/cost_functions/rosenbrock.py b/src/popt/cost_functions/rosenbrock.py similarity index 100% rename from popt/cost_functions/rosenbrock.py rename to src/popt/cost_functions/rosenbrock.py diff --git a/popt/loop/__init__.py b/src/popt/loop/__init__.py similarity index 100% rename from popt/loop/__init__.py rename to src/popt/loop/__init__.py diff --git a/popt/loop/ensemble_base.py b/src/popt/loop/ensemble_base.py similarity index 100% rename from popt/loop/ensemble_base.py rename to src/popt/loop/ensemble_base.py diff --git a/popt/loop/ensemble_gaussian.py b/src/popt/loop/ensemble_gaussian.py similarity index 100% rename from popt/loop/ensemble_gaussian.py rename to src/popt/loop/ensemble_gaussian.py diff --git a/popt/loop/ensemble_generalized.py b/src/popt/loop/ensemble_generalized.py similarity index 100% rename from popt/loop/ensemble_generalized.py rename to src/popt/loop/ensemble_generalized.py diff --git a/popt/loop/extensions.py b/src/popt/loop/extensions.py similarity index 100% rename from popt/loop/extensions.py rename to src/popt/loop/extensions.py diff --git a/popt/loop/optimize.py b/src/popt/loop/optimize.py similarity index 100% rename from popt/loop/optimize.py rename to src/popt/loop/optimize.py diff --git a/popt/misc_tools/__init__.py b/src/popt/misc_tools/__init__.py similarity index 100% rename from popt/misc_tools/__init__.py rename to src/popt/misc_tools/__init__.py diff --git a/popt/misc_tools/basic_tools.py b/src/popt/misc_tools/basic_tools.py similarity index 100% rename from popt/misc_tools/basic_tools.py rename to src/popt/misc_tools/basic_tools.py diff --git a/popt/misc_tools/optim_tools.py b/src/popt/misc_tools/optim_tools.py similarity index 100% rename from popt/misc_tools/optim_tools.py rename to src/popt/misc_tools/optim_tools.py diff --git a/popt/update_schemes/__init__.py b/src/popt/update_schemes/__init__.py similarity index 100% rename from popt/update_schemes/__init__.py rename to src/popt/update_schemes/__init__.py diff --git a/popt/update_schemes/enopt.py b/src/popt/update_schemes/enopt.py similarity index 100% rename from popt/update_schemes/enopt.py rename to src/popt/update_schemes/enopt.py diff --git a/popt/update_schemes/genopt.py b/src/popt/update_schemes/genopt.py similarity index 100% rename from popt/update_schemes/genopt.py rename to src/popt/update_schemes/genopt.py diff --git a/popt/update_schemes/linesearch.py b/src/popt/update_schemes/linesearch.py similarity index 100% rename from popt/update_schemes/linesearch.py rename to src/popt/update_schemes/linesearch.py diff --git a/popt/update_schemes/smcopt.py b/src/popt/update_schemes/smcopt.py similarity index 100% rename from popt/update_schemes/smcopt.py rename to src/popt/update_schemes/smcopt.py diff --git a/popt/update_schemes/subroutines/__init__.py b/src/popt/update_schemes/subroutines/__init__.py similarity index 100% rename from popt/update_schemes/subroutines/__init__.py rename to src/popt/update_schemes/subroutines/__init__.py diff --git a/popt/update_schemes/subroutines/cma.py b/src/popt/update_schemes/subroutines/cma.py similarity index 100% rename from popt/update_schemes/subroutines/cma.py rename to src/popt/update_schemes/subroutines/cma.py diff --git a/popt/update_schemes/subroutines/optimizers.py b/src/popt/update_schemes/subroutines/optimizers.py similarity index 100% rename from popt/update_schemes/subroutines/optimizers.py rename to src/popt/update_schemes/subroutines/optimizers.py diff --git a/popt/update_schemes/subroutines/subroutines.py b/src/popt/update_schemes/subroutines/subroutines.py similarity index 100% rename from popt/update_schemes/subroutines/subroutines.py rename to src/popt/update_schemes/subroutines/subroutines.py diff --git a/popt/update_schemes/trust_region.py b/src/popt/update_schemes/trust_region.py similarity index 100% rename from popt/update_schemes/trust_region.py rename to src/popt/update_schemes/trust_region.py diff --git a/simulator/README.md b/src/simulator/README.md similarity index 100% rename from simulator/README.md rename to src/simulator/README.md diff --git a/simulator/__init__.py b/src/simulator/__init__.py similarity index 100% rename from simulator/__init__.py rename to src/simulator/__init__.py diff --git a/simulator/simple_models.py b/src/simulator/simple_models.py similarity index 100% rename from simulator/simple_models.py rename to src/simulator/simple_models.py