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

remove deprec warning #649

Merged
merged 20 commits into from
Nov 9, 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
1 change: 0 additions & 1 deletion .github/workflows/markdown-altimetry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
with:
activate-environment: coast
environment-file: external/environment.yml
python-version: 3.8.10
- name: prep exec notebooks
run: |
conda info
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/markdown-general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
with:
activate-environment: coast
environment-file: external/environment.yml
python-version: 3.8.10
- name: prep exec notebooks
run: |
conda info
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/markdown-gridded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
with:
activate-environment: coast
environment-file: external/environment.yml
python-version: 3.8.10
- name: prep exec notebooks
run: |
conda info
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/markdown-profile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
with:
activate-environment: coast
environment-file: external/environment.yml
python-version: 3.8.10
- name: prep exec notebooks
run: |
conda info
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/markdown-tidegauge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
with:
activate-environment: coast
environment-file: external/environment.yml
python-version: 3.8.10
- name: prep exec notebooks
run: |
conda info
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/pylint_checking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
echo NEW_SCORE=$NEW_SCORE
OLD_SCORE=$(cat .pylint-score);
OLD_SCORE=$(echo "scale=2; $OLD_SCORE" | bc)
THREESHOLD_SCORE=$OLD_SCORE;
echo THREESHOLD_SCORE=$THREESHOLD_SCORE
if [ "$(echo "$NEW_SCORE > $THREESHOLD_SCORE" | bc -l)" -eq 1 ] ; then
THRESHOLD_SCORE=$OLD_SCORE;
echo THRESHOLD_SCORE=$THRESHOLD_SCORE
if [ "$(echo "$NEW_SCORE > $THRESHOLD_SCORE" | bc -l)" -eq 1 ] ; then
git config --global user.name "PylintBot"
git config --global author.name "PylintBot"
git config --global user.email "[email protected]"
Expand All @@ -35,14 +35,14 @@ jobs:
git checkout -b $GITHUB_HEAD_REF
git pull --rebase origin $GITHUB_HEAD_REF
git status
echo "NEW_SCORE is greater than THREESHOLD_SCORE"
echo "Updating THREESHOLD_SCORE"
echo "NEW_SCORE is greater than THESHOLD_SCORE"
echo "Updating THESHOLD_SCORE"
echo "$NEW_SCORE" > .pylint-score
git status
git commit -am "Update pylint threeshold score"
git commit -am "Update pylint THESHOLD score"
git push --set-upstream origin $GITHUB_HEAD_REF
elif [ "$(echo "$NEW_SCORE == $THREESHOLD_SCORE" | bc -l)" -eq 1 ] ; then
echo "NEW_SCORE is equal to THREESHOLD_SCORE"
elif [ "$(echo "$NEW_SCORE == $THESHOLD_SCORE" | bc -l)" -eq 1 ] ; then
echo "NEW_SCORE is equal to THESHOLD_SCORE"
else
exit 1
echo "NEW_SCORE is below the THESHOLD_SCORE. Check your pylint"
fi
5 changes: 4 additions & 1 deletion coast/_utils/stats_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def find_maxima(x, y, method="comp", **kwargs):
if flag_dt64:
N = len(extr_x_vals[ind])
x_out = [
np.datetime64("1970-01-01T00:00:00") + np.timedelta64(int(extr_x_vals[ind[i]]), "s") for i in range(N)
(np.datetime64("1970-01-01T00:00:00") + np.timedelta64(int(extr_x_vals[ind[i]]), "s")).astype(
"datetime64[ns]"
)
for i in range(N)
]
else:
x_out = extr_x_vals[ind]
Expand Down
49 changes: 30 additions & 19 deletions coast/data/tidegauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,21 +524,26 @@ def _read_hlw_data(cls, filnam, header_dict, date_start=None, date_end=None, hea
localtime_flag = False

# Open file and loop until EOF
with open(filnam) as file:
with open(filnam, encoding="utf-8") as file:
line_count = 1
for line in file:
# Read all data. Date boundaries are set later.
if line_count > header_length:
working_line = line.split()
if working_line[0] != "#":
time_str = working_line[0] + " " + working_line[1]
# Read time as datetime.datetime because it can handle local timezone easily AND the unusual date format
# Read time as datetime.datetime because it can handle
# local timezone easily AND the unusual date format
datetime_obj = datetime.datetime.strptime(time_str, "%d/%m/%Y %H:%M")
if localtime_flag == True:
if localtime_flag is True:
bst_obj = pytz.timezone("Europe/London")
time.append(np.datetime64(bst_obj.localize(datetime_obj).astimezone(pytz.utc)))
time.append(
np.datetime64(
bst_obj.localize(datetime_obj).astimezone(pytz.utc).replace(tzinfo=None)
).astype("datetime64[ns]")
)
else:
time.append(np.datetime64(datetime_obj))
time.append(np.datetime64(datetime_obj).astype("datetime64[ns]"))
ssh.append(float(working_line[2]))
line_count = line_count + 1
debug(f'Read done, close file "{filnam}"')
Expand Down Expand Up @@ -570,27 +575,31 @@ def show(self, timezone: str = None):
Print out the values in the xarray
Displays with specified timezone
"""
# debug(" Saltney pred", np.datetime_as_string(Saltney_time_pred[i], unit='m', timezone=pytz.timezone('Europe/London')),". Height: {:.2f} m".format( HT.values[i] ))
if timezone == None:
for i in range(len(self.dataset.ssh)):
# debug('time:', self.dataset.time[i].values,
# debug(" Saltney pred",
# np.datetime_as_string(Saltney_time_pred[i],
# unit='m',
# timezone=pytz.timezone('Europe/London')),
# ". Height: {:.2f} m".format( HT.values[i] ))
if timezone is None:
for ssh, idx in enumerate(self.dataset.ssh):
# debug('time:', self.dataset.time[i].values,
debug(
"time (UTC):",
general_utils.dayoweek(self.dataset.time[i].values),
np.datetime_as_string(self.dataset.time[i], unit="m"),
general_utils.day_of_week(self.dataset.time[idx].values),
np.datetime_as_string(self.dataset.time[idx], unit="m"),
"height:",
self.dataset.ssh[i].values,
ssh.values,
"m",
)
else: # display timezone aware times
for i in range(len(self.dataset.ssh)):
# debug('time:', self.dataset.time[i].values,
for ssh, idx in enumerate(self.dataset.ssh):
# debug('time:', self.dataset.time[i].values,
debug(
"time (" + timezone + "):",
general_utils.day_of_week(self.dataset.time[i].values),
np.datetime_as_string(self.dataset.time[i], unit="m", timezone=pytz.timezone(timezone)),
general_utils.day_of_week(self.dataset.time[idx].values),
np.datetime_as_string(self.dataset.time[idx], unit="m", timezone=pytz.timezone(timezone)),
"height:",
self.dataset.ssh[i].values,
ssh.values,
"m",
)

Expand All @@ -614,8 +623,10 @@ def get_tide_table_times(
window: +/- hours window size, winsize, (int) return values in that window
uses additional variable winsize (int) [default 2hrs]
nearest_1: return only the nearest event, if in winsize [default:None]
nearest_2: return nearest event in future and the nearest in the past (i.e. high and a low), if in winsize [default:None]
nearest_HW: return nearest High Water event (computed as the max of `nearest_2`), if in winsize [default:None]
nearest_2: return nearest event in future and the nearest in the past
(i.e. high and a low), if in winsize [default:None]
nearest_HW: return nearest High Water event (computed as the max of
`nearest_2`), if in winsize [default:None]

returns: xr.DataArray( measure_var, coords=time_var)
E.g. ssh (m), time (utc)
Expand Down
6 changes: 3 additions & 3 deletions coast/diagnostics/circulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def quick_plot(self, name, Vmax=0.16, Np=3, headwidth=4, scale=50, time_value=No
magnitude: shaded
"""
# %%
from matplotlib import cm
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap

nx = self.dataset.x_dim.size
Expand All @@ -124,9 +124,9 @@ def quick_plot(self, name, Vmax=0.16, Np=3, headwidth=4, scale=50, time_value=No
X = self.dataset.longitude
Y = self.dataset.latitude
# create a light colour map
N_colours = int(Vmax * 100)
n_colours = int(Vmax * 100)
n_c = 2
cmap0 = cm.get_cmap("BrBG_r", lut=N_colours + n_c * 2)
cmap0 = plt.get_cmap("BrBG_r", lut=n_colours + n_c * 2)
colors = cmap0(np.arange(cmap0.N))
colors1 = colors[n_c : cmap0.N - n_c]
cmap1 = LinearSegmentedColormap.from_list("cmap1", colors1, cmap0.N - n_c * 2)
Expand Down
6 changes: 4 additions & 2 deletions unit_testing/test_general_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ def test_bst_to_gmt(self):
time_str = "11/10/2020 12:00"
datetime_obj = datetime.datetime.strptime(time_str, "%d/%m/%Y %H:%M")
bst_obj = pytz.timezone("Europe/London")
check1 = np.datetime64(bst_obj.localize(datetime_obj).astimezone(pytz.utc)) == np.datetime64(
"2020-10-11T11:00:00"
check1 = (
np.datetime64(bst_obj.localize(datetime_obj).astimezone(pytz.utc).replace(tzinfo=None))
== np.datetime64("2020-10-11T11:00:00")
== np.datetime64("2020-10-11T11:00:00")
)
self.assertTrue(check1, msg="check1")

Expand Down
2 changes: 1 addition & 1 deletion unit_testing/test_process_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_statsmodel_seasonal_decompose(self):
gd_t = coast.Gridded(files.fn_nemo_grid_t_dat, files.fn_nemo_dom, config=files.fn_config_t_grid)
fake_time = np.arange(
np.datetime64("2010-01-01"), np.datetime64("2014-01-01"), np.timedelta64(1, "M"), dtype="datetime64[M]"
).astype("datetime64[s]")
).astype("datetime64[ns]")
fake_temp = (
(np.arange(0, 48) * 0.05)[:, np.newaxis, np.newaxis, np.newaxis]
+ np.random.normal(0, 0.1, 48)[:, np.newaxis, np.newaxis, np.newaxis]
Expand Down
Loading