Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
behrouzz committed Jan 5, 2023
0 parents commit afd1d06
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"# iers"
1 change: 1 addition & 0 deletions iers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .core import *
68 changes: 68 additions & 0 deletions iers/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
##from datetime import datetime
##import numpy as np
##import matplotlib.pyplot as plt
##import os
##from urllib.request import urlretrieve
import pandas as pd
from .utils import files_dc

def __extract(file):
with open(file, 'r') as f:
raw = f.read()
rawlist = raw.split('\n')
data = []
for row in rawlist:
if len(row)>0:
if row[0]!='#':
rowlist = row.split(' ')
rowlist = [float(i) for i in rowlist if len(i)>0]
data.append(rowlist)
return raw, data


def create_df(file, first_col=None, int_cols=None):
"""
Create DataFrame from a text file
Arguments:
----------
file : path of file to open
first_col : first column of data; (for trying to extract column names)
int_cols : columns whose data type are integer (1-based numbers)
Returns:
--------
dataframe
"""
raw, data = __extract(file)
columns = None

if file.split('/')[-1] in files_dc.keys():
file = file.split('/')[-1]
if len(files_dc[file]['cols']) > 0:
columns = files_dc[file]['cols']
if len(files_dc[file]['int']) > 0:
int_cols = files_dc[file]['int']
if first_col is not None:
i1 = raw.find(first_col)
i2 = raw.find('\n', i1)
columns = raw[i1:i2].split(' ')
columns = [i for i in columns if len(i)>0]

if (columns is not None) and (len(data[0])!=len(columns)):
columns = None

df = pd.DataFrame(data, columns=columns)
if int_cols is not None:
int_col_names = []
for i in int_cols:
int_col_names.append(list(df.columns)[i-1])
df[int_col_names] = df[int_col_names].astype(int)
return df


def serop_to_df(file):
"""series/operational to DataFrame"""
return create_df(file, first_col='MJD', int_cols=[17,18,19])


46 changes: 46 additions & 0 deletions iers/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
bs01 = ['an','x','x_er','y','y_er','UT1-TAI','UT1_er',
'dX', 'dX_er', 'dY', 'dY_er' ]

bs02 = ['an','x','x_er','y','y_er','UT1-TAI','UT1_er',
'dPsi','dPsi_er','dEps','dEps_er']


files_dc = {

'eopc01.iau2000.1900-now.dat': {
'adr':'eop/eopc01',
'cols': bs01,
'int':[],
},

'eopc01.1846-now': {
'adr':'eop/eopc01',
'cols':[],
'int':[17, 18, 19],
},

'eopc01.iau2000.1846-now': {
'adr':'eop/eopc01',
'cols':['MJD','PM-X','PM-Y','UT1-TAI','DX','DY','X-ERR','Y-ERR',
'UT1-ERR','DX-ERR','DY-ERR','RMS DELAY','CORR X-Y','CORR X-U',
'CORR Y-U','CORR DX-DY','IND1','IND2','IND3','XRT','YRT',
'LOD','DXRT','DYRT','XRT-ERR','YRT-ERR','LOD-ERR','DXRT-ERR',
'DYRT-ERR'],
'int':[17,18,19],
},

'eopc01.1900-now.dat': {
'adr':'',
'cols': bs02,
'int': [],
},

'TEMPLATE': {
'adr': '',
'cols': [],
'int': [],
},

}


0 comments on commit afd1d06

Please sign in to comment.