<jupyter_start><jupyter_text>Download dataAttributes of .nc files: http://earthpy.org/04_work_with_different_data_formats.htmlOpen-netCDF-files<jupyter_code># https://rabernat.github.io/research_computing_2018/xarray-tips-and-tricks.html
url = 'http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface/air.sig995.2018.nc'

from netCDF4 import Dataset as NetCDFFile
nc = NetCDFFile(url)
nc
# Extract data from NetCDF file (will take a minute)
lats = nc.variables['lat'][:]
lons = nc.variables['lon'][:]
time = nc.variables['time'][:]
air  = nc.variables['air'][:]  # shape is time, lat, lon
# Convert time values to datetime objects
import datetime as dt

dt_time = [dt.date(1, 1, 1) + dt.timedelta(hours=t) for t in time]<jupyter_output><empty_output><jupyter_text>Choose map in backgroundSee http://matplotlib.org/basemap/users/mapsetup.html for other projections.<jupyter_code># Setup the map
m = Basemap(projection='moll', llcrnrlat=-90, urcrnrlat=90,\
            llcrnrlon=0, urcrnrlon=360, resolution='c', lon_0=0)
m.drawcoastlines()
m.drawmapboundary()<jupyter_output><empty_output><jupyter_text>Format data to fit map<jupyter_code># Take a random day in the year
time_idx = 237
cur_time = dt_time[time_idx]

print(cur_time)
# Make the plot continuous
air_cyclic, lons_cyclic = addcyclic(air[time_idx, :, :], lons)

# Shift the grid so lons go from -180 to 180 instead of 0 to 360.
air_cyclic, lons_cyclic = shiftgrid(180., air_cyclic, lons_cyclic, start=False)

# Create 2D lat/lon arrays for Basemap
lon2d, lat2d = np.meshgrid(lons_cyclic, lats)

# Transforms lat/lon into plotting coordinates for projection
x, y = m(lon2d, lat2d)<jupyter_output>/home/myself/anaconda3/lib/python3.7/site-packages/numpy/ma/core.py:3225: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  dout = self.data[indx]<jupyter_text>Draw contour on map<jupyter_code>m.drawcoastlines()
m.drawmapboundary()

m.contourf(x, y, air_cyclic, 11, cmap=plt.cm.Spectral_r)
plt.title("Air temperature on %s" % cur_time)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12527472527472527, 'fraction_numerical': 0.025054945054945054, 'mean_word_length': 5.876132930513595, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '457480', 'license': 'MIT', 'n_tokens_mistral': 905, 'n_tokens_neox': 840, 'n_words': 200, 'path': 'docs/!matplotlib/Basemap.ipynb', 'repo_name': 'a-mt/dev-roadmap', 'size': '2275'}