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

fix for bug when reading Waterinfo #162 #163

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions hydropandas/io/waterinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ def read_waterinfo_file(
"File type '{}' not supported!".format(os.path.splitext(path)[-1])
)

if index_cols is None:
index_cols = ["WAARNEMINGDATUM", "WAARNEMINGTIJD"]

if value_col is None:
value_col = "NUMERIEKEWAARDE"

Expand All @@ -66,11 +63,25 @@ def read_waterinfo_file(
sep=";",
decimal=",",
encoding="ISO-8859-1",
parse_dates=[index_cols],
dayfirst=True,
index_col="_".join(index_cols),
)

if index_cols is None:
index_cols = ["WAARNEMINGDATUM"]
if "WAARNEMINGTIJD (MET/CET)" in df.columns:
index_cols += ["WAARNEMINGTIJD (MET/CET)"]
elif "WAARNEMINGTIJD" in df.columns:
index_cols += ["WAARNEMINGTIJD"]
else:
raise KeyError(
"expected column with WAARNEMINGSTIJD but could not find one"
)

df.index = pd.to_datetime(
df[index_cols[0]] + " " + df[index_cols[1]], dayfirst=True
)
df.drop(columns=index_cols, inplace=True)

# do some conversions
df.loc[df[value_col] == 999999999, value_col] = np.NaN
df[value_col] = df[value_col] / 100.0
Expand Down
3 changes: 2 additions & 1 deletion hydropandas/obs_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,8 @@ def to_pastastore(
Name of the column in the Obs dataframe to be used. If None the
first numeric column in the Obs Dataframe is used.
kind : str, optional
The kind of series that is added to the pastastore
The kind of series that is added to the pastastore. Use 'oseries'
for observations and anything else for stresses.
add_metadata : boolean, optional
If True metadata from the observations added to the pastastore
conn : pastastore.connectors or None, optional
Expand Down
1 change: 1 addition & 0 deletions tests/data/2023-waterinfo-test/20231023_017.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MONSTER_IDENTIFICATIE;MEETPUNT_IDENTIFICATIE;LOCATIE_CODE;TYPERING_OMSCHRIJVING;TYPERING_CODE;GROOTHEID_OMSCHRIJVING;GROOTHEID_ CODE;PARAMETER_OMSCHRIJVING;PARAMETER_ CODE;CAS_NR;EENHEID_CODE;HOEDANIGHEID_OMSCHRIJVING;HOEDANIGHEID_CODE;COMPARTIMENT_OMSCHRIJVING;COMPARTIMENT_CODE;WAARDEBEWERKINGSMETHODE_OMSCHRIJVING;WAARDEBEWERKINGSMETHODE_CODE;WAARDEBEPALINGSMETHODE_OMSCHRIJVING;WAARDEBEPALINGSMETHODE_CODE;BEMONSTERINGSSOORT_OMSCHRIJVING;BEMONSTERINGSSOORT_CODE;WAARNEMINGDATUM;WAARNEMINGTIJD (MET/CET);LIMIETSYMBOOL;NUMERIEKEWAARDE;ALFANUMERIEKEWAARDE;KWALITEITSOORDEEL_CODE;REFERENTIE;NOTITIE_CODE;NOTITIE_OMSCHRIJVING;STATUSWAARDE;OPDRACHTGEVENDE_INSTANTIE;MEETAPPARAAT_OMSCHRIJVING;MEETAPPARAAT_CODE;BEMONSTERINGSAPPARAAT_OMSCHRIJVING;BEMONSTERINGSAPPARAAT_CODE;PLAATSBEPALINGSAPPARAAT_OMSCHRIJVING;PLAATSBEPALINGSAPPARAAT_CODE;BEMONSTERINGSHOOGTE;REFERENTIEVLAK;EPSG;X;Y;ORGAAN_OMSCHRIJVING;ORGAAN_CODE;TAXON_NAME;GROEPERING_OMSCHRIJVING;GROEPERING_CODE;GROEPERING_KANAAL;GROEPERING_TYPE;Krimpen a/d Lek;KRIMPADLK;;;Waterhoogte;WATHTE;;;;cm;t.o.v. Normaal Amsterdams Peil;NAP;Oppervlaktewater;OW;;;Rekenkundig gemiddelde waarde over vorige 5 en volgende 5 minuten;other:F007;Steekbemonstering;SB;01-01-2022;00:00:00;;43;43;Normale waarde;;;;Gecontroleerd;RIKZMON_WAT;Vlotter;127;;;;;-999999999;NVT;25831;612093,755309996;5750138,05579548;;;;;;;;Krimpen a/d Lek;KRIMPADLK;;;Waterhoogte;WATHTE;;;;cm;t.o.v. Normaal Amsterdams Peil;NAP;Oppervlaktewater;OW;;;Rekenkundig gemiddelde waarde over vorige 5 en volgende 5 minuten;other:F007;Steekbemonstering;SB;01-01-2022;00:10:00;;51;51;Normale waarde;;;;Gecontroleerd;RIKZMON_WAT;Vlotter;127;;;;;-999999999;NVT;25831;612093,755309996;5750138,05579548;;;;;;;;Krimpen a/d Lek;KRIMPADLK;;;Waterhoogte;WATHTE;;;;cm;t.o.v. Normaal Amsterdams Peil;NAP;Oppervlaktewater;OW;;;Rekenkundig gemiddelde waarde over vorige 5 en volgende 5 minuten;other:F007;Steekbemonstering;SB;01-01-2022;00:20:00;;60;60;Normale waarde;;;;Gecontroleerd;RIKZMON_WAT;Vlotter;127;;;;;-999999999;NVT;25831;612093,755309996;5750138,05579548;;;;;;;;Krimpen a/d Lek;KRIMPADLK;;;Waterhoogte;WATHTE;;;;cm;t.o.v. Normaal Amsterdams Peil;NAP;Oppervlaktewater;OW;;;Rekenkundig gemiddelde waarde over vorige 5 en volgende 5 minuten;other:F007;Steekbemonstering;SB;01-01-2022;00:30:00;;70;70;Normale waarde;;;;Gecontroleerd;RIKZMON_WAT;Vlotter;127;;;;;-999999999;NVT;25831;612093,755309996;5750138,05579548;;;;;;;;Krimpen a/d Lek;KRIMPADLK;;;Waterhoogte;WATHTE;;;;cm;t.o.v. Normaal Amsterdams Peil;NAP;Oppervlaktewater;OW;;;Rekenkundig gemiddelde waarde over vorige 5 en volgende 5 minuten;other:F007;Steekbemonstering;SB;01-01-2022;00:40:00;;82;82;Normale waarde;;;;Gecontroleerd;RIKZMON_WAT;Vlotter;127;;;;;-999999999;NVT;25831;612093,755309996;5750138,05579548;;;;;;;
Expand Down
1 change: 0 additions & 1 deletion tests/data/waterinfo-test/20200128_045.csv

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_001_to_from.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def test_knmi_collection_from_grid():


def test_waterinfo_from_dir():
path = "./tests/data/waterinfo-test"
path = "./tests/data/2023-waterinfo-test"
hpd.read_waterinfo(path)


Expand Down