{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\nimport glob\nfrom tqdm import tqdm\n\nimport numpy as np\nimport pandas as pd\nimport xarray as xr\n\nfrom skimage.transform import resize\nfrom skimage import io\n\nimport matplotlib.pyplot as plt\n%matplotlib inline","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"ls ../input/galaxy-zoo-the-galaxy-challenge/44352/","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"DATA_DIR = '../input/galaxy-zoo-the-galaxy-challenge/44352/'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_image_path = glob.glob(os.path.join(DATA_DIR, 'images_test_rev1/*.jpg'))\ntest_image_name = [os.path.basename(path) for path in test_image_path]\ntest_image_name.sort()\nlen(test_image_name)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_image_name[:5]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"GalaxyID = [name[:-4] for name in test_image_name]\nGalaxyID[:5]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"pd.Series(GalaxyID).to_csv('galaxy_id_test.csv', header=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ORIG_SHAPE = (424,424)\nCROP_SIZE = (256,256)\nIMG_SHAPE = (64,64)\n\ndef get_image(path, x1,y1, shape, crop_size):\n    x = plt.imread(path)\n    x = x[x1:x1+crop_size[0], y1:y1+crop_size[1]]\n    x = resize(x, shape)\n    return x\n    \ndef get_test_images(shape=IMG_SHAPE, crop_size=CROP_SIZE):\n    x1 = (ORIG_SHAPE[0]-CROP_SIZE[0])//2\n    y1 = (ORIG_SHAPE[1]-CROP_SIZE[1])//2\n   \n    x_batch = []\n    for image_name in tqdm(test_image_name):\n        x = get_image(os.path.join(DATA_DIR, 'images_test_rev1', image_name), \n                      x1, y1, shape=shape, crop_size=crop_size)\n        x_batch.append(x.astype(np.float32))\n    x_batch = np.array(x_batch)\n    return x_batch\n\n%time X_test = get_test_images()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ds = xr.Dataset({\n    'image_test': (('sample', 'x', 'y', 'channel'), X_test)\n})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%time ds.to_netcdf('galaxy_test.nc')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ls -lh galaxy_test.nc","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":1}