Python 3.x 在Python中从外部文件调用函数

Python 3.x 在Python中从外部文件调用函数,python-3.x,matplotlib-basemap,calling-convention,Python 3.x,Matplotlib Basemap,Calling Convention,我试图从python中的另一个文件调用函数。我正在尝试以NetCDF格式处理来自Goes 16的卫星图像。Im从保存在名为“remap”的.py文件中的函数所需的文件中提取不同的值。我的一段主要代码如下所示: from remap import remap # Calculate the image extent required for the reprojection H = nc.variables['goes_imager_projection'].perspective_point_h

我试图从python中的另一个文件调用函数。我正在尝试以NetCDF格式处理来自Goes 16的卫星图像。Im从保存在名为“remap”的.py文件中的函数所需的文件中提取不同的值。我的一段主要代码如下所示:

from remap import remap
# Calculate the image extent required for the reprojection
H = nc.variables['goes_imager_projection'].perspective_point_height
x1 = nc.variables['x_image_bounds'][0] * H
x2 = nc.variables['x_image_bounds'][1] * H
y1 = nc.variables['y_image_bounds'][1] * H
y2 = nc.variables['y_image_bounds'][0] * H

# Projection Prameters 
lat_0 = nc.variables['goes_imager_projection'].latitude_of_projection_origin
lon_0 = nc.variables['goes_imager_projection'].longitude_of_projection_origin
a = nc.variables['goes_imager_projection'].semi_major_axis
b = nc.variables['goes_imager_projection'].semi_minor_axis
f = 1/nc.variables['goes_imager_projection'].inverse_flattening

# Call the reprojection funcion
grid = remap(path, extent, resolution, x1, y1, x2, y2)
在我称为“remap”的.py文件中,函数定义为:

# Define KM_PER_DEGREE
KM_PER_DEGREE = 111.32

# GOES-16 Spatial Reference System
sourcePrj = osr.SpatialReference()
sourcePrj.ImportFromProj4('+proj=geos +h=' + H + ' +a=' + a + ' +b=' + b + '  +f=' + f + 'lat_0=' + lat_0 + ' +lon_0=' + lon_0 + ' +sweep=x +no_defs')

# Lat/lon WSG84 Spatial Reference System
targetPrj = osr.SpatialReference()
targetPrj.ImportFromProj4('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')

def remap(path, extent, resolution, x1, y1, x2, y2):
... (and so on)
现在我有两个不同的问题:

(1) 我的第一个问题是,我从系统中得到一个错误,说: “remap()接受4个位置参数,但给出了7个”,我不明白为什么会发生这种情况,因为我已经在第二个名为“remap”的文件的函数中定义了这7个参数

(2) 我的第二个问题是,我不知道如何调用从NetCDF文件中提取的原始代码中的值,例如:要在第二个文件中使用的“lat_0、lon_0、a、b、f和H”,从一开始就需要使用函数“remap”

有什么建议吗?

关于您的第一个问题:

如何定义remap()中所需的路径、范围和分辨率

还有你的第二个问题:


您不需要在remap文件上调用这些参数,因为在主代码中,您正在调用remap,并使用这7个参数进行重投影。

我在这里没有看到matplotlib。移除标签