Skip to content

Commit

Permalink
Apply suggestions from code review m_tools_ph3.py
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos Paniagua <[email protected]>
  • Loading branch information
kmilo9999 and cpaniaguam authored Mar 11, 2024
1 parent 228e0d1 commit 0c7e627
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/icesat2_tracks/local_modules/m_tools_ph3.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,24 @@
import glob


def dt_form_timestamp(timestamp, unit=None):
unit = "h" if unit is None else unit
return (timestamp[1] - timestamp[0]).astype("m8[" + unit + "]")
def dt_form_timestamp(timestamp, unit="h"):
return (timestamp[1]-timestamp[0]).astype(f"m8[{unit}]")


def tick_formatter(a, interval=2, rounder=2, expt_flag=True, shift=0):

O = int(np.log10(a.max()))
fact = 10 ** (O - 1)
fact = 10**(int(np.log10(a.max())) - 1)
b = np.round(a / fact, rounder + 1) * fact
ticklabels = [" " for i in range(len(b))]

tt = np.arange(shift, len(b), interval)

for t in tt:
if expt_flag:
ticklabels[int(t)] = "{:.2e}".format(b[t])
ticklabels[int(t)] = f"{b[t]:.2e}"
else:

ticklabels[int(t)] = format(b[t], ".2f").rstrip("0").rstrip(".")
ticklabels[int(t)] = f"{b[t]:.2f}".rstrip("0").rstrip(".")

return ticklabels, b

Expand All @@ -58,8 +56,7 @@ def mkdirs_r(path):


def check_year(inputstr, yearstring):
a = np.datetime64(inputstr).astype(object).year
ref = np.datetime64(yearstring).astype(object).year
a, ref = [np.datetime64(t).astype(object).year for t in (inputstr, yearstring)]
return a == ref


Expand Down

0 comments on commit 0c7e627

Please sign in to comment.