hydrogeoscience / pygtide

A Python module and wrapper for ETERNA PREDICT to compute gravitational tides on Earth
Mozilla Public License 2.0
50 stars 19 forks source link

Wrong format etpolut1.dat #11

Closed Jollyfant closed 3 years ago

Jollyfant commented 4 years ago

Hi, when creating etpolut1.dat and running test.py there is a problem:

ValueError: time data '1962010' does not match format '%Y%m%d'

This file uses upstream pandas to_string function and there is a problem with a leading space: https://github.com/pandas-dev/pandas/issues/28538 since version 0.25.

A manual fix is to remove the leading white space in the created file.

hydrogeoscience commented 3 years ago

Please see the new update.

scottstanie commented 3 years ago

This seems to still happen with the update:

In [17]: pygtide.pygtide()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-17-f5604c506a21> in <module>
----> 1 pygtide.pygtide()

~/repos/pygtide/pygtide.py in __init__(self, msg)
    133         self.etpolut1_bin = str(etpred.params.etpolutbin, 'UTF-8').strip()
    134         self.etpolut1_start = dt.datetime.strptime(str(etpred.inout.etpol_start), "%Y%m%d")
--> 135         self.etpolut1_end = dt.datetime.strptime(str(etpred.inout.etpol_end), "%Y%m%d")
    136
    137         # print(end_date)

~/miniconda3/envs/mapping/lib/python3.8/_strptime.py in _strptime_datetime(cls, data_string, format)
    566     """Return a class cls instance based on the input string and the
    567     format string."""
--> 568     tt, fraction, gmtoff_fraction = _strptime(data_string, format)
    569     tzname, gmtoff = tt[-2:]
    570     args = tt[:6] + (fraction,)

~/miniconda3/envs/mapping/lib/python3.8/_strptime.py in _strptime(data_string, format)
    347     found = format_regex.match(data_string)
    348     if not found:
--> 349         raise ValueError("time data %r does not match format %r" %
    350                          (data_string, format))
    351     if len(data_string) != found.end():

ValueError: time data '0' does not match format '%Y%m%d'
> /home/scott/miniconda3/envs/mapping/lib/python3.8/_strptime.py(349)_strptime()
    347     found = format_regex.match(data_string)
    348     if not found:
--> 349         raise ValueError("time data %r does not match format %r" %
    350                          (data_string, format))
    351     if len(data_string) != found.end():
> /home/scott/repos/pygtide/pygtide.py(135)__init__()
    133         self.etpolut1_bin = str(etpred.params.etpolutbin, 'UTF-8').strip()
    134         self.etpolut1_start = dt.datetime.strptime(str(etpred.inout.etpol_start), "%Y%m%d")
--> 135         self.etpolut1_end = dt.datetime.strptime(str(etpred.inout.etpol_end), "%Y%m%d")
    136
    137         # print(end_date)

ipdb> etpred.inout.etpol_end
array(0, dtype=int32)
hydrogeoscience commented 3 years ago

The issue is related to faulty newlines in the file “etpolut1.dat”. Please run the script “update_commdat.py” and see if that resolves the issue.

Cheers,

Gabriel

From: Scott Staniewicz notifications@github.com Sent: Tuesday, 8 December 2020 22:33 To: hydrogeoscience/pygtide pygtide@noreply.github.com Cc: Gabriel C Rau gabriel@hydrogeo.science; State change state_change@noreply.github.com Subject: Re: [hydrogeoscience/pygtide] Wrong format etpolut1.dat (#11)

This seems to still happen with the update:

In [17]: pygtide.pygtide()

ValueError Traceback (most recent call last)

in ----> 1 pygtide.pygtide() ~/repos/pygtide/pygtide.py in __init__(self, msg) 133 self.etpolut1_bin = str(etpred.params.etpolutbin, 'UTF-8').strip() 134 self.etpolut1_start = dt.datetime.strptime(str(etpred.inout.etpol_start), "%Y%m%d") --> 135 self.etpolut1_end = dt.datetime.strptime(str(etpred.inout.etpol_end), "%Y%m%d") 136 137 # print(end_date) ~/miniconda3/envs/mapping/lib/python3.8/_strptime.py in _strptime_datetime(cls, data_string, format) 566 """Return a class cls instance based on the input string and the 567 format string.""" --> 568 tt, fraction, gmtoff_fraction = _strptime(data_string, format) 569 tzname, gmtoff = tt[-2:] 570 args = tt[:6] + (fraction,) ~/miniconda3/envs/mapping/lib/python3.8/_strptime.py in _strptime(data_string, format) 347 found = format_regex.match(data_string) 348 if not found: --> 349 raise ValueError("time data %r does not match format %r" % 350 (data_string, format)) 351 if len(data_string) != found.end(): ValueError: time data '0' does not match format '%Y%m%d' > /home/scott/miniconda3/envs/mapping/lib/python3.8/_strptime.py(349)_strptime() 347 found = format_regex.match(data_string) 348 if not found: --> 349 raise ValueError("time data %r does not match format %r" % 350 (data_string, format)) 351 if len(data_string) != found.end(): > /home/scott/repos/pygtide/pygtide.py(135)__init__() 133 self.etpolut1_bin = str(etpred.params.etpolutbin, 'UTF-8').strip() 134 self.etpolut1_start = dt.datetime.strptime(str(etpred.inout.etpol_start), "%Y%m%d") --> 135 self.etpolut1_end = dt.datetime.strptime(str(etpred.inout.etpol_end), "%Y%m%d") 136 137 # print(end_date) ipdb> etpred.inout.etpol_end array(0, dtype=int32) — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub , or unsubscribe . -- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus
scottstanie commented 3 years ago

Yep that worked, although I had to alter one line in update_commdat.py which i'll submiit in a PR