添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Im trying to run a program to reproject satellite images. Im running the code on my command and the code is as follows:

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np # Import the Numpy package
from remap import remap # Import the Remap function
from cpt_convert import loadCPT # Import the CPT convert function
from matplotlib.colors import LinearSegmentedColormap 
from netCDF4 import Dataset
# Load the Data
# Path to the GOES-16 image file
#path = '/Volumes/Anthonys_backup/Masters_Thesis/Satellite_Data/new2/C13/OR_ABI-L2-CMIPF-M3C13_G16_s20180400500385_e20180400511163_c20180400511242.nc'
path = '/home/alighezzolo/Casos/ANTHONY/OR_ABI-L2-CMIPF-M3C13_G16_s20180010000387_e20180010011165_c20180010011246.nc'
nc = Dataset(path)
H = nc.variables['goes_imager_projection'].perspective_point_height
# Choose the visualization extent (min lon, min lat, max lon, max lat)
extent = [-90.0, -40.0, -20.0, 10.0]
# Choose the image resolution (the higher the number the faster the processing is)
resolution = 1.0
# Call the reprojection funcion
grid = remap(path, extent, resolution, 'HDF5')
# Read the data returned by the function
data = grid.ReadAsArray()
# Plot the Data 
# Create the basemap reference for the Rectangular Projection
bmap = Basemap(resolution='h', llcrnrlon=extent[0], llcrnrlat=extent[1], urcrnrlon=extent[2], urcrnrlat=extent[3], epsg=4326)
# Draw the countries and Argentinian states shapefiles
bmap.readshapefile('/home/alighezzolo/BTCH13/SHAPES/008_limites_provinciales_LL','008_limites_provinciales_LL',linewidth=.5,color='black')
#bmap.readshapefile('/Users/anthonycrespo/Desktop/Satelite/arg_adm1/ARG_adm1','ARG_adm1',linewidth=.5,color='black')
#bmap.readshapefile('/Users/anthonycrespo/Desktop/Satelite/Countries_Shape/ne_10m_admin_0_countries','ne_10m_admin_0_countries',linewidth=.7,color='black')
# Draw parallels and meridians
bmap.drawcoastlines(linewidth=1., linestyle='solid', color='black')
bmap.drawparallels(np.arange(-90.0, 90.0, 10.0), linewidth=0.25, color='white', labels=[True,False,False,True])
bmap.drawmeridians(np.arange(-180.0, 180.0, 10.0), linewidth=0.25, color='white', labels=[True,False,False,True])
# Converts a CPT file to be used in Python
#cpt = loadCPT('/Users/anthonycrespo/Desktop/Satelite/IR4AVHRR6.cpt')
cpt = loadCPT('/home/alighezzolo/BTCH13/CPT/IR4AVHRR6.cpt')
# Makes a linear interpolation
cpt_convert = LinearSegmentedColormap('cpt', cpt)
# Plot the GOES-16 channel with the converted CPT colors
bmap.imshow(data, origin='upper', cmap=cpt_convert, vmin=170, vmax=378)
# Date and time
import datetime
time_var = nc.time_coverage_start
iyear = time_var[0:4]
imonth = time_var[5:7]
import calendar
cmonth = calendar.month_abbr[int(imonth)]
iday = time_var[8:10]
itime = time_var[11:19]
itimehr = time_var[11:13]
itimemn = time_var[14:16]
ctime_string = iyear +' '+cmonth+' '+iday+'  '+itime+' GMT'
ctime_file_string = iyear + imonth + iday + itimehr + itimemn
filestring = "C13_" + iyear + imonth + iday + "_" + itimehr + itimemn + ".jpg"
filestring = "C13_" + iyear + imonth + iday + "_" + itimehr + itimemn + ".png"
time_string = 'GOES-16 ABI Band 13\n"Clean" LW IR Window\n%s '%ctime_string
# Add a title to the plot
plt.title('GOES-16 Band 13\n"Clean" LW IR Window\n%s '%ctime_string)
# Insert the legend at the bottom
bmap.colorbar(location='right', label='Brightness Temperature [K]')
# Show the plot
#plt.show()
DPI = 150
plt.savefig(filestring, dpi=DPI, bbox_inches='tight', pad_inches=0)

But is returning the following error:

(base) Anthonys-MacBook-Pro:New_code_for_plotting anthonycrespo$ python Reprojection.py
Traceback (most recent call last):
  File "Reprojection.py", line 4, in <module>
    import matplotlib.pyplot as plt # Import the Matplotlib package
ModuleNotFoundError: No module named 'matplotlib.pyplot'

I already doubled checked "conda list" and it has the latest matplotlib version, i tried "pip install matplotlib" and the system is telling me that I have the latest version.

The environment Im running the code is:

Mac OS Mojave 10.14.5
Python 3.7.3 (default, Mar 27 2019, 16:54:48) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin

Any suggestions?

Probably you have multiple python versions or you somehow are using a virtual environment (what is the "(base)" thing at the beginning of the prompt? ). Try checking the python version that you are using:

> which python
> which python3

and next lookup if you have any virtual environment enabled.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.