def test_resample_schedule_dates() -> None: """ This function checks if the observation files (complete, training, and test) in ERT and YAML version are equal. Returns: Nothing """ # Load production headers = [ "date", "WOPR", "WGPR", "WWPR", "WOPT", "WGPT", "WWPT", "WBHP", "WTHP", "WGIR", "WWIR", "WGIT", "WWIT", "WSTAT", "WELL_NAME", "PHASE", "TYPE", "date", ] df_production_data: pd.DataFrame = pd.read_csv(_PRODUCTION_DATA_FILE_NAME, usecols=headers) df_production_data["date"] = pd.to_datetime(df_production_data["date"]) start_date = date(2005, 10, 1) schedule = _create_schedule_from_data(df_production_data, start_date) days_original = [ (d - start_date).days for d in resample_schedule_dates(schedule, resampling=None) ] days_monthly = [(d - start_date).days for d in resample_schedule_dates(schedule, resampling="M")] days_quarterly = [ (d - start_date).days for d in resample_schedule_dates(schedule, resampling="Q") ] days_yearly = [(d - start_date).days for d in resample_schedule_dates(schedule, resampling="A")] assert (np.allclose(days_original[0:3], [31, 61, 62]) and np.allclose(days_monthly[0:3], [31, 61, 92]) and np.allclose(days_quarterly[0:3], [92, 182, 273]) and np.allclose(days_yearly[0:3], [92]))
def test_check_obsfiles_ert_yaml() -> None: """ This function checks if the observation files (complete, training, and test) in ERT and YAML version are equal. Returns: Nothing """ # pylint: disable-msg=too-many-locals # pylint: disable-msg=too-many-statements # pylint: disable=maybe-no-member config = collections.namedtuple("configuration", "flownet") config.flownet = collections.namedtuple("flownet", "data_source") config.flownet.data_source = collections.namedtuple( "data_source", "simulation") config.flownet.data_source.simulation = collections.namedtuple( "simulation", "vectors") config.flownet.data_source.simulation.vectors = collections.namedtuple( "vectors", "WTHP") config.flownet.data_source.simulation.vectors.WOPR = collections.namedtuple( "WOPR", "min_error") config.flownet.data_source.simulation.vectors.WOPR.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WOPR.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WGPR = collections.namedtuple( "WGPR", "min_error") config.flownet.data_source.simulation.vectors.WGPR.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WGPR.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WWPR = collections.namedtuple( "WWPR", "min_error") config.flownet.data_source.simulation.vectors.WWPR.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WWPR.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WOPT = collections.namedtuple( "WOPT", "min_error") config.flownet.data_source.simulation.vectors.WOPT.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WOPT.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WGPT = collections.namedtuple( "WGPT", "min_error") config.flownet.data_source.simulation.vectors.WGPT.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WGPT.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WWPT = collections.namedtuple( "WWPT", "min_error") config.flownet.data_source.simulation.vectors.WWPT.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WWPT.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WBHP = collections.namedtuple( "WBHP", "min_error") config.flownet.data_source.simulation.vectors.WBHP.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WBHP.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WTHP = collections.namedtuple( "WTHP", "min_error") config.flownet.data_source.simulation.vectors.WTHP.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WTHP.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WGIR = collections.namedtuple( "WGIR", "min_error") config.flownet.data_source.simulation.vectors.WGIR.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WGIR.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WWIR = collections.namedtuple( "WWIR", "min_error") config.flownet.data_source.simulation.vectors.WWIR.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WWIR.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WGIT = collections.namedtuple( "WGIT", "min_error") config.flownet.data_source.simulation.vectors.WGIT.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WGIT.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WWIT = collections.namedtuple( "WWIT", "min_error") config.flownet.data_source.simulation.vectors.WWIT.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WWIT.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WSPR = collections.namedtuple( "WSPR", "min_error") config.flownet.data_source.simulation.vectors.WSPR.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WSPR.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WSPT = collections.namedtuple( "WSPT", "min_error") config.flownet.data_source.simulation.vectors.WSPT.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WSPT.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WSIR = collections.namedtuple( "WSIR", "min_error") config.flownet.data_source.simulation.vectors.WSIR.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WSIR.rel_error = _REL_ERROR config.flownet.data_source.simulation.vectors.WSIT = collections.namedtuple( "WSIT", "min_error") config.flownet.data_source.simulation.vectors.WSIT.min_error = _MIN_ERROR config.flownet.data_source.simulation.vectors.WSIT.rel_error = _REL_ERROR config.flownet.data_source.resampling = _RESAMPLING # Load production headers = [ "date", "WOPR", "WGPR", "WWPR", "WOPT", "WGPT", "WWPT", "WBHP", "WTHP", "WGIR", "WWIR", "WGIT", "WWIT", "WSTAT", "WELL_NAME", "PHASE", "TYPE", "date", ] df_production_data: pd.DataFrame = pd.read_csv(_PRODUCTION_DATA_FILE_NAME, usecols=headers) df_production_data["date"] = pd.to_datetime(df_production_data["date"]) start_date = date(2005, 10, 1) schedule = _create_schedule_from_data(df_production_data, start_date) # Testing with resampling create_observation_file( schedule, _OBSERVATION_FILES / "observations.ertobs", config, _TRAINING_SET_FRACTION, ) create_observation_file( schedule, _OBSERVATION_FILES / "observations.yamlobs", config, _TRAINING_SET_FRACTION, yaml=True, ) dates_resampled = resample_schedule_dates( schedule, config.flownet.data_source.resampling) num_dates = len(dates_resampled) num_training_dates = round(num_dates * _TRAINING_SET_FRACTION) export_settings = [ ["_complete", 0, num_dates], ["_training", 0, num_training_dates], ["_test", num_training_dates + 1, num_dates], ] file_root = pathlib.Path(_OBSERVATION_FILES / "observations") for setting in export_settings: ert_obs_file_name = f"{file_root}{setting[0]}.ertobs" yaml_obs_file_name = f"{file_root}{setting[0]}.yamlobs" # Comparing the complete observation data # Reading ERT file ert_obs = _read_ert_obs(ert_obs_file_name) # Reading YAML file parsed_yaml_file = _read_yaml_obs(yaml_obs_file_name) # Comparing observation data compare(ert_obs, parsed_yaml_file) # Testing without resampling config.flownet.data_source.resampling = None create_observation_file( schedule, _OBSERVATION_FILES / "observations.ertobs", config, _TRAINING_SET_FRACTION, ) create_observation_file( schedule, _OBSERVATION_FILES / "observations.yamlobs", config, _TRAINING_SET_FRACTION, yaml=True, ) dates_original = resample_schedule_dates( schedule, config.flownet.data_source.resampling) num_dates = len(dates_original) num_training_dates = round(num_dates * _TRAINING_SET_FRACTION) export_settings = [ ["_complete", 0, num_dates], ["_training", 0, num_training_dates], ["_test", num_training_dates + 1, num_dates], ] file_root = pathlib.Path(_OBSERVATION_FILES / "observations") for setting in export_settings: ert_obs_file_name = f"{file_root}{setting[0]}.ertobs" yaml_obs_file_name = f"{file_root}{setting[0]}.yamlobs" # Comparing the complete observation data # Reading ERT file ert_obs = _read_ert_obs(ert_obs_file_name) # Reading YAML file parsed_yaml_file = _read_yaml_obs(yaml_obs_file_name) print(ert_obs) print(parsed_yaml_file) # Comparing observation data compare(ert_obs, parsed_yaml_file)