Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
import pandas as pds
import numpy as np
import pysat
# pysat required parameters
platform = 'pysat'
name = 'testing'
# dictionary of data 'tags' and corresponding description
tags = {'': 'Regular testing data set'}
# dictionary of satellite IDs, list of corresponding tags
sat_ids = {'': ['']}
test_dates = {'': {'': pysat.datetime(2009, 1, 1)}}
meta = pysat.Meta()
meta['uts'] = {'units': 's', 'long_name': 'Universal Time', 'custom': False}
meta['mlt'] = {'units': 'hours', 'long_name': 'Magnetic Local Time'}
meta['slt'] = {'units': 'hours', 'long_name': 'Solar Local Time'}
def init(self):
self.new_thing = True
def load(fnames, tag=None, sat_id=None, sim_multi_file_right=False,
sim_multi_file_left=False, root_date=None):
# create an artifical satellite data set
parts = fnames[0].split('/')
yr = int('20' + parts[-1][0:2])
month = int(parts[-3])
day = int(parts[-2])
"""
import pandas as pds
import numpy as np
import pysat
# pysat required parameters
platform = 'pysat'
name = 'testing'
# dictionary of data 'tags' and corresponding description
tags = {'': 'Regular testing data set'}
# dictionary of satellite IDs, list of corresponding tags
sat_ids = {'': ['']}
test_dates = {'': {'': pysat.datetime(2009, 1, 1)}}
meta = pysat.Meta()
meta['uts'] = {'units': 's', 'long_name': 'Universal Time', 'custom': False}
meta['mlt'] = {'units': 'hours', 'long_name': 'Magnetic Local Time'}
meta['slt'] = {'units': 'hours', 'long_name': 'Solar Local Time'}
def init(self):
self.new_thing = True
def load(fnames, tag=None, sat_id=None, sim_multi_file_right=False,
sim_multi_file_left=False, root_date=None):
# create an artifical satellite data set
parts = fnames[0].split('/')
yr = int('20' + parts[-1][0:2])
month = int(parts[-3])
day = int(parts[-2])
# pysat required parameters
platform = 'pysat'
name = 'testadd1'
# dictionary of data 'tags' and corresponding description
tags = {'': 'Ascending Integers from 0 testing data set',
'negative': 'Descending Integers from 0 testing data set',
'plus10': 'Ascending Integers from 10 testing data set',
'five': 'All 5s testing data set'}
# dictionary of satellite IDs, list of corresponding tags
sat_ids = {'': ['', 'negative', 'plus10', 'five']}
test_dates = {'': {'': pysat.datetime(2009, 1, 1),
'negative': pysat.datetime(2009, 1, 1),
'plus10': pysat.datetime(2009, 1, 1),
'five': pysat.datetime(2009, 1, 1)}}
meta = pysat.Meta()
meta['uts'] = {'units': 's', 'long_name': 'Universal Time', 'custom': False}
meta['mlt'] = {'units': 'hours', 'long_name': 'Magnetic Local Time'}
meta['slt'] = {'units': 'hours', 'long_name': 'Solar Local Time'}
def init(self):
self.new_thing = True
def load(fnames, tag=None, sat_id=None, sim_multi_file_right=False,
sim_multi_file_left=False, root_date=None):
""" Loads the test files
Parameters
----------
fnames : (list)
# create an artifical satellite data set
parts = os.path.split(fnames[0])[-1].split('-')
yr = int(parts[0])
month = int(parts[1])
day = int(parts[2][0:2])
date = pysat.datetime(yr, month, day)
# scalar divisor below used to reduce the number of time samples
# covered by the simulation per day. The higher the number the lower
# the number of samples (86400/scalar)
scalar = 100
num = 86400/scalar
# basic time signal in UTS
uts = np.arange(num) * scalar
num_array = np.arange(num) * scalar
# seed DataFrame with UT array
data = pysat.DataFrame(uts, columns=['uts'])
# need to create simple orbits here. Have start of first orbit
# at 2009,1, 0 UT. 14.84 orbits per day
# figure out how far in time from the root start
# use that info to create a signal that is continuous from that start
# going to presume there are 5820 seconds per orbit (97 minute period)
time_delta = date - pysat.datetime(2009, 1, 1)
# root start
uts_root = np.mod(time_delta.total_seconds(), 5820)
# mlt runs 0-24 each orbit.
mlt = np.mod(uts_root+np.arange(num)*scalar, 5820) * (24./5820.)
data['mlt'] = mlt
# do slt, 20 second offset from mlt
uts_root = np.mod(time_delta.total_seconds() + 20, 5820)
data['slt'] = np.mod(uts_root + np.arange(num) * scalar,
5820) * (24./5820.)
def list_files(tag=None, sat_id=None, data_path=None, format_str=None):
"""Produce a fake list of files spanning a year"""
index = pds.date_range(pysat.datetime(2008, 1, 1),
pysat.datetime(2010, 12, 31))
names = [data_path + date.strftime('%D') + '.nofile' for date in index]
return pysat.Series(names, index=index)
day = int(parts[-2])
date = pysat.datetime(yr, month, day)
if sim_multi_file_right:
root_date = root_date or pysat.datetime(2009, 1, 1, 12)
data_date = date+pds.DateOffset(hours=12)
elif sim_multi_file_left:
root_date = root_date or pysat.datetime(2008, 12, 31, 12)
data_date = date-pds.DateOffset(hours=12)
else:
root_date = root_date or pysat.datetime(2009, 1, 1)
data_date = date
num = 86400 if tag is '' else int(tag)
num_array = np.arange(num)
uts = num_array
data = pysat.DataFrame(uts, columns=['uts'])
# need to create simple orbits here. Have start of first orbit
# at 2009,1, 0 UT. 14.84 orbits per day
time_delta = date - root_date
uts_root = np.mod(time_delta.total_seconds(), 5820)
mlt = np.mod(uts_root + num_array, 5820) * (24. / 5820.)
data['mlt'] = mlt
# fake orbit number
fake_delta = date - pysat.datetime(2008, 1, 1)
fake_uts_root = fake_delta.total_seconds()
data['orbit_num'] = ((fake_uts_root + num_array) / 5820.).astype(int)
# create a fake longitude, resets every 6240 seconds
# sat moves at 360/5820 deg/s, Earth rotates at 360/86400, takes extra time
import pysat
"""
Creates a constellationfor testing difference with two small test instruments
"""
inst1 = pysat.Instrument('pysat', 'testsmall', clean_level='clean', tag='6000')
inst2 = pysat.Instrument('pysat', 'testsmall', clean_level='clean', tag='6000')
instruments = [inst1, inst2]
# Test code for pandas ix deprecation tests
# Delete before merging pull request!
import pysat
date = pysat.datetime(2011,6,29)
ivm = pysat.Instrument(platform='cnofs', name='ivm',clean_level='none')
ivm.load(date=date)
# By name
print('input => Ni')
print(ivm['Ni'])
print('\n')
# Slicing by name
# print('input => zpos:zvel')
# print(ivm['zpos':'zvel'])
# print('\n')
# By position
print('input => 0, Ni')
print(ivm[0,'Ni'])
print('\n')
def setup(self):
reload(pysat.instruments.pysat_testing)
'''Runs before every method to create a clean testing setup.'''
self.testInst = pysat.Instrument('pysat', 'testing', '10', 'clean')
def test_custom_instrument_load(self):
'''
Test if the correct day is being loaded (End-to-End),
with no instrument file but routines are passed.
'''
import pysat.instruments.pysat_testing as test
testInst = pysat.Instrument(inst_module=test, tag='1000', clean_level='clean')
testInst.load(2009,32)
assert testInst.date == pds.datetime(2009,2,1)