In [51]:
# setup
from planet4 import io
import tempfile
import numpy as np
import planet4 as p4
from pathlib import Path
import datetime as dt
from numpy.testing import assert_array_equal
import datetime as dt
import pytest
import pkg_resources as pr
datapath = Path(pr.resource_filename('planet4', 'data'))
In [52]:
io.get_data_root()
Out[52]:
In [53]:
io.configpath
Out[53]:
In [79]:
pm = io.PathManager('007')#, obsid='PSP_0030982_0985')
In [80]:
pm.datapath
Out[80]:
In [81]:
pm.reduced_blotchfile
Out[81]:
In [82]:
pm.blotchfile
Out[82]:
In [83]:
pm.final_blotchfile
Out[83]:
In [43]:
obsid = 'PSP_003092_0985'
pm = io.PathManager('something', obsid=obsid)
assert pm.datapath == Path('/abc/db/clustering') / obsid
In [50]:
pm.datapath
Out[50]:
In [45]:
Path.home() / obsid
Out[45]:
In [7]:
def mockreturn():
return Path('/abc')
In [11]:
def test_dataroot(monkeypatch):
monkeypatch.setattr(io, 'dataroot', mockreturn)
print(io.dataroot)
In [ ]:
In [2]:
# test_P4DBName
name = '2015-10-21_planet_four_classifications.csv'
p4db = io.P4DBName(name)
assert p4db.name == name
assert p4db.p == Path(name)
assert p4db.parent == Path('.')
assert p4db.date == dt.datetime(2015, 10, 21)
In [3]:
# test_get_image_names_from_db
result = io.get_image_names_from_db(datapath / 'test_db.csv')
expected = np.array(['APF000012q', 'APF000012w'])
assert_array_equal(expected, result)
In [4]:
# test_get_latest_file
l = ['2015-12-01_test.h5','2015-11-01_test.h5']
assert io.get_latest_file(l) == Path(l[0])
# empty list should raise NoFilesFoundError
with pytest.raises(p4.exceptions.NoFilesFoundError):
io.get_latest_file([])
In [5]:
# test_PathManager_default_setup
pm = io.PathManager('1234')
assert pm.fanfile == Path('/tmp/ABC0001234_fans.csv')
assert pm.blotchfile == Path('/tmp/ABC0001234_blotches.csv')
assert pm.fnotchfile == Path('/tmp/ABC0001234_fnotches.csv')
In [6]:
pm.fanfile
Out[6]:
In [ ]:
# test_PathManager_different_suffix
pm = io.PathManager('/tmp', suffix='.hdf')
pm.id_ = 'ABC0001234'
assert pm.fanfile == Path('/tmp/ABC0001234_fans.hdf')
assert pm.blotchfile == Path('/tmp/ABC0001234_blotches.hdf')
assert pm.fnotchfile == Path('/tmp/ABC0001234_fnotches.hdf')
In [ ]:
# test_PathManager_suffix_.csv
pm = io.PathManager('/tmp', suffix='.csv')
pm.id_ = 'ABC0001234'
assert pm.fanfile == Path('/tmp/ABC0001234_fans.csv')
assert pm.blotchfile == Path('/tmp/ABC0001234_blotches.csv')
assert pm.fnotchfile == Path('/tmp/ABC0001234_fnotches.csv')
In [ ]:
# test_PathManager_with_image_name
image_name = 'PSP_012345_6789'
pm = io.PathManager('/tmp', image_name=image_name, suffix='.csv')
pm.id_ = 'ABC0001234'
assert pm.fanfile == Path('/tmp/' + image_name + '/ABC0001234_fans.csv')
In [ ]: