Skip to content

Instantly share code, notes, and snippets.

View NimishMishra's full-sized avatar

NimishMishra

View GitHub Profile
#Lists all subdatasets of any one file
file = gdal.Open('/Users/nimishmishra/Downloads/Kanpur MODIS Data/November/2018.11.18.hdf')
for path, desc in file.GetSubDatasets():
print(desc)
def load_data(FILEPATH):
ds = gdal.Open(FILEPATH)
return ds
# Opens the data HDF file and returns as a dataframe
def read_dataset(SUBDATASET_NAME, FILEPATH):
dataset = load_data(FILEPATH)
path = ''
for sub, description in dataset.GetSubDatasets():
if (description.endswith(SUBDATASET_NAME)):
# Loads the HDF file, gets the Latitude subdataset and returns the information of the nearest pixel to specified position
def find_latitude_position(CITY_LATITUDE, FILEPATH):
dataset_to_load = 'Latitude (32-bit floating-point)'
latitude_dataframe = read_dataset(dataset_to_load, FILEPATH)
min_diff = 100
row_number = -1
column_number = -1
rows = latitude_dataframe.shape[0]
columns = latitude_dataframe.shape[1]
for i in range(rows):
# 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):
def find_product_value(LATITUDE_ROW_NUMBER, LONGITUDE_COLUMN_NUMBER, SUBDATASET, FILEPATH):
dataset = read_dataset(SUBDATASET, FILEPATH)
if(LATITUDE_ROW_NUMBER < 0 or LONGITUDE_COLUMN_NUMBER < 0):
return -1
return dataset.iloc[LATITUDE_ROW_NUMBER][LONGITUDE_COLUMN_NUMBER]
# Creates a list of values of the product under observation across all datasets
def create_list(PRODUCT, CITY_LATITUDE, CITY_LONGITUDE, FILEPATH):
latitude_dataframe, lat_row, lat_column = find_latitude_position(CITY_LATITUDE, FILEPATH)
if lat_row == -1:
return -1
longitude_dataframe, lon_column = find_longitude_position(CITY_LONGITUDE, lat_row, FILEPATH)
city_row_number = lat_row
city_column_number = lon_column
if(PRODUCT == 'AOD'):
subdataset = 'Deep_Blue_Aerosol_Optical_Depth_550_Land mod04 (16-bit integer)'
import glob
scattering_angle = []
deep_blue_AOD_Land = []
cloud_fraction = []
file_names = []
latitude = []
longitude = []
combined_AOD = []
angstrom_exponent = []
directory = '/Users/nimishmishra/Downloads/Kanpur MODIS Data/November'
def plot(x_axis, y_axis_1, y_axis_2, label1, label2, directory, month):
figure = plt.figure()
ax = sns.lineplot(x=date, y=y_axis_1)
ax = sns.lineplot(x=x_axis, y=y_axis_2)
figure.legend(labels = [label1, label2])
plt.show()
path = (directory + month + '/') + month + label1 + label2 + '.png'
fig = ax.get_figure()
fig.savefig(path)
import glob
import seaborn as sns
import matplotlib.pyplot as plt
sns.set()
month_dict = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6, 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov':11, 'Dec':12}
mean_month_list = []
mean_AOD_list = []
csv_directory = '/Users/nimishmishra/Downloads/Kanpur MODIS Data/CSV Files/'
for filename in glob.glob(csv_directory + '*.csv'):
month = filename[63:66]
@NimishMishra
NimishMishra / server.py
Last active December 10, 2019 03:57
A very basic skeleton of a socket server
import socket
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.bind((socket.gethostname(), 8000))
connection.listen(5)
while True:
connectedsocket, address = connection.accept()