code
stringlengths
17
6.64M
class DeepFM(BaseModel): 'Instantiates the DeepFM Network architecture.\n\n :param linear_feature_columns: An iterable containing all the features used by linear part of the model.\n :param dnn_feature_columns: An iterable containing all the features used by deep part of the model.\n :param use_fm: bool,...
class DIN(BaseModel): 'Instantiates the Deep Interest Network architecture.\n\n :param dnn_feature_columns: An iterable containing all the features used by deep part of the model.\n :param history_feature_list: list,to indicate sequence sparse field\n :param dnn_use_bn: bool. Whether use BatchNormalizat...
class FiBiNET(BaseModel): 'Instantiates the Feature Importance and Bilinear feature Interaction NETwork architecture.\n\n :param linear_feature_columns: An iterable containing all the features used by linear part of the model.\n :param dnn_feature_columns: An iterable containing all the features used by dee...
class MLR(BaseModel): 'Instantiates the Mixed Logistic Regression/Piece-wise Linear Model.\n\n :param region_feature_columns: An iterable containing all the features used by region part of the model.\n :param base_feature_columns: An iterable containing all the features used by base part of the model.\n ...
class NFM(BaseModel): 'Instantiates the NFM Network architecture.\n\n :param linear_feature_columns: An iterable containing all the features used by linear part of the model.\n :param dnn_feature_columns: An iterable containing all the features used by deep part of the model.\n :param dnn_hidden_units: l...
class PNN(BaseModel): 'Instantiates the Product-based Neural Network architecture.\n\n :param dnn_feature_columns: An iterable containing all the features used by deep part of the model.\n :param dnn_hidden_units: list,list of positive integer or empty list, the layer number and units in each layer of deep ...
class WDL(BaseModel): 'Instantiates the Wide&Deep Learning architecture.\n\n :param linear_feature_columns: An iterable containing all the features used by linear part of the model.\n :param dnn_feature_columns: An iterable containing all the features used by deep part of the model.\n :param dnn_hidden_u...
class xDeepFM(BaseModel): 'Instantiates the xDeepFM architecture.\n\n :param linear_feature_columns: An iterable containing all the features used by linear part of the model.\n :param dnn_feature_columns: An iterable containing all the features used by deep part of the model.\n :param dnn_hidden_units: l...
class EncoderBase(object): def __init__(self): self.trans_ls = list() def reset(self): self.trans_ls = list() def check_var(self, df): for (_, _, target, _) in self.trans_ls: if (target not in df.columns): raise Exception('The columns to be transforme...
class LabelEncoder(EncoderBase): def __init__(self): super(LabelEncoder, self).__init__() def fit(self, df, targets): self.reset() for target in targets: unique = df[target].unique() index = range(len(unique)) mapping = dict(zip(unique, index)) ...
class NANEncoder(EncoderBase): def __init__(self): warnings.warn("This is a simple application in order to perform the simpliest imputation. It is strongly suggest to use R's mice package instead. ") super().__init__() def fit(self, df, targets, method='simple_impute'): self.reset() ...
class ScaleEncoder(EncoderBase): def __init__(self): super().__init__() def fit(self, df, targets, configs): '\n :param df: the dataframe to transform\n :param targets: a list of variables to perform the scaling\n :param configs: the scaling methods\n ' fo...
class ClusteringEncoder(EncoderBase): '\n ' def __init__(self): super().__init__() def fit(self, df, targets, configs): '\n :param df: the dataframe to train the clustering algorithm.\n :param targets: a list of list of variables.\n :param config: configurations f...
class CategoryEncoder(EncoderBase): def __init__(self): super().__init__() def fit(self, df, y, targets, configurations): "\n\n :param df: the data frame to be fitted; can be different from the transformed ones.\n :param y: the y variable\n :param targets: the variables ...
class DiscreteEncoder(EncoderBase): def __init__(self): super(DiscreteEncoder, self).__init__() def fit(self, df, targets, configurations): "\n\n :param df: the dataframe to be fitted; can be different from the transformed one;\n :param targets: the variables to be transformed\...
class UnaryContinuousVarEncoder(EncoderBase): def __init__(self): super(UnaryContinuousVarEncoder, self).__init__() def fit(self, targets, config): self.reset() for target in targets: for (method, parameter) in config: if (method == 'power'): ...
class BinaryContinuousVarEncoder(EncoderBase): def __init__(self): super(BinaryContinuousVarEncoder, self).__init__() def fit(self, targets_pairs, config): for (target1, target2) in targets_pairs: for method in config: if (method == 'add'): sel...
class BoostTreeEncoder(EncoderBase): def __init__(self, nthread=None): super(BoostTreeEncoder, self).__init__() if nthread: self.nthread = cpu_count else: self.nthread = nthread def fit(self, df, y, targets_list, config): self.reset() for (meth...
class AnomalyScoreEncoder(EncoderBase): def __init__(self, nthread=None): super(AnomalyScoreEncoder, self).__init__() if nthread: self.nthread = cpu_count else: self.nthread = nthread def fit(self, df, y, targets_list, config): self.reset() for...
class GroupbyEncoder(EncoderBase): def __init__(self): super(GroupbyEncoder, self).__init__() def fit(self, df, targets, groupby_op_list): self.reset() for target in targets: for (groupby, operations, param) in groupby_op_list: for operation in operations:...
def get_interval(x, sorted_intervals): if pd.isnull(x): return (- 1) if (x == np.inf): return (- 2) if (x == (- np.inf)): return (- 3) interval = 0 found = False sorted_intervals.append(np.inf) if ((x < sorted_intervals[0]) or (x >= sorted_intervals[(len(sorted_inte...
def encode_label(x): x_copy = x.copy(deep=True) unique = sorted(list(set([str(item) for item in x_copy.astype(str).unique()]))) kv = {unique[i]: i for i in range(len(unique))} x_copy = x_copy.map((lambda x: kv[str(x)])) return x_copy
def get_uniform_interval(minimum, maximum, nbins): result = [minimum] step_size = (float((maximum - minimum)) / nbins) for index in range((nbins - 1)): result.append((minimum + (step_size * (index + 1)))) result.append(maximum) return result
def get_quantile_interval(data, nbins): quantiles = get_uniform_interval(0, 1, nbins) return list(data.quantile(quantiles))
def to_str(x): if pd.isnull(x): return '#NA#' else: return str(x)
def get_booster_leaf_condition(leaf_node, conditions, tree_info: pd.DataFrame): start_node_info = tree_info[(tree_info['Node'] == leaf_node)] if (start_node_info['Feature'].tolist()[0] == 'Leaf'): conditions = [] if (str(leaf_node) in tree_info['Yes'].drop_duplicates().tolist()): father_no...
class tree_to_dataframe_for_lightgbm(object): def __init__(self, model): self.json_model = model.dump_model() self.features = self.json_model['feature_names'] def get_root_nodes_count(self, tree, max_id): tree_node_id = tree.get('split_index') if tree_node_id: if ...
class StandardizeEncoder(EncoderBase): def __init__(self): super(StandardizeEncoder, self).__init__() def fit(self, df, targets): self.reset() for target in targets: mean = df[target].mean() std = df[target].std() new_name = (('continuous_' + remov...
class InteractionEncoder(): def __init__(self): self.level = list() self.targets = None def fit(self, targets, level='all'): if (level == 'all'): self.level = [2, 3, 4] else: self.level = level self.targets = targets def transform(self, df...
class DimReducEncoder(): def __init__(self): self.result = list() def fit(self, df, targets, config): for target in targets: for (method, parameter) in config: if (method == 'pca'): n_comp = parameter['n_components'] pos = (...
def is_missing(v): return (v == np.NaN)
@dataclass class TabDataOpt(): label: str = field(default='label', metadata={'help': "\n The name for the `y` variable.\n The default name is 'label'.\n "}) dis_vars_entity: list = field(default=None, metadata={'help': '\n A l...
def permutate_selector(train_df, eval_df, y, variables=None, metric='acc', **kwargs): '\n Return the importance of variables based on permutation loss\n\n :param train_df: training data set\n :param eval_df: eval data set\n :param y: name of the target variable\n :param variables: the variables to ...
def tree_selector(train_df, eval_df, y, opt, metric='error', type='lgb'): "\n This function select variable importance using built functions from xgboost or lightgbm\n :param train_df: training dataset,\n :param eval_df: evaluation dataset\n :param y: target variable\n :param opt: training operatio...
def shap_selector(train_df, eval_df, y, opt, type='lgb', metric='error'): "\n This returns the shap explainer so that one can use it for variable selection.\n The base tree model we use will select the best iterations\n :param train_df: training dataset\n :param eval_df: eval dataset\n :param y: th...
def vif_selector(data_df, y): '\n Calculate the VIF to select variables.\n :param data_df: the dataset\n :param y: the target variable\n ' ray.init() ex_var = [var for var in data_df.columns if (var != y)] data_df_id = ray.put(data_df) @ray.remote() def ls(data_df, target_var): ...
@click.group() def cli(): 'FitsMap --- Convert FITS files and catalogs into LeafletJS maps.' pass
@cli.command() @click.argument('directory', type=str) @click.option('--out_dir', default='.', help=HELP_OUT_DIR) @click.option('--min_zoom', default=0, help=HELP_MIN_ZOOM) @click.option('--title', default='FitsMap', help=HELP_TITLE) @click.option('--task_procs', default=0, help=HELP_TASK_PROCS) @click.option('--procs...
@cli.command() @click.argument('files', type=str) @click.option('--out_dir', default='.', help=HELP_OUT_DIR) @click.option('--min_zoom', default=0, help=HELP_MIN_ZOOM) @click.option('--title', default='FitsMap', help=HELP_TITLE) @click.option('--task_procs', default=0, help=HELP_TASK_PROCS) @click.option('--procs_per...
def __server(out_dir: str, port: int) -> None: def f(): server = http.server.HTTPServer(('', port), functools.partial(http.server.SimpleHTTPRequestHandler, directory=out_dir)) server.serve_forever() return f
def __opener(address: str) -> None: def f(): print('Opening up FitsMap in browser') webbrowser.open(address) return f
@cli.command() @click.option('--out_dir', default='.', help=HELP_OUT_DIR) @click.option('--port', default=8000, help=HELP_OUT_DIR) @click.option('--open_browser', default=True, help=HELP_OUT_DIR) def serve(out_dir: str, port: int, open_browser: bool): 'Spins up a web server to serve a fitsmap. webservers are requ...
class KDBush(): 'Python port of https://github.com/mourner/kdbush' def __init__(self, points, get_x: Callable=(lambda p: p[0]), get_y: Callable=(lambda p: p[1]), node_size: int=64, array_dtype=np.float64): self.points = points self.node_size = node_size n_points = len(points) ...
def _sort(ids: np.ndarray, coords: np.ndarray, node_size: int, left: int, right: int, axis: int) -> None: if ((right - left) <= node_size): return m = ((left + right) >> 1) _select(ids, coords, m, left, right, axis) _sort(ids, coords, node_size, left, (m - 1), (1 - axis)) _sort(ids, coords...
def _select(ids: np.ndarray, coords: np.ndarray, k: int, left: int, right: int, axis: int) -> None: while (right > left): if ((right - left) > 600): n = ((right - left) + 1) m = ((k - left) + 1) z = np.log(n) s = (0.5 * np.exp(((2 * z) / 3))) sd ...
def _swap_item(ids: np.ndarray, coords: np.ndarray, i: int, j: int) -> None: _swap(ids, i, j) _swap(coords, (2 * i), (2 * j)) _swap(coords, ((2 * i) + 1), ((2 * j) + 1))
def _swap(arr: np.ndarray, i: int, j: int) -> None: tmp = arr[i] arr[i] = arr[j] arr[j] = tmp
def _range(ids: np.ndarray, coords: np.ndarray, min_x: int, min_y: int, max_x: int, max_y: int, node_size: int) -> List[int]: stack = [0, (len(ids) - 1), 0] result = [] while len(stack): axis = stack.pop() right = stack.pop() left = stack.pop() if ((right - left) <= node_si...
def _within(ids: np.ndarray, coords: np.ndarray, qx: int, qy: int, r: int, node_size: int) -> List[int]: stack = [0, (len(ids) - 1), 0] result = [] r2 = (r * r) while len(stack): axis = stack.pop() right = stack.pop() left = stack.pop() if ((right - left) <= node_size):...
def __sq_dist(ax: float, ay: float, bx: float, by: float) -> float: return (((ax - bx) ** 2) + ((ay - by) ** 2))
class OutputManager(): 'Manages all FitsMap console output for tasks.' SENTINEL = (- 1) __instance = None @staticmethod def pbar_disabled(): return bool(os.getenv('DISBALE_TQDM', False)) def check_for_updates(func): def f(*args, **kwargs): func(*args, **kwargs) ...
class PaddedArray(): def __init__(self, array: np.ndarray, pad: Tuple[(int, int)], tile_size=(256, 256)): self.array = array self.pad = pad shape = [(array.shape[0] + pad[0]), (array.shape[1] + pad[1])] empty_tile_shape = list(tile_size) if (len(array.shape) == 3): ...
def default_map(i): return i
def default_udpate_f(): pass
def default_get_x(p): return p['x']
def default_get_y(p): return p['y']
class Supercluster(): def __init__(self, min_zoom: int=0, max_zoom: int=16, min_points: int=2, radius: float=40, extent: int=512, node_size: int=64, log: bool=False, generate_id: bool=False, reduce: Callable=None, map: Callable=default_map, alternate_CRS: Tuple[(int, int)]=(), update_f: Callable=default_udpate_f...
class MockTQDM(): unit = '' def update(self, n: int=1): pass def clear(self): pass def display(self, message): pass def set_description(self, desc): pass def reset(total): pass
class MockWCS(): 'Mock WCS object for testing' def __init__(self, include_cd: bool): if include_cd: self.cd = np.array([[1, 0], [0, 1]]) else: self.crpix = np.array([1, 1]) self.crval = np.array([1, 1]) def all_pix2world(self, *args, **kwargs): ...
def setup(with_data=False): 'Builds testing structure' if (not os.path.exists(TEST_PATH)): os.mkdir(TEST_PATH) if with_data: with_data_path = (lambda f: os.path.join(DATA_DIR, f)) with_test_path = (lambda f: os.path.join(TEST_PATH, f)) copy_file = (lambda f: shutil.copy(wit...
def tear_down(include_ray=False): 'Tears down testing structure' if os.path.exists(TEST_PATH): shutil.rmtree(TEST_PATH) if include_ray: ray.shutdown()
def disbale_tqdm(): os.environ[TQDM_ENV_VAR] = 'True'
def enable_tqdm(): os.environ[TQDM_ENV_VAR] = 'False'
def cat_to_json(fname): with open(fname, 'r') as f: lines = f.readlines() data = json.loads((('[' + ''.join([l.strip() for l in lines[1:(- 1)]])) + ']')) return (data, lines[0])
def __stable_idx_answer(shape, zoom, tile_size=256): dim0_tile_fraction = (shape[0] / tile_size) dim1_tile_fraction = (shape[1] / tile_size) if ((dim0_tile_fraction < 1) or (dim1_tile_fraction < 1)): raise StopIteration() num_tiles_dim0 = int(np.ceil(dim0_tile_fraction)) num_tiles_dim1 = i...
def covert_idx_to_hashable_tuple(idx): 'Converts idxs to hashable type for set, slice is not hashable' return (idx[0], idx[1], idx[2], str(idx[3]), str(idx[4]))
def get_slice_idx_generator_solution(zoom: int): 'Gets proper idxs using a method that tests correctly.\n\n The data returned by this can be big at high zoom levels.\n TODO: Find particular cases to test for.\n ' return list(__stable_idx_answer((4305, 9791), zoom))
def compare_file_directories(dir1, dir2) -> bool: is_file = (lambda x: x.is_file()) is_dir = (lambda x: x.is_dir()) get_name = (lambda x: x.name) get_path = (lambda x: x.path) def get_file_extension(fname): return os.path.splitext(fname)[1] def compare_file_contents(file1, file2) -> ...
def get_version(): here = os.path.dirname(os.path.realpath(__file__)) version_lcocation = os.path.join(here, '../__version__.py') with open(version_lcocation, 'r') as f: return f.readline().strip().replace('"', '')
@pytest.mark.unit @pytest.mark.cartographer def test_layer_name_to_dict_image(): 'test cartographer.layer_name_to_dict' out_dir = '.' min_zoom = 0 max_native_zoom = 2 name = 'test' color = '' actual_dict = c.layer_name_to_dict(out_dir, (max_native_zoom + 5), min_zoom, max_native_zoom, name...
@pytest.mark.unit @pytest.mark.cartographer def test_layer_name_to_dict_catalog(): 'test cartographer.layer_name_to_dict' helpers.setup() out_dir = helpers.DATA_DIR min_zoom = 0 max_native_zoom = 2 name = 'test' color = '#4C72B0' columns = 'a,b,c' with open(os.path.join(out_dir, f'...
@pytest.mark.unit @pytest.mark.cartographer def test_img_layer_dict_to_str(): 'test cartographer.layer_dict_to_str' min_zoom = 0 max_zoom = 2 name = 'test' layer_dict = dict(directory=(name + '/{z}/{y}/{x}.png'), name=name, min_zoom=min_zoom, max_zoom=(max_zoom + 5), max_native_zoom=max_zoom) ...
@pytest.mark.unit @pytest.mark.cartographer def test_cat_layer_dict_to_str(): 'test cartographer.layer_dict_to_str' min_zoom = 0 max_zoom = 2 name = 'test' columns = 'a,b,c' layer_dict = dict(directory=(name + '/{z}/{y}/{x}.png'), name=name, min_zoom=min_zoom, max_zoom=(max_zoom + 5), max_nati...
@pytest.mark.unit @pytest.mark.cartographer def test_leaflet_layer_control_declaration(): 'test cartographer.add_layer_control' min_zoom = 0 max_zoom = 2 name = 'test' img_layer_dict = dict(directory=(name + '/{z}/{y}/{x}.png'), name=name, min_zoom=min_zoom, max_zoom=(max_zoom + 5), max_native_zoo...
@pytest.mark.unit @pytest.mark.cartographer def test_get_colors(): 'test cartographer.colors_js' expected = ['#4C72B0', '#DD8452', '#55A868', '#C44E52', '#8172B3', '#937860', '#DA8BC3', '#8C8C8C', '#CCB974', '#64B5CD'] color_iter = c.get_colors() assert (expected == [next(color_iter) for _ in range(le...
@pytest.mark.unit @pytest.mark.cartographer def test_leaflet_crs_js(): 'test cartographer.leaflet_crs_js' min_zoom = 0 max_zoom = 2 name = 'test' layer_dict = dict(directory=(name + '/{z}/{y}/{x}.png'), name=name, min_zoom=min_zoom, max_zoom=(max_zoom + 5), max_native_zoom=max_zoom) actual = c...
@pytest.mark.unit @pytest.mark.cartographer def test_extract_cd_matrix_as_string_with_cd(): 'test cartographer.extract_cd_matrix_as_string' wcs = helpers.MockWCS(include_cd=True) actual = c.extract_cd_matrix_as_string(wcs) expected = '[[1, 0], [0, 1]]' assert (actual == expected)
@pytest.mark.unit @pytest.mark.cartographer def test_extract_cd_matrix_as_string_without_cd(): 'test cartographer.extract_cd_matrix_as_string' wcs = helpers.MockWCS(include_cd=False) actual = c.extract_cd_matrix_as_string(wcs) expected = '[[0.0, 0.0], [0.0, 0.0]]' assert (actual == expected)
@pytest.mark.unit @pytest.mark.cartographer def test_leaflet_map_js(): 'test cartographer.leaflet_map_js' min_zoom = 0 max_zoom = 2 name = 'test' layer_dict = dict(directory=(name + '/{z}/{y}/{x}.png'), name=name, min_zoom=min_zoom, max_zoom=(max_zoom + 5), max_native_zoom=max_zoom) acutal_map...
@pytest.mark.unit @pytest.mark.cartographer def test_build_conditional_css(): 'test cartographer.build_conditional_css' helpers.setup() actual_css = c.build_conditional_css(helpers.TEST_PATH) expected_css = '\n'.join([' <link rel=\'preload\' href=\'https://unpkg.com/leaflet-search@2.9.8/dist/leafle...
@pytest.mark.unit @pytest.mark.cartographer def test_build_conditional_js(): 'test cartographer.build_conditional_js' helpers.setup() acutal_js = c.build_conditional_js(helpers.TEST_PATH, True) expected_js = '\n'.join([" <script defer src='https://cdnjs.cloudflare.com/ajax/libs/leaflet-search/3.0.2...
@pytest.mark.unit @pytest.mark.cartographer def test_build_index_js(): 'Tests cartographer.build_index_js' img_layer_dict = [dict(name='img', directory='img/{z}/{y}/{x}.png', min_zoom=0, max_zoom=8, max_native_zoom=3)] cat_layer_dict = [dict(name='cat', directory='cat/{z}/{y}/{x}.pbf', min_zoom=0, max_zoo...
@pytest.mark.unit @pytest.mark.cartographer def test_move_support_images(): 'test cartographer.move_support_images' helpers.setup() actual_moved_images = c.move_support_images(helpers.TEST_PATH) expected_moved_images = ['favicon.ico', 'loading-logo.svg'] helpers.tear_down() assert (actual_move...
@pytest.mark.unit @pytest.mark.cartographer def test_build_html(): 'test cartographer.build_html' title = 'test_title' extra_js = 'test_extra_js' extra_css = 'test_extra_css' actual_html = c.build_html(title, extra_js, extra_css) expected_html = '\n'.join(['<!DOCTYPE html>', '<html lang="en">'...
@pytest.mark.integration @pytest.mark.cartographer def test_chart_no_wcs(): 'test cartographer.chart' helpers.setup(with_data=True) out_dir = helpers.TEST_PATH title = 'test' map_layer_names = 'test_layer' marker_file_names = 'test_marker' wcs = None columns = 'a,b,c' with open(os....
@pytest.mark.integration @pytest.mark.cartographer def test_chart_with_wcs(): 'test cartographer.chart' helpers.setup(with_data=True) out_dir = helpers.TEST_PATH title = 'test' map_layer_names = 'test_layer' marker_file_names = 'test_marker' wcs = WCS(os.path.join(out_dir, 'test_image.fits...
@pytest.mark.unit @pytest.mark.convert def test_build_path(): 'Test the convert.build_path function' (z, y, x) = (1, 2, 3) out_dir = helpers.TEST_PATH img_name = convert.build_path(z, y, x, out_dir) expected_img_name = os.path.join(out_dir, str(z), str(y), f'{x}.png') expected_file_name_matche...
@pytest.mark.unit @pytest.mark.convert def test_slice_idx_generator_z0(): "Test convert.slice_idx_generator at zoom level 0.\n\n The given shape (4305, 9791) breaks iterative schemes that don't properly\n seperate tiles. Was a bug.\n " shape = (4305, 9791) zoom = 0 tile_size = 256 given =...
@pytest.mark.unit @pytest.mark.convert def test_slice_idx_generator_z1(): "Test convert.slice_idx_generator at zoom level 1.\n\n The given shape (4305, 9791) breaks iterative schemes that don't properly\n seperate tiles. Was a bug.\n " shape = (4305, 9791) zoom = 1 tile_size = 256 given =...
@pytest.mark.unit @pytest.mark.convert def test_slice_idx_generator_z2(): "Test convert.slice_idx_generator at zoom level 2.\n\n The given shape (4305, 9791) breaks iterative schemes that don't properly\n seperate tiles. Was a bug.\n " shape = (4305, 9791) zoom = 2 tile_size = 256 given =...
@pytest.mark.unit @pytest.mark.convert def test_slice_idx_generator_z3(): "Test convert.slice_idx_generator at zoom level 3.\n\n The given shape (4305, 9791) breaks iterative schemes that don't properly\n seperate tiles. Was a bug.\n " shape = (4305, 9791) zoom = 3 tile_size = 256 given =...
@pytest.mark.unit @pytest.mark.convert def test_slice_idx_generator_z4(): "Test convert.slice_idx_generator at zoom level 4.\n\n The given shape (4305, 9791) breaks iterative schemes that don't properly\n seperate tiles. Was a bug.\n " shape = (4305, 9791) zoom = 4 tile_size = 256 given =...
@pytest.mark.unit @pytest.mark.convert def test_slice_idx_generator_z5(): "Test convert.slice_idx_generator at zoom level 5.\n\n The given shape (4305, 9791) breaks iterative schemes that don't properly\n seperate tiles. Was a bug.\n " shape = (4305, 9791) zoom = 5 tile_size = 256 given =...
@pytest.mark.unit @pytest.mark.convert def test_slice_idx_generator_raises(): "Test convert.slice_idx_generator raises StopIteration.\n\n The given shape (4305, 9791) breaks iterative schemes that don't properly\n seperate tiles. Was a bug.\n " shape = (250, 250) zoom = 5 tile_size = 256 ...
@pytest.mark.unit @pytest.mark.convert def test_balance_array_2d(): 'Test convert.balance_array' in_shape = (10, 20) expected_shape = (32, 32) expected_num_nans = (np.prod(expected_shape) - np.prod(in_shape)) test_array = np.zeros(in_shape) out_array = convert.balance_array(test_array) ass...
@pytest.mark.unit @pytest.mark.convert def test_balance_array_3d(): 'Test convert.balance_array' in_shape = (10, 20, 3) expected_shape = (32, 32, 3) expected_num_nans = (np.prod(expected_shape) - np.prod(in_shape)) test_array = np.zeros(in_shape) out_array = convert.balance_array(test_array) ...
@pytest.mark.unit @pytest.mark.convert def test_get_array_fits(): 'Test convert.get_array' helpers.setup() tmp = np.zeros((3, 3), dtype=np.float32) out_path = os.path.join(helpers.TEST_PATH, 'test.fits') fits.PrimaryHDU(data=tmp).writeto(out_path) pads = [[0, 1], [0, 1]] expected_array = n...
@pytest.mark.unit @pytest.mark.convert def test_get_array_fits_fails(): 'Test convert.get_array' helpers.setup() tmp = np.zeros(3, dtype=np.float32) out_path = os.path.join(helpers.TEST_PATH, 'test.fits') fits.PrimaryHDU(data=tmp).writeto(out_path) with pytest.raises(ValueError) as excinfo: ...
@pytest.mark.unit @pytest.mark.convert def test_get_array_png(): 'Test convert.get_array' helpers.setup() expected_array = camera() out_path = os.path.join(helpers.TEST_PATH, 'test.png') Image.fromarray(expected_array).save(out_path) actual_array = convert.get_array(out_path) helpers.tear_...
@pytest.mark.unit @pytest.mark.convert def test_filter_on_extension_without_predicate(): 'Test convert.filter_on_extension without a predicate argument' test_files = ['file_one.fits', 'file_two.fits', 'file_three.exclude'] extensions = ['fits'] expected_list = test_files[:(- 1)] actual_list = conv...