def test_find_datasets(): # find all datasets matching pattern r = datasets.find_all_matching_datasets(r"(.*)\.camgeom\.fits\.gz") assert len(r) > 3 # get the full filename for a resrouces assert datasets.get_dataset_path(r[0].name).exists() # try using a pattern r = datasets.find_all_matching_datasets(r"(.*)\.camgeom\.fits\.gz", regexp_group=1) assert not str(r[0]).endswith("gz")
def _info_resources(): """ display all known resources """ print('\n*** ctapipe resources ***\n') print("ctapipe_resources version: {}".format( ctapipe_resources.__version__)) print("CTAPIPE_SVC_PATH: (directories where resources are searched)") if os.getenv('CTAPIPE_SVC_PATH') is not None: for dir in datasets.get_searchpath_dirs(): print("\t * {}".format(dir)) else: print("\t no path is set") print("") all_resources = sorted(datasets.find_all_matching_datasets("\w.*")) locations = [ os.path.dirname(datasets.get_dataset(name)) for name in all_resources ] home = os.path.expanduser("~") resource_dir = os.path.dirname( datasets.get_dataset("HESS-I.camgeom.fits.gz")) fmt = "{name:<30.30s} : {loc:<30.30s}" print(fmt.format(name="RESOURCE NAME", loc="LOCATION")) print("-" * 70) for name, loc in zip(all_resources, locations): if name.endswith(".py") or name.startswith("_"): continue loc = loc.replace(resource_dir, "[ctapipe_resources]") loc = loc.replace(home, "~") print(fmt.format(name=name, loc=loc))
def test_datasets_in_custom_path(tmpdir_factory): """ check that a dataset in a user-defined CTAPIPE_SVC_PATH is located """ tmpdir1 = tmpdir_factory.mktemp('datasets1') tmpdir2 = tmpdir_factory.mktemp('datasets2') os.environ['CTAPIPE_SVC_PATH'] = ":".join([str(tmpdir1), str(tmpdir2)]) # create a dummy dataset to search for: dataset_name = "test_dataset_1.txt" dataset_path = str(tmpdir1.join(dataset_name)) with open(dataset_path, "w") as fp: fp.write("test test test") # try to find dummy dataset path = datasets.get_dataset_path(dataset_name) assert path == dataset_path with pytest.raises(FileNotFoundError): datasets.get_dataset_path("does_not_exist") # try using find_all_matching_datasets: ds = datasets.find_all_matching_datasets("test.*", searchpath=os.environ[ 'CTAPIPE_SVC_PATH']) assert dataset_name in ds
def _info_resources(): """ display all known resources """ print('\n*** ctapipe resources ***\n') print("ctapipe_resources version: {}".format(ctapipe_resources.__version__)) print("CTAPIPE_SVC_PATH: (directories where resources are searched)") if os.getenv('CTAPIPE_SVC_PATH') is not None: for dir in datasets.get_searchpath_dirs(): print("\t * {}".format(dir)) else: print("\t no path is set") print("") all_resources = sorted(datasets.find_all_matching_datasets("\w.*")) locations = [os.path.dirname(datasets.get_dataset(name)) for name in all_resources] home = os.path.expanduser("~") resource_dir = os.path.dirname(datasets.get_dataset( "HESS-I.camgeom.fits.gz")) fmt = "{name:<30.30s} : {loc:<30.30s}" print(fmt.format(name="RESOURCE NAME", loc="LOCATION")) print("-"*70) for name, loc in zip(all_resources, locations): if name.endswith(".py") or name.startswith("_"): continue loc = loc.replace(resource_dir, "[ctapipe_resources]") loc = loc.replace(home, "~") print(fmt.format(name=name, loc=loc))