Skip to content

Commit

Permalink
Merge pull request #20 from pysat/develop
Browse files Browse the repository at this point in the history
v0.1.2 release
  • Loading branch information
jklenzing authored Aug 14, 2020
2 parents 980f045 + 47bc0f1 commit 953ed76
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 185 deletions.
5 changes: 0 additions & 5 deletions .coveragerc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ your test configuration

# Checklist:

- [ ] Make sure you are merging into the ``develop`` (not ``master``) branch
- [ ] Make sure you are merging into the ``develop`` (not ``main``) branch
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
Expand Down
68 changes: 41 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
language: python
dist: xenial
matrix:
jobs:
include:
- python: 2.7
- python: 3.5
- name: Minimum NEP 029 versions
python: 3.6
env: NUMPY_VER=1.15
# Versions with latest numpy
- python: 3.6
- python: 3.7

Expand All @@ -13,44 +15,56 @@ addons:
packages:
- gfortran

before_install:
- pip install pytest-cov
- pip install coveralls
- pip install future
# Install version specific packages for 2.7 and 3.5
- pip install 'pandas<0.25'
- pip install xarray
- pip install matplotlib
# Install pysatCDF and dump output
install:
- sudo apt-get update
# We do this conditionally because it saves us some downloading if the
# version is the same.
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
- bash miniconda.sh -b -p $HOME/miniconda
- source "$HOME/miniconda/etc/profile.d/conda.sh"
- hash -r
- conda config --set always_yes True --set changeps1 False
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a
# Create conda test environment
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy scipy requests beautifulsoup4 lxml netCDF4 nose pytest-cov pytest-ordering coveralls future
- conda activate test-environment
# check for custom version of numpy
- if [ -z ${NUMPY_VER} ]; then
echo 'Using latest numpy';
else
conda install numpy==$NUMPY_VER;
fi
# Enforce version limits due to use of Panel
- conda install pandas==0.24.2
- conda install 'xarray<0.15'
# Dependencies not available through conda, install through pip
- pip install PyForecastTools
- pip install pysatCDF >/dev/null
# Prepare modified pysat install
- pip install numpy
# Get latest coveralls from pip, not conda
- pip install coveralls
- pip install pytest-flake8
# Prepare pysat install from git
- cd ..
- echo 'cloning pysat'
- git clone https://github.com/pysat/pysat.git >/dev/null
- echo 'installing pysat'
- cd ./pysat
- git checkout no_sgp4
# set up data directory
- mkdir /home/travis/build/pysat/pysatData
- mkdir /home/travis/build/pysatData
# install pysat
- cd /home/travis/build/pysat/pysat
- git checkout develop-3
- python setup.py install >/dev/null
- cd /home/travis/build/pysat/pysatSeasons

install:
- export PYTHONPATH=$PYTHONPATH:$(pwd)
# install pysatSeasons
- cd ../pysatSeasons
- python setup.py install

before_script:
# set up display screen
- export DISPLAY=:99.0
- if [[ $TRAVIS_PYTHON_VERSION < "3.0" ]]; then
sh -e /etc/init.d/xvfb start;
sleep 3;
fi

script:
- pytest -vs --cov=pysatSeasons/
- pytest -vs --cov=pysatSeasons/ --flake8

after_success:
- coveralls
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.1.2] - 2020-07-29
- Updates demo codes to import objects from datetime and pandas for pysat 3.0.0 compatibility
- Fixed a bug where test routines used float where numpy 1.18 expects an int
- Import objects from datetime and pandas for pysat 3.0.0 compatibility
- Use conda to manage Travis CI
- Rename default branch as `main`
- Update to pysat documentation standards
- Add flake8 testing for code

## [0.1.1] - 2019-10-09
- Add demo code
- Added DOI badge to documentation page
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
</div>

# pysatSeasons
[![Build Status](https://travis-ci.org/pysat/pysatSeasons.svg?branch=master)](https://travis-ci.org/pysat/pysatSeasons)
[![Coverage Status](https://coveralls.io/repos/github/pysat/pysatSeasons/badge.svg?branch=master)](https://coveralls.io/github/pysat/pysatSeasons?branch=master)
[![Build Status](https://travis-ci.org/pysat/pysatSeasons.svg?branch=main)](https://travis-ci.org/pysat/pysatSeasons)
[![Coverage Status](https://coveralls.io/repos/github/pysat/pysatSeasons/badge.svg?branch=main)](https://coveralls.io/github/pysat/pysatSeasons?branch=main)
[![DOI](https://zenodo.org/badge/209365329.svg)](https://zenodo.org/badge/latestdoi/209365329)


Expand Down
42 changes: 22 additions & 20 deletions demo/cosmic_and_ivm_demo.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import pysat
import pysatSeasons
import pandas as pds
import datetime as dt
import numpy as np
import numpy.ma as ma
import matplotlib.pyplot as plt
import pandas as pds

import pysat
import pysatSeasons

# dates for demo
ssnDays = 67
startDate = pds.datetime(2009, 12, 21) - pds.DateOffset(days=ssnDays)
stopDate = pds.datetime(2009, 12, 21) + pds.DateOffset(days=ssnDays)
startDate = dt.datetime(2009, 12, 21) - pds.DateOffset(days=ssnDays)
stopDate = dt.datetime(2009, 12, 21) + pds.DateOffset(days=ssnDays)


# define functions to customize data for application
Expand Down Expand Up @@ -65,7 +67,7 @@ def geo2mag(incoord):
r = 1.0

# convert first to radians
lon, lat = [x*pi/180 for x in [lon, lat]]
lon, lat = [x * pi / 180 for x in [lon, lat]]

glat = incoord[0] * pi / 180.0
glon = incoord[1] * pi / 180.0
Expand Down Expand Up @@ -96,7 +98,7 @@ def geo2mag(incoord):
tomaglat[1, 1] = 1.
out = dot(tomaglat, out)

mlat = arctan2(out[2], sqrt(out[0]*out[0] + out[1]*out[1]))
mlat = arctan2(out[2], sqrt((out[0] * out[0]) + (out[1] * out[1])))
mlat = mlat * 180 / pi
mlon = arctan2(out[1], out[0])
mlon = mlon * 180 / pi
Expand All @@ -119,8 +121,8 @@ def restrictMLAT(inst, maxMLAT=None):

def filterMLAT(inst, mlatRange=None):
if mlatRange is not None:
inst.data = inst.data[(np.abs(inst['mlat']) >= mlatRange[0]) &
(np.abs(inst['mlat']) <= mlatRange[1])]
inst.data = inst.data[(np.abs(inst['mlat']) >= mlatRange[0])
& (np.abs(inst['mlat']) <= mlatRange[1])]
return


Expand All @@ -137,9 +139,9 @@ def addTopsideScaleHeight(cosmic):
output.name = 'thf2'

for i, profile in enumerate(cosmic['profiles']):
profile = profile[(profile['ELEC_dens'] >=
(1./np.e) * cosmic['edmax'].iloc[i]) &
(profile.index >= cosmic['edmaxalt'].iloc[i])]
profile = profile[(profile['ELEC_dens']
>= (1. / np.e) * cosmic['edmax'].iloc[i])
& (profile.index >= cosmic['edmaxalt'].iloc[i])]
# want the first altitude where density drops below NmF2/e
# first, resample such that we know all altitudes in between samples
# are there
Expand All @@ -157,8 +159,8 @@ def addTopsideScaleHeight(cosmic):

if len(profile) > 10:
# make sure density at highest altitude is near Nm/e
if (profile['ELEC_dens'].iloc[-1]/profile['ELEC_dens'].iloc[0] <
0.4):
if (profile['ELEC_dens'].iloc[-1] / profile['ELEC_dens'].iloc[0]
< 0.4):
altDiff = profile.index.values[-1] - profile.index.values[0]
if altDiff >= 500:
altDiff = np.nan
Expand All @@ -176,7 +178,7 @@ def addTopsideScaleHeight(cosmic):
name='ivm', tag='',
clean_level='clean')
# restrict meausurements to those near geomagnetic equator
ivm.custom.add(restrictMLAT, 'modify', maxMLAT=25.)
ivm.custom.attach(restrictMLAT, 'modify', maxMLAT=25.)
# perform seasonal average
ivm.bounds = (startDate, stopDate)
ivmResults = pysatSeasons.avg.median2D(ivm, [0, 360, 24], 'alon',
Expand All @@ -189,13 +191,13 @@ def addTopsideScaleHeight(cosmic):
clean_level='clean',
altitude_bin=3)
# apply custom functions to all data that is loaded through cosmic
cosmic.custom.add(addApexLong, 'add')
cosmic.custom.attach(addApexLong, 'add')
# select locations near the magnetic equator
cosmic.custom.add(filterMLAT, 'modify', mlatRange=(0., 10.))
cosmic.custom.attach(filterMLAT, 'modify', mlatRange=(0., 10.))
# take the log of NmF2 and add to the dataframe
cosmic.custom.add(addlogNm, 'add')
cosmic.custom.attach(addlogNm, 'add')
# calculates the height above hmF2 to reach Ne < NmF2/e
cosmic.custom.add(addTopsideScaleHeight, 'add')
cosmic.custom.attach(addTopsideScaleHeight, 'add')

# do an average of multiple COSMIC data products
# from startDate through stopDate
Expand Down Expand Up @@ -294,7 +296,7 @@ def addTopsideScaleHeight(cosmic):
temp = pds.DataFrame(ltview['ELEC_dens'])
# produce a grid covering plot region
# (y values determined by profile)
xx, yy = np.meshgrid(np.array([i, i+1]), temp.index.values)
xx, yy = np.meshgrid(np.array([i, i + 1]), temp.index.values)
filtered = ma.array(np.log10(temp.values),
mask=pds.isnull(temp))
graph = axarr[j].pcolormesh(xx, yy, filtered,
Expand Down
13 changes: 8 additions & 5 deletions demo/ssnl_occurrence_by_orbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
the occurrent probability of an event occurring.
"""

import datetime as dt
import numpy as np
import os

import matplotlib.pyplot as plt

import pysat
import pysatSeasons
import matplotlib.pyplot as plt
import numpy as np

# set the directory to save plots to
results_dir = ''
Expand All @@ -26,10 +29,10 @@ def filter_vefi(inst):
return


vefi.custom.add(filter_vefi, 'modify')
vefi.custom.attach(filter_vefi, 'modify')
# set limits on dates analysis will cover, inclusive
start = pysat.datetime(2010, 5, 9)
stop = pysat.datetime(2010, 5, 15)
start = dt.datetime(2010, 5, 9)
stop = dt.datetime(2010, 5, 15)

# if there is no vefi dc magnetometer data on your system, then run command
# below where start and stop are pandas datetimes (from above)
Expand Down
9 changes: 5 additions & 4 deletions pysatSeasons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

import os

from pysatSeasons import occur_prob
from pysatSeasons import avg
from pysatSeasons import plot
from pysatSeasons._core import computational_form
# Import key modules and skip F401 testing in flake8
from pysatSeasons import occur_prob # noqa: F401
from pysatSeasons import avg # noqa: F401
from pysatSeasons import plot # noqa: F401
from pysatSeasons._core import computational_form # noqa: F401

# set version
here = os.path.abspath(os.path.dirname(__file__))
Expand Down
16 changes: 9 additions & 7 deletions pysatSeasons/_core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pandas as pds


def computational_form(data):
"""
Repackages numbers, Series, or DataFrames
Expand All @@ -21,15 +24,14 @@ def computational_form(data):
-------
pandas.Series, DataFrame, or Panel
repacked data, aligned by indices, ready for calculation
"""
from pysat import DataFrame, Series, Panel
"""

if isinstance(data.iloc[0], DataFrame):
dslice = Panel.from_dict(dict([(i, data.iloc[i])
for i in range(len(data))]))
elif isinstance(data.iloc[0], Series):
dslice = DataFrame(data.tolist())
if isinstance(data.iloc[0], pds.DataFrame):
dslice = pds.Panel.from_dict(dict([(i, data.iloc[i])
for i in range(len(data))]))
elif isinstance(data.iloc[0], pds.Series):
dslice = pds.DataFrame(data.tolist())
dslice.index = data.index
else:
dslice = data
Expand Down
Loading

0 comments on commit 953ed76

Please sign in to comment.