Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
pythonic api
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Apr 24, 2017
1 parent c93d4b8 commit ca5305b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 53 deletions.
50 changes: 50 additions & 0 deletions gridaurora/__init__.py
@@ -0,0 +1,50 @@
from __future__ import print_function
try:
from pathlib import Path
Path().expanduser()
except (ImportError,AttributeError):
from pathlib2 import Path
#

def readmonthlyApF107(yearmon,fn=None):
"""
We should use:
ftp://ftp.ngdc.noaa.gov/STP/GEOMAGNETIC_DATA/INDICES/KP_AP/
but for now use:
ftp://ftp.swpc.noaa.gov/pub/weekly/RecentIndices.txt
Michael Hirsch, Ph.D.
"""
if not fn:
fn = Path(__file__).parent / 'data' / 'RecentIndices.txt'

fn = Path(fn).expanduser()
#%% date handle
if isinstance(yearmon,str):
yearmon = parse(yearmon)
#not elif
if isinstance(yearmon,datetime):
yearmon = int(str(yearmon.year) + '{:02d}'.format(yearmon.month))

assert isinstance(yearmon,int)
#%% load data
if not fn.is_file():
raise FileNotFoundError(str(fn.resolve()) +' download from ftp://ftp.swpc.noaa.gov/pub/weekly/RecentIndices.txt')

d = loadtxt(str(fn),comments=('#',':'), usecols=(0,1,7,8,9,10))
# genfromtxt didn't eliminate missing values, unsure if bug
# d = genfromtxt(fn,comments='#', usecols=(0,1,7,8,9,10), skip_header=2,dtype=float,
# missing_values={-1:-1},filling_values={-1:nan},invalid_raise=False)
#%% process and pack data
ind=[]
for ym in d[:,:2]:
ind.append(int(str(int(ym[0])) + '{:02d}'.format(int(ym[1]))))

data = DataFrame(index=ind,data=d[:,2:],columns=['f107o','f107s','Apo','Aps'])

data[data==-1] = nan #by defn of NOAA

ApF107 = data.loc[yearmon,:]

return ApF107
52 changes: 0 additions & 52 deletions gridaurora/readApF107.py

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -18,7 +18,7 @@
author='Michael Hirsch, Ph.D.',
description='Gridding for auroral and ionospheric modeling',
url='https://github.com/scivision/gridaurora',
version='1.0.5',
version='1.1.0',
package_data={'gridaurora':['data/RecentIndices.txt'],
'gridaurora.precompute': ['*.h5']},
classifiers=[
Expand Down

0 comments on commit ca5305b

Please sign in to comment.