text: # Copyright 2022 Kaiyu Zheng
  # 
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  # 
  #     http://www.apache.org/licenses/LICENSE-2.0
  # 
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  import numpy as np
  import math
  import datetime
  import pytz
  from pytz import reference as pytz_reference
  
  def remap(oldval, oldmin, oldmax, newmin, newmax, enforce=False):
      newval = (((oldval - oldmin) * (newmax - newmin)) / (oldmax - oldmin)) + newmin
      if enforce:
          return min(max(newval, newmin), newmax)
      else:
          return newval
  
  # Math
  def to_radians(th):
      return th*np.pi / 180
  
  def to_rad(th):
      return th*np.pi / 180
  
  def to_degrees(th):
      return th*180 / np.pi
  
  def to_deg(th):
      return th*180 / np.pi
  
  
  def euclidean_dist(p1, p2):
      return math.sqrt(sum([(a - b)** 2 for a, b in zip(p1, p2)]))
  
  
  ########## Python utils
  def nice_timestr(dtobj=None):
      """pass in a datetime.datetime object `dt`
      and get a nice time string. If None is passed in,
      then get string for the current time"""
      if dtobj is None:
          dtobj = datetime.datetime.now()
  
      localtime = pytz_reference.LocalTimezone()
      return dtobj.strftime("%a, %d-%b-%Y %I:%M:%S, " + localtime.tzname(dtobj))
  