Skip to content

Instantly share code, notes, and snippets.

@NimishMishra
Created April 22, 2019 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NimishMishra/b31e257dcc83c7cf9bb8b5eee577a601 to your computer and use it in GitHub Desktop.
Save NimishMishra/b31e257dcc83c7cf9bb8b5eee577a601 to your computer and use it in GitHub Desktop.
# Loads the HDF file, gets the Longitude subdataset and returns the information of the nearest pixel to specified position
def find_longitude_position(CITY_LONGITUDE, LATITUDE_ROW_NUMBER, FILEPATH):
dataset_to_load = 'Longitude (32-bit floating-point)'
longitude_dataframe = read_dataset(dataset_to_load, FILEPATH)
min_diff = 100
row_number = -1
column_number = -1
rows = longitude_dataframe.shape[0]
columns = longitude_dataframe.shape[1]
for j in range(columns):
lon = longitude_dataframe.iloc[LATITUDE_ROW_NUMBER][j]
diff = np.abs(lon - CITY_LONGITUDE)
if(diff < min_diff):
min_diff = diff
row_number = LATITUDE_ROW_NUMBER
column_number = j
found_lon = lon
if(column_number == -1):
print("Longitude not found. You might have chosen wrong scene")
return longitude_dataframe, column_number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment