Jan-31-2022, 03:09 PM
Hi everybody
Why is this code running twice? Is this related with the variables that the code imports from convert_nc_to_csv1?
Thank you.
Why is this code running twice? Is this related with the variables that the code imports from convert_nc_to_csv1?
Thank you.
# Reading the netcdf file from netCDF4 import Dataset import numpy as np import pandas as pd from convert_nc_to_csv1 import lat_of_station, lon_of_station data = Dataset (r'G:\My Drive\Python_Projects\NC4 Files code\ERA5-Land hourly data from 1950 to present\ERA5_land_hourly_data_from_2000_to_2010.nc') data_range = pd.date_range(start = '2000-01-01', end = '2011-01-01', freq='H') lat = data.variables['latitude'][:] lon = data.variables['longitude'][:] sq_diff_lat = (lat - lat_of_station)**2 sq_diff_lon = (lon - lon_of_station)**2 #Identifying the index of the minimum value for lat and lon min_index_lat = sq_diff_lat.argmin() min_index_lon = sq_diff_lon.argmin() df1 = pd.DataFrame(0, columns = ['t2m'], index = data_range) df = df1.iloc[:-1 , :] dt = np.arange(0, data.variables['time'].size) temperature = data.variables['t2m'] for time_index in dt: df.iloc[time_index] = temperature[time_index, min_index_lat,min_index_lon]-273.15 print (time_index) #Saving the time series to csv df.to_csv('64_PONTE MESTRAS_3.csv')