本文整理汇总了Python中pysat.datetime函数的典型用法代码示例。如果您正苦于以下问题:Python datetime函数的具体用法?Python datetime怎么用?Python datetime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了datetime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_versioned_files
def create_versioned_files(inst, start=None, stop=None, freq='1D', use_doy=True,
root_fname=None):
# create a bunch of files
if start is None:
start = pysat.datetime(2009, 1, 1)
if stop is None:
stop = pysat.datetime(2013, 12, 31)
dates = pysat.utils.season_date_range(start, stop, freq=freq)
versions = np.array([1, 2])
revisions = np.array([0, 1])
if root_fname is None:
root_fname = 'pysat_testing_junk_{year:04d}_{month:02d}_{day:03d}{hour:02d}{min:02d}{sec:02d}_stuff_{version:02d}_{revision:03d}.pysat_testing_file'
# create empty file
for date in dates:
for version in versions:
for revision in revisions:
yr, doy = pysat.utils.getyrdoy(date)
if use_doy:
doy = doy
else:
doy = date.day
fname = os.path.join(inst.files.data_path, root_fname.format(year=yr,
day=doy, month=date.month, hour=date.hour,
min=date.minute, sec=date.second,
version=version, revision=revision))
with open(fname, 'w') as f:
pass
示例2: test_get_new_files_after_deleting_files_and_adding_files
def test_get_new_files_after_deleting_files_and_adding_files(self):
# create new files and make sure that new files are captured
start = pysat.datetime(2008, 1, 11)
stop = pysat.datetime(2008, 1, 12)
dates = pysat.utils.season_date_range(start, stop, freq='100min')
# remove files, same number as will be added
to_be_removed = len(dates)
for the_file in os.listdir(self.testInst.files.data_path):
if (the_file[0:13] == 'pysat_testing') & (the_file[-19:] == '.pysat_testing_file'):
file_path = os.path.join(self.testInst.files.data_path, the_file)
if os.path.isfile(file_path) & (to_be_removed > 0):
to_be_removed -= 1
# Remove all versions of the file
# otherwise, previous versions will look like new files
pattern = '_'.join(file_path.split('_')[0:7])+'*.pysat_testing_file'
map(os.unlink, glob.glob(pattern))
#os.unlink(file_path)
# add new files
create_versioned_files(self.testInst, start, stop, freq='100min',
use_doy=False,
root_fname=self.root_fname)
# get new files
new_files = self.testInst.files.get_new()
assert (np.all(new_files.index == dates))
示例3: test_refresh_on_unchanged_files
def test_refresh_on_unchanged_files(self):
start = pysat.datetime(2007, 12, 31)
stop = pysat.datetime(2008, 1, 10)
dates = pysat.utils.season_date_range(start, stop, freq='100min')
self.testInst.files.refresh()
assert (np.all(self.testInst.files.files.index == dates))
示例4: test_set_bounds_by_date_season
def test_set_bounds_by_date_season(self):
start = [pysat.datetime(2009,1,1), pysat.datetime(2009,2,1)]
stop = [pysat.datetime(2009,1,15), pysat.datetime(2009,2,15)]
self.testInst.bounds = (start, stop)
out = pds.date_range(start[0], stop[0]).tolist()
out.extend(pds.date_range(start[1], stop[1]).tolist())
assert np.all(self.testInst._iter_list == out)
示例5: test_basic_orbit_mean
def test_basic_orbit_mean(self):
orbit_info = {'kind':'local time', 'index':'mlt'}
self.testInst = pysat.Instrument('pysat','testing', clean_level='clean', orbit_info=orbit_info)
self.testInst.bounds = (pysat.datetime(2009,1,1), pysat.datetime(2009,1,2))
ans = pysat.ssnl.avg.mean_by_orbit(self.testInst, 'mlt')
# note last orbit is incomplete thus not expected to satisfy relation
assert np.allclose(ans[:-1], np.ones(len(ans)-1)*12., 1.E-2)
示例6: test_heterogenous_constellation_average
def test_heterogenous_constellation_average(self):
for inst in self.testC:
inst.bounds = (pysat.datetime(2008,1,1), pysat.datetime(2008,2,1))
results = pysat.ssnl.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']
dummy2_val = results['dummy2']['median']
dummy2_dev = results['dummy2']['avg_abs_dev']
dummy3_val = results['dummy3']['median']
dummy3_dev = results['dummy3']['avg_abs_dev']
dummy_x = results['dummy1']['bin_x']
dummy_y = results['dummy1']['bin_y']
# iterate over all y rows, value should be equal to integer value of mlt
# no variation in the median, all values should be the same
check = []
for i, y in enumerate(dummy_y[:-1]):
check.append(np.all(dummy_val[i, :] == y.astype(int)))
check.append(np.all(dummy_dev[i, :] == 0))
for i, x in enumerate(dummy_x[:-1]):
check.append(np.all(dummy2_val[:, i] == x/15.) )
check.append(np.all(dummy2_dev[:, i] == 0))
for i, x in enumerate(dummy_x[:-1]):
check.append(np.all(dummy3_val[:, i] == x/15.*1000. + dummy_y[:-1]) )
check.append(np.all(dummy3_dev[:, i] == 0))
assert np.all(check)
示例7: setup
def setup(self):
"""Runs before every method to create a clean testing setup."""
# store current pysat directory
self.data_path = pysat.data_dir
# create temporary directory
dir_name = tempfile.gettempdir()
pysat.utils.set_data_dir(dir_name, store=False)
# create testing directory
create_dir(temporary_file_list=self.temporary_file_list)
# create a test instrument, make sure it is getting files from filesystem
re_load(pysat.instruments.pysat_testing)
# self.stored_files_fcn = pysat.instruments.pysat_testing.list_files
pysat.instruments.pysat_testing.list_files = list_versioned_files
# create a bunch of files by year and doy
self.testInst = pysat.Instrument(inst_module=pysat.instruments.pysat_testing,
clean_level='clean',
temporary_file_list=self.temporary_file_list)
self.root_fname = 'pysat_testing_junk_{year:04d}_{month:02d}_{day:03d}{hour:02d}{min:02d}{sec:02d}_stuff_{version:02d}_{revision:03d}.pysat_testing_file'
start = pysat.datetime(2007, 12, 31)
stop = pysat.datetime(2008, 1, 10)
create_versioned_files(self.testInst, start, stop, freq='100min',
use_doy=False,
root_fname=self.root_fname)
self.testInst = pysat.Instrument(inst_module=pysat.instruments.pysat_testing,
clean_level='clean', update_files=True,
temporary_file_list=self.temporary_file_list)
示例8: test_files_non_standard_pysat_directory
def test_files_non_standard_pysat_directory(self):
# create new files and make sure that new files are captured
start = pysat.datetime(2008, 1, 11)
stop = pysat.datetime(2008, 1, 15)
dates = pysat.utils.season_date_range(start, stop, freq='100min')
pysat.instruments.pysat_testing.list_files = list_versioned_files
self.testInst = pysat.Instrument(inst_module=pysat.instruments.pysat_testing,
clean_level='clean',
sat_id='hello',
directory_format='pysat_testing_{tag}_{sat_id}',
update_files=True,
temporary_file_list=self.temporary_file_list)
# add new files
create_dir(self.testInst)
remove_files(self.testInst)
create_versioned_files(self.testInst, start, stop, freq='100min',
use_doy=False,
root_fname=self.root_fname)
self.testInst = pysat.Instrument(inst_module=pysat.instruments.pysat_testing,
clean_level='clean',
sat_id='hello',
directory_format='pysat_testing_{tag}_{sat_id}',
update_files=True,
temporary_file_list=self.temporary_file_list)
# get new files
new_files = self.testInst.files.get_new()
assert (np.all(self.testInst.files.files.index == dates) &
np.all(new_files.index == dates))
示例9: test_iterate_over_default_bounds
def test_iterate_over_default_bounds(self):
start = pysat.datetime(2008,1,1)
stop = pysat.datetime(2010,12,31)
self.testInst.bounds = (start, stop)
dates = []
for inst in self.testInst:
dates.append(inst.date)
out = pds.date_range(start, stop).tolist()
assert np.all(dates == out)
示例10: test_iterate_over_bounds_set_by_date_season
def test_iterate_over_bounds_set_by_date_season(self):
start = [pysat.datetime(2009,1,1), pysat.datetime(2009,2,1)]
stop = [pysat.datetime(2009,1,15), pysat.datetime(2009,2,15)]
self.testInst.bounds = (start, stop)
dates = []
for inst in self.testInst:
dates.append(inst.date)
out = pds.date_range(start[0], stop[0]).tolist()
out.extend(pds.date_range(start[1], stop[1]).tolist())
assert np.all(dates == out)
示例11: test_get_new_files_after_adding_files
def test_get_new_files_after_adding_files(self):
# create new files and make sure that new files are captured
start = pysat.datetime(2008, 1, 11)
stop = pysat.datetime(2008, 1, 12)
create_versioned_files(self.testInst, start, stop, freq='100min',
use_doy=False,
root_fname=self.root_fname)
dates = pysat.utils.season_date_range(start, stop, freq='100min')
new_files = self.testInst.files.get_new()
assert (np.all(new_files.index == dates))
示例12: test_iterate_over_bounds_set_by_fname
def test_iterate_over_bounds_set_by_fname(self):
start = '2009-01-01.nofile'
stop = '2009-01-15.nofile'
start_d = pysat.datetime(2009,1,1)
stop_d = pysat.datetime(2009,1,15)
self.testInst.bounds = (start, stop)
dates = []
for inst in self.testInst:
dates.append(inst.date)
out = pds.date_range(start_d, stop_d).tolist()
assert np.all(dates == out)
示例13: test_iterate_over_bounds_set_by_fname_season
def test_iterate_over_bounds_set_by_fname_season(self):
start = ['2009-01-01.nofile', '2009-02-01.nofile']
stop = ['2009-01-15.nofile', '2009-02-15.nofile']
start_d = [pysat.datetime(2009,1,1), pysat.datetime(2009,2,1)]
stop_d = [pysat.datetime(2009,1,15), pysat.datetime(2009,2,15)]
self.testInst.bounds = (start, stop)
dates = []
for inst in self.testInst:
dates.append(inst.date)
out = pds.date_range(start_d[0], stop_d[0]).tolist()
out.extend(pds.date_range(start_d[1], stop_d[1]).tolist())
assert np.all(dates == out)
示例14: test_refresh
def test_refresh(self):
# create new files and make sure that new files are captured
start = pysat.datetime(2008,1,10)
stop = pysat.datetime(2008,1,12)
create_files(self.testInst, start, stop, freq='100min',
use_doy=False,
root_fname = self.root_fname)
start = pysat.datetime(2007,12,31)
dates = pysat.utils.season_date_range(start, stop, freq='100min')
self.testInst.files.refresh()
assert (np.all(self.testInst.files.files.index == dates))
示例15: test_iterate_over_bounds_set_by_fname_via_prev
def test_iterate_over_bounds_set_by_fname_via_prev(self):
start = '2009-01-01.nofile'
stop = '2009-01-15.nofile'
start_d = pysat.datetime(2009,1,1)
stop_d = pysat.datetime(2009,1,15)
self.testInst.bounds = (start, stop)
dates = []
self.testInst.prev()
dates.append(self.testInst.date)
while self.testInst.date > start_d:
self.testInst.prev()
dates.append(self.testInst.date)
out = pds.date_range(start_d, stop_d).tolist()
assert np.all(dates == out[::-1])