diff --git a/.vscode/settings.json b/.vscode/settings.json index 0cfcb653850ceb990c5a2ca4b158a9ee52d93b27..b323bd22ab5f1a9fd19dbefd7ede743a850c669d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,13 +1,10 @@ { - "python.testing.unittestArgs": [ + "python.testing.pytestArgs": [ + "tests/", "-v", - "-s", - "tests", - "-t", - "src/vipscore_common", - "-p", - "test_*.py" + "-k", + "test_" ], - "python.testing.pytestEnabled": false, - "python.testing.unittestEnabled": true + "python.testing.pytestEnabled": true, + "python.testing.unittestEnabled": false } \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..ad9df02c558eb3280ec8f2638771627970dc3c42 --- /dev/null +++ b/LICENSE @@ -0,0 +1,15 @@ +Copyright (c) 2023 NIBIO <http://www.nibio.no/>. + +This file is part of VIPSCore-Python-Common. +VIPSCore-Python-Common is free software: you can redistribute it and/or modify +it under the terms of the NIBIO Open Source License as published by +NIBIO, either version 1 of the License, or (at your option) any +later version. + +VIPSCore-Python-Common is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +NIBIO Open Source License for more details. + +You should have received a copy of the NIBIO Open Source License +along with VIPSCore-Python-Common. If not, see <http://www.nibio.no/licenses/>. \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 374b58cbf4636f1e28bacf987ac2fe89ed27ccba..6fe23d7c296072e8de5e266a6d07f71860039281 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,5 @@ [build-system] requires = [ - "setuptools>=42", - "wheel" + "setuptools>=61.0" ] build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg index 91debbde832c40d69b9aa716b3756f306134e501..fdadd5ae110113e667e059447e93b31fd1286d61 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [metadata] -name = vipscore-python-common +name = vipscore_python_common version = 0.5.0 author = Tor-Einar Skog author_email = tor-einar.skog@nibio.no @@ -21,6 +21,7 @@ install_requires = shapely pydantic pytz + pandas [options.packages.find] where = src \ No newline at end of file diff --git a/src/vipscore_common/__init__.py b/src/vipscore_common/__init__.py index 44e6f454d49ae6d69188abea9994c130cb15629b..8b137891791fe96927ad78e64b0aad7bded08bdc 100755 --- a/src/vipscore_common/__init__.py +++ b/src/vipscore_common/__init__.py @@ -1,2 +1 @@ -from .entities import * -from .vips_model import * \ No newline at end of file + diff --git a/src/vipscore_common/data_utils.py b/src/vipscore_common/data_utils.py index 6d1abdd4c3b38b43afeb33aaf5afc292926aae96..4bc6acd04183f757a0ca050c8c7a70da0b58b652 100644 --- a/src/vipscore_common/data_utils.py +++ b/src/vipscore_common/data_utils.py @@ -26,7 +26,7 @@ import numpy as np import pandas as pd from pandas import DataFrame import json -from entities import * +from .entities import * def get_dataframe_from_weather_observations(weather_observations: list, timezone:datetime.tzinfo) -> DataFrame: """ diff --git a/src/vipscore_common/reference_model.py b/src/vipscore_common/reference_model.py index 717882182d0cd03e24411eff51d93fcee18fa2a7..1fd3bf60229e076bafba12adacc4fb894a598382 100755 --- a/src/vipscore_common/reference_model.py +++ b/src/vipscore_common/reference_model.py @@ -18,9 +18,9 @@ You should have received a copy of the NIBIO Open Source License along with VIPSCore-Python-Common. If not, see <http://www.nibio.no/licenses/>. """ -from vips_model import VIPSModel -from entities import Result, ModelConfiguration, WeatherObservation -import data_utils +from .vips_model import VIPSModel +from .entities import Result, ModelConfiguration, WeatherObservation +from .data_utils import * import numpy as np class ReferenceModel(VIPSModel): @@ -46,8 +46,8 @@ class ReferenceModel(VIPSModel): self.sowing_date = model_configuration.get_config_parameter_as_date("sowingDate") self.timezone = model_configuration.get_config_parameter_as_timezone("timeZone") # Weather data is turned into Pandas dataframe - self.df = data_utils.get_dataframe_from_weather_observations( - data_utils.get_weather_observations_from_json_list( + self.df = get_dataframe_from_weather_observations( + get_weather_observations_from_json_list( model_configuration.config_parameters["observations"] ), self.timezone @@ -74,7 +74,7 @@ class ReferenceModel(VIPSModel): # Calculate day degrees from sowingDate and as far as weather data goes # Adjusting for base temperature - self.df["TMContrib"] = self.df["TM"].apply(data_utils.get_temp_adjusted_for_base, args=(5,)) + self.df["TMContrib"] = self.df["TM"].apply(get_temp_adjusted_for_base, args=(5,)) # Aggregating the day degrees self.df["TMDD"] = self.df["TMContrib"].cumsum() # Adding the thresholds to the data frame @@ -84,7 +84,7 @@ class ReferenceModel(VIPSModel): # For each day: check accumulated day-degrees and decide warning status self.df["WARNING_STATUS"] = self.df["TMDD"].apply(self.determine_warning_status) #print(self.df) - result = data_utils.get_result_list_from_dataframe(self.df) + result = get_result_list_from_dataframe(self.df) #print(result) return result diff --git a/src/vipscore_common/vips_model.py b/src/vipscore_common/vips_model.py index 175b032de008e14cf16c21f880eb33fdca38e2f0..38e02f9236174e364597ae83aa40ae0c973b3f92 100755 --- a/src/vipscore_common/vips_model.py +++ b/src/vipscore_common/vips_model.py @@ -22,7 +22,7 @@ along with VIPSCore-Python-Common. If not, see <http://www.nibio.no/licenses/>. # @author Tor-Einar Skog <tor-einar.skog@nibio.no> from abc import ABC, abstractmethod, abstractproperty -from entities import Result, ModelConfiguration +from .entities import Result, ModelConfiguration class VIPSModel(ABC): diff --git a/src/vipscore_common/tests/__init__.py b/tests/__init__.py similarity index 100% rename from src/vipscore_common/tests/__init__.py rename to tests/__init__.py diff --git a/src/vipscore_common/tests/test_data_utils.py b/tests/test_data_utils.py similarity index 81% rename from src/vipscore_common/tests/test_data_utils.py rename to tests/test_data_utils.py index 09dab010aa0f266db0bf92d6cd21a780a5319577..5b0b255c91e0ce509cac9fec011b0b25c7291307 100644 --- a/src/vipscore_common/tests/test_data_utils.py +++ b/tests/test_data_utils.py @@ -1,9 +1,8 @@ import unittest -import data_utils -from reference_model import * -from entities import * +from src.vipscore_common import data_utils +from src.vipscore_common.entities import * import pytz class TestDataUtils(unittest.TestCase): @@ -11,7 +10,7 @@ class TestDataUtils(unittest.TestCase): """ The method can convert a json dict to a list of WeatherObservation objects """ - with open ("src/vipscore_common/tests/weather_data_2015_NO_aas_TMD.json") as f: + with open ("tests/weather_data_2015_NO_aas_TMD.json") as f: result = data_utils.get_weather_observations_from_json(f.read()) # Length should be > 0 self.assertGreater(len(result), 0) @@ -23,7 +22,7 @@ class TestDataUtils(unittest.TestCase): """ Lorem Ipsum osv """ - with open ("src/vipscore_common/tests/weather_data_2015_NO_aas_TMD.json") as f: + with open ("tests/weather_data_2015_NO_aas_TMD.json") as f: weather_observations = data_utils.get_weather_observations_from_json(f.read()) result = data_utils.get_dataframe_from_weather_observations(weather_observations, pytz.timezone("Europe/Oslo")) self.assertIsNotNone(result) diff --git a/src/vipscore_common/tests/test_reference_model.py b/tests/test_reference_model.py similarity index 94% rename from src/vipscore_common/tests/test_reference_model.py rename to tests/test_reference_model.py index 743855eaa2b6f40a9992d1c3bc4c4b79c85d2342..5d6ba9061c99f27ee57167c63a8687aa0f10fd0a 100644 --- a/src/vipscore_common/tests/test_reference_model.py +++ b/tests/test_reference_model.py @@ -2,11 +2,11 @@ import unittest import json -from reference_model import * -from entities import * +from src.vipscore_common.reference_model import * +from src.vipscore_common.entities import * def get_model_configuration(): - with open ("src/vipscore_common/tests/weather_data_2015_NO_aas_TMD.json") as f: + with open ("tests/weather_data_2015_NO_aas_TMD.json") as f: weather_observations = json.load(f) return ModelConfiguration( model_id=ReferenceModel.MODEL_ID, diff --git a/src/vipscore_common/tests/weather_data_2015_NO_aas_TMD.json b/tests/weather_data_2015_NO_aas_TMD.json similarity index 100% rename from src/vipscore_common/tests/weather_data_2015_NO_aas_TMD.json rename to tests/weather_data_2015_NO_aas_TMD.json