{"cells":[{"metadata":{},"cell_type":"markdown","source":"In this notebook, I want to show that tiff images are flipped in y-axis. \n\nWhat, I mean is that the index of row 0 correponds to the max latitude and row end \nto the min latitude"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport rasterio as rio\nimport folium\nimport os\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\n\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"file = '/kaggle/input/ds4g-environmental-insights-explorer/eie_data/s5p_no2/s5p_no2_20180708T172237_20180714T190743.tif'\n\nimage_rio = rio.open(file)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(image_rio.bounds)\n[row1,col1] = [0,0]\n[row2,col2] = [147,0]\nprint(image_rio.xy(row1,col1))\nprint(image_rio.xy(row2,col2))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Till here, everthing is ok. row=0 corresponds to lattitude min (17.90) and row = 147 corresponds to lattitude max (18.56)."},{"metadata":{"trusted":true},"cell_type":"code","source":"[lat, lon] = [18.23, -66.255]\ndef overlay_image_on_puerto_rico(file,band_layer):\n    \n    im_rio = rio.open(file)\n    \n    band = im_rio.read(band_layer)\n    \n    band[0:10,0:10] = 0\n    m = folium.Map([lat, lon], zoom_start=8)\n    folium.raster_layers.ImageOverlay(\n        image=band,\n        bounds = [[im_rio.bounds.bottom, im_rio.bounds.left],[im_rio.bounds.top, im_rio.bounds.right]],\n        colormap=lambda x: (2, 0, 0, abs(x)),\n    ).add_to(m)\n    [lon0,lat0] = im_rio.xy(0,0)\n    folium.Marker([lat0,lon0]).add_to(m)\n    return m\noverlay_image_on_puerto_rico(file,1)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"In this map, we mark the position of [lon0,lat0] = im_rio.xy(0,0), which corresponds to (col,row)=(0,0). Howerver, when I change the value of the band image (band[0:10,0:10] = 0), it appears in the opposition location.  "},{"metadata":{},"cell_type":"markdown","source":"Look at gfs data for this flip; specifically the u v wind components"},{"metadata":{"trusted":true},"cell_type":"code","source":"# check u component of wind (channel 4)\nfile = '/kaggle/input/ds4g-environmental-insights-explorer/eie_data/gfs/gfs_2019030800.tif'\nrio.open(file).read(4)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"file = '/kaggle/input/ds4g-environmental-insights-explorer/eie_data/gfs/gfs_2019030800.tif'\noverlay_image_on_puerto_rico(file,4)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"file = '/kaggle/input/ds4g-environmental-insights-explorer/eie_data/gfs/gfs_2019030800.tif'\nimage_rio = rio.open(file)\nprint(image_rio.bounds)\n[row1,col1] = [0,0]\n[row2,col2] = [147,0]\nprint(image_rio.xy(row1,col1))\nprint(image_rio.xy(row2,col2))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"The bounding box top attribute corresponds to the higher latitude in this case."},{"metadata":{"trusted":true},"cell_type":"code","source":"# check v component of wind\noverlay_image_on_puerto_rico(file,5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","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":4}