# Path: pygeons/mjd.py
# @_memoize
# def mjd_inv(m,fmt):
#   ''' 
#   Converts Modified Julian Date (MJD) to a date string 
#   
#   Parameters
#   ----------
#   m : int
#     Modified Julian Date
# 
#   fmt : string
#     format string indicating how to form *out*
#       
#   Returns
#   -------
#   out : str
#     Date string
#     
#   '''
#   m = int(m)
#   d = _REFERENCE_DATETIME + timedelta(m)
#   out = d.strftime(fmt)
#   return out


import numpy as np
import logging
from pygeons.mjd import mjd_inv
      

def check_unique_stations(data):
  ''' 
  makes sure each station id is unique
  '''
  unique_ids = list(set(data['id']))
  if len(data['id']) != len(unique_ids):
    # there are duplicate stations, now find them
    duplicates = []
    for i in unique_ids:
      if sum(data['id'] == i) > 1:
        duplicates += [i]
        
    duplicates = ', '.join(duplicates)
    raise DataError(
      'Dataset contains the following duplicate station IDs : %s ' 
      % duplicates) 


def check_unique_dates(data):
  ''' 
  makes sure each date is unique
  '''
  unique_days = list(set(data['time']))
  if len(data['time']) != len(unique_days):
    # there are duplicate dates, now find them
    duplicates = []
    for i in unique_days:
      if sum(data['time'] == i) > 1:

# Path: pygeons/mjd.py
# @_memoize
# def mjd_inv(m,fmt):
#   ''' 
#   Converts Modified Julian Date (MJD) to a date string 
#   
#   Parameters
#   ----------
#   m : int
#     Modified Julian Date
# 
#   fmt : string
#     format string indicating how to form *out*
#       
#   Returns
#   -------
#   out : str
#     Date string
#     
#   '''
#   m = int(m)
#   d = _REFERENCE_DATETIME + timedelta(m)
#   out = d.strftime(fmt)
#   return out


# Path: pygeons/io/datacheck.py
import numpy as np
import logging
from pygeons.mjd import mjd_inv

      

def check_unique_stations(data):
  ''' 
  makes sure each station id is unique
  '''
  unique_ids = list(set(data['id']))
  if len(data['id']) != len(unique_ids):
    # there are duplicate stations, now find them
    duplicates = []
    for i in unique_ids:
      if sum(data['id'] == i) > 1:
        duplicates += [i]
        
    duplicates = ', '.join(duplicates)
    raise DataError(
      'Dataset contains the following duplicate station IDs : %s ' 
      % duplicates) 


def check_unique_dates(data):
  ''' 
  makes sure each date is unique
  '''
  unique_days = list(set(data['time']))
  if len(data['time']) != len(unique_days):
    # there are duplicate dates, now find them
    duplicates = []
    for i in unique_days:
      if sum(data['time'] == i) > 1:

        duplicates += [mjd_inv(i,'%Y-%m-%d')]