Skip to content

Commit

Permalink
Merge pull request #17 from pysat/pysat3_update
Browse files Browse the repository at this point in the history
BUG/STY: update code to be compliant with numpy, pandas, and pysat development paths
  • Loading branch information
jklenzing committed Apr 27, 2020
2 parents 7b1c89c + 0687c7e commit 74fa185
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 29 deletions.
16 changes: 12 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ jobs:
# Versions with latest numpy
- python: 3.6
- python: 3.7
- python: 3.8

services: xvfb
addons:
Expand All @@ -29,21 +28,30 @@ install:
# 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 pandas xarray requests beautifulsoup4 lxml netCDF4 nose pytest-cov pytest-ordering coveralls future
- 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 -q numpy==$NUMPY_VER;
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 pysat install from git
- cd ..
- git clone https://github.com/pysat/pysat.git >/dev/null
- cd ./pysat
# set up data directory
- mkdir /home/travis/build/pysatData
# install pysat
- python setup.py install
- git checkout develop-3
- python setup.py install >/dev/null
- export PYTHONPATH=$PYTHONPATH:$(pwd)
# install pysatSeasons
- cd ../pysatSeasons
- python setup.py install
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ 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-04-25
- 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

Expand Down
22 changes: 12 additions & 10 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 @@ -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
2 changes: 1 addition & 1 deletion demo/ssnl_occurrence_by_orbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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 = dt.datetime(2010, 5, 9)
stop = dt.datetime(2010, 5, 15)
Expand Down
28 changes: 14 additions & 14 deletions pysatSeasons/tests/test_avg.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def teardown(self):
def test_basic_seasonal_median2D(self):
""" Test the basic seasonal 2D median"""
self.testInst.bounds = self.bounds1
results = avg.median2D(self.testInst, [0., 360., 24.], 'longitude',
[0., 24, 24], 'mlt',
results = avg.median2D(self.testInst, [0., 360., 24], 'longitude',
[0., 24., 24], 'mlt',
['dummy1', 'dummy2', 'dummy3'])
dummy_val = results['dummy1']['median']
dummy_dev = results['dummy1']['avg_abs_dev']
Expand Down Expand Up @@ -109,8 +109,8 @@ def teardown(self):
def test_basic_seasonal_2Dmedian(self):
""" Test the basic seasonal 2D median"""

results = avg.median2D(self.testInst, [0., 360., 24.], 'longitude',
[0., 24, 24], 'mlt', [self.dname])
results = avg.median2D(self.testInst, [0., 360., 24], 'longitude',
[0., 24., 24], 'mlt', [self.dname])

# iterate over all
# no variation in the median, all values should be the same
Expand Down Expand Up @@ -156,8 +156,8 @@ def teardown(self):

def test_basic_seasonal_median2D(self):
""" Test basic seasonal 2D median"""
results = avg.median2D(self.testInst, [0., 360., 24.], 'longitude',
[0., 24, 24], 'mlt', [self.dname])
results = avg.median2D(self.testInst, [0., 360., 24], 'longitude',
[0., 24., 24], 'mlt', [self.dname])

# iterate over all
# no variation in the median, all values should be the same
Expand All @@ -172,7 +172,7 @@ def test_basic_seasonal_median2D(self):

def test_basic_seasonal_median1D(self):
""" Test basic seasonal 1D median"""
results = avg.median1D(self.testInst, [0., 24, 24], 'mlt',
results = avg.median1D(self.testInst, [0., 24., 24], 'mlt',
[self.dname])

# iterate over all
Expand Down Expand Up @@ -203,11 +203,11 @@ def test_constellation_median2D(self):
for i in self.testC.instruments:
i.bounds = self.bounds
self.testI.bounds = self.bounds
resultsC = avg.median2D(self.testC, [0., 360., 24.], 'longitude',
[0., 24, 24], 'mlt',
resultsC = avg.median2D(self.testC, [0., 360., 24], 'longitude',
[0., 24., 24], 'mlt',
['dummy1', 'dummy2', 'dummy3'])
resultsI = avg.median2D(self.testI, [0., 360., 24.], 'longitude',
[0., 24, 24], 'mlt',
resultsI = avg.median2D(self.testI, [0., 360., 24], 'longitude',
[0., 24., 24], 'mlt',
['dummy1', 'dummy2', 'dummy3'])
medC1 = resultsC['dummy1']['median']
medI1 = resultsI['dummy1']['median']
Expand Down Expand Up @@ -259,8 +259,8 @@ def test_heterogenous_constellation_median2D(self):
""" Test the seasonal 2D median of a heterogeneous constellation """
for inst in self.testC:
inst.bounds = self.bounds
results = avg.median2D(self.testC, [0., 360., 24.], 'longitude',
[0., 24, 24], 'mlt',
results = avg.median2D(self.testC, [0., 360., 24], 'longitude',
[0., 24., 24], 'mlt',
['dummy1', 'dummy2', 'dummy3'])
dummy_val = results['dummy1']['median']
dummy_dev = results['dummy1']['avg_abs_dev']
Expand Down Expand Up @@ -462,7 +462,7 @@ def setup(self):
112023., 111562., 112023., 111412.,
111780., 111320., 111780., 111320.],
'avg_abs_dev': np.zeros(shape=24),
'median': np.linspace(0.0, 23.0, 24.0)},
'median': np.linspace(0.0, 23.0, 24)},
'dummy2':
{'count': [111780., 111320., 111780., 111320.,
111780., 111320., 111780., 111320.,
Expand Down

0 comments on commit 74fa185

Please sign in to comment.