Skip to content

Commit

Permalink
first publish to pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
behrouzz committed Jan 6, 2023
1 parent afd1d06 commit 0cfba33
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 67 deletions.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Behrouz Safari

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
"# iers"
**Author:** [Behrouz Safari](https://astrodatascience.net//)<br/>
**License:** [MIT](https://opensource.org/licenses/MIT)<br/>

# iers
*Analysis data of the International Earth Rotation and Reference Systems Service (IERS)*


## Installation

Install the latest version of *iers* from [PyPI](https://pypi.org/project/iers/):

pip install iers

Requirements are *numpy* and *pandas*.


## Examples

Let's read a file:

```python
from iers import create_df

adr = '../data/eop/eopc01/'
f = adr + 'eopc01.iau2000.1846-now'

df = create_df(f)
```

Let's open all files we have downloaded from iers server:

```python
from iers import create_df, files_dc

files = [i for i in files_dc.keys() if i[:3]!='TEM']

adrs = [files_dc[i]['adr'] for i in files]

for i, f in enumerate(files):
df = create_df('C:/Moi/_py/Astronomy/Earth/IERS/data/'+adrs[i] + f)
print(df)
print(len(files_dc[f]['cols']))
print('-'*80)
```

See more examples at [astrodatascience.net](https://astrodatascience.net/)
7 changes: 6 additions & 1 deletion iers/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
from .core import *
from .core import create_df
from .formats import files_dc
from .utils import dt_to_mjd, mjd_to_dt


__version__ = "0.0.1"
27 changes: 8 additions & 19 deletions iers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,9 @@
##import os
##from urllib.request import urlretrieve
import pandas as pd
from .utils import files_dc
from .formats import files_dc
from .utils import is_data, extract

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):
Expand All @@ -34,7 +23,7 @@ def create_df(file, first_col=None, int_cols=None):
--------
dataframe
"""
raw, data = __extract(file)
raw, data = extract(file)
columns = None

if file.split('/')[-1] in files_dc.keys():
Expand All @@ -49,7 +38,7 @@ def create_df(file, first_col=None, int_cols=None):
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)):
if (columns is not None) and (len(data[0])!=len(columns)): # IRAD
columns = None

df = pd.DataFrame(data, columns=columns)
Expand All @@ -60,9 +49,9 @@ def create_df(file, first_col=None, int_cols=None):
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])

#series/operational to DataFrame
return create_df(file, first_col='Date', int_cols=[17,18,19])
"""
212 changes: 212 additions & 0 deletions iers/formats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
col_bc_lps = ['MJD', 'day', 'month', 'year', 'TAI-UTC']

col_psi_eps =[ #Psi,Eps
'MJD','PM-X','PM-Y','UT1-TAI',
'DPSI','DEPS',#PPP
'X-ERR','Y-ERR','UT1-ERR',
'DPSI-ERR','DEPS-ERR', #PPP
'RMS DELAY','CORR X-Y','CORR X-U','CORR Y-U',
'CORR DP-DE', #ppp
'IND1','IND2','IND3','XRT','YRT','LOD',
'DPSIRT','DEPSRT', #PPP
'XRT-ERR','YRT-ERR','LOD-ERR',
'DPSIRT-ERR','DEPSRT-ERR' # PPP
]


col_x_y = [ #x,y
'MJD','PM-X','PM-Y','UT1-TAI',
'DX','DY', #ppp
'X-ERR','Y-ERR','UT1-ERR',
'DX-ERR','DY-ERR', #ppp
'RMS DELAY','CORR X-Y','CORR X-U','CORR Y-U',
'CORR DX-DY', #ppp
'IND1','IND2','IND3','XRT','YRT','LOD',
'DXRT','DYRT', # ppp
'XRT-ERR','YRT-ERR','LOD-ERR',
'DXRT-ERR','DYRT-ERR' #
]

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

col_x_y_brief = [
'an','x','x_er','y','y_er','UT1-TAI','UT1_er',
'dX','dX_er','dY','dY_er' # ppp
]

col_psi_eps_brief_02 = [
'year','month','day','mjd','x','y','UT1-UTC','LOD',
'dPsi','dEps',
'x_er','y_er','UT1-UTC_er','LOD_err',
'dPsi_er','dEps_er'
]

col_x_y_brief_02 = [
'year','month','day','mjd','x','y','UT1-UTC','LOD',
'dX','dY',
'x_er','y_er','UT1-UTC_er','LOD_err',
'dX_er','dY_er'
]


col_x_y_03 = [
'year','month','day','hour','mjd','x','y','UT1-UTC',
'dX','dY','xrt','yrt','LOD',
'x_er','y_er','UT1-UTC_er','dX_er','dY_er',
'xrt_er','yrt_er','LOD_er'
]

col_psi_eps_03 = [
'year','month','day','hour','mjd','x','y','UT1-UTC',
'dPsi','dEps','xrt','yrt','LOD',
'x_er','y_er','UT1-UTC_er','dPsi_er','dEps_er',
'xrt_er','yrt_er','LOD_er'
]


files_dc = {

'Leap_Second.dat': {# delete year,month,day
'adr': 'bul/bulc/',
'cols': col_bc_lps,
'int': [2,3,4,5],
},

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

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

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

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

'filtered-pole.tab': { #1900-2023
'adr': 'eop/eopc01/',
'cols': ['year', 'xf', 'yf'],
'int': [],
},

'mean-pole.tab': { #1900-2016
'adr': 'eop/eopc01/',
'cols': ['year', 'xm', 'ym'],
'int': [],
},

'eopc04.62-now': {
'adr': 'eop/eopc04/',
'cols': col_psi_eps_brief_02,
'int': [1,2,3],
},

'eopc04.dPsi_dEps.12h.84-now': {
'adr': 'eop/eopc04/',
'cols': col_psi_eps_brief_02[:3]+['hour']+col_psi_eps_brief_02[3:],
'int': [1,2,3,4],
},

'eopc04.dPsi_dEps.62-now': {
'adr': 'eop/eopc04/',
'cols': col_psi_eps_brief_02,
'int': [1,2,3],
},

'eopc04.dX_dY.12h.84-now': {
'adr': 'eop/eopc04/',
'cols': col_x_y_brief_02[:3]+['hour']+col_x_y_brief_02[3:],
'int': [1,2,3,4],
},

'eopc04_IAU2000.62-now': {
'adr': 'eop/eopc04/',
'cols': col_x_y_brief_02,
'int': [],
},

'eopc04.12h.1984-now': {
'adr': 'eop/eopc04_20/',
'cols': col_x_y_03,
'int': [1,2,3,4],
},

'eopc04.1962-now': {
'adr': 'eop/eopc04_20/',
'cols': col_x_y_03,
'int': [1,2,3,4],
},

'eopc04.dPsi_dEps.12h.1984-now': {
'adr': 'eop/eopc04_20/',
'cols': col_psi_eps_03,
'int': [1,2,3,4],
},

'eopc04.dPsi_dEps.1962-now': {
'adr': 'eop/eopc04_20/',
'cols': col_psi_eps_03,
'int': [],
},

# SERIES
'bkg_r.eop': {
'adr': 'series/operational/',
'cols': col_psi_eps[:3] + ['UT1-UTC'] + col_psi_eps[4:],
'int': [17,18,19],
},

'eopc02.1830-now': {
'adr': 'series/longterm/',
'cols': col_psi_eps,
'int': [17,18,19],
},

'hmnao_a_2021.eop': {
'adr': 'series/longterm/',
'cols': col_psi_eps,
'int': [17,18,19],
},

'eopc04_extended.dat': {
'adr': 'series/prediction/',
'cols': col_x_y_brief_02,
'int': [1,2,3],
},

'eopc04R35d_IAU2000_daily': {
'adr': 'series/opa/',
'cols': col_x_y_brief_02,
'int': [1,2,3],
},

'eopc04R35d_IAU2000': {
'adr': 'series/opa/',
'cols': col_x_y_brief_02,
'int': [1,2,3],
},


}





Loading

0 comments on commit 0cfba33

Please sign in to comment.