def test_get_transform_grid_list__bbox__out_of_bounds(): grids = get_transform_grid_list(bbox=BBox(170, -90, 190, 90), include_already_downloaded=True) assert len(grids) > 10 source_ids = set() for grid in grids: source_ids.add(grid["properties"]["source_id"]) assert sorted(source_ids) == [ "au_ga", "nc_dittt", "nz_linz", "us_nga", "us_noaa" ]
def test_get_transform_grid_list__contains(): grids = get_transform_grid_list( bbox=BBox(170, -90, -170, 90), spatial_test="contains", include_already_downloaded=True, ) assert len(grids) > 5 source_ids = set() for grid in grids: source_ids.add(grid["properties"]["source_id"]) assert sorted(source_ids) == ["nz_linz"]
def test_get_transform_grid_list__source_id(): grids = get_transform_grid_list( bbox=BBox(170, -90, -170, 90), source_id="us_noaa", include_already_downloaded=True, ) assert len(grids) > 5 source_ids = set() for grid in grids: source_ids.add(grid["properties"]["source_id"]) assert sorted(source_ids) == ["us_noaa"]
def test_not_intersects(): assert not BBox(1, 1, 4, 4).intersects(BBox(10, 10, 20, 20))
def test_intersects(): assert BBox(1, 1, 4, 4).intersects(BBox(2, 2, 5, 5))
def test_not_contains(): assert not BBox(1, 1, 4, 4).contains(BBox(2, 2, 5, 5))
def test_contains(): assert BBox(1, 1, 4, 4).contains(BBox(2, 2, 3, 3))
def main(): args = parser.parse_args() if hasattr(args, "bbox") and any(( args.bbox, args.list_files, args.all, args.source_id, args.area_of_use, args.file, )): if args.all and (args.list_files or args.source_id or args.area_of_use or args.file or args.bbox): raise RuntimeError( "Cannot use '--all' with '--list-files', '--source-id'," "'--area-of-use', '--bbox', or '--file'.") bbox = None if args.bbox is not None: west, south, east, north = args.bbox.split(",") bbox = BBox( west=float(west), south=float(south), east=float(east), north=float(north), ) if args.target_directory and args.system_directory: raise RuntimeError( "Cannot set both --target-directory and --system-directory.") target_directory = args.target_directory if args.system_directory: target_directory = get_data_dir().split(os.path.sep)[0] elif not target_directory: target_directory = get_user_data_dir(True) grids = get_transform_grid_list( source_id=args.source_id, area_of_use=args.area_of_use, filename=args.file, bbox=bbox, spatial_test=args.spatial_test, include_world_coverage=not args.exclude_world_coverage, include_already_downloaded=args.include_already_downloaded, target_directory=target_directory, ) if args.list_files: print("filename | source_id | area_of_use") print("----------------------------------") else: endpoint = get_proj_endpoint() for grid in grids: if args.list_files: print( grid["properties"]["name"], grid["properties"]["source_id"], grid["properties"].get("area_of_use"), sep=" | ", ) else: filename = grid["properties"]["name"] _download_resource_file( file_url=f"{endpoint}/{filename}", short_name=filename, directory=target_directory, verbose=args.verbose, sha256=grid["properties"]["sha256sum"], ) elif not hasattr(args, "bbox") and args.verbose: _show_versions.show_versions() elif hasattr(args, "bbox"): sync_parser.print_help() else: parser.print_help()