如何运行 opendapL4.py

如何解决如何运行 opendapL4.py

我正在尝试从 PODAAC 下载基于 4 级卫星的 SST 数据 > https://opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/GDS2/L4/

我正在使用 python 代码 opendapL4.py,它可以在这里找到https://github.com/nasa/podaac_tools_and_services/blob/master/subset_GHRSST/opendapL4.py

#! /usr/bin/env python
#
# a skeleton script to download a set of GHRSST L4 file using OPeNDAP.
#
#
#   2011.04.06  mike chin,version 0
#   2011.04.25  mike chin,version 1
#   2012.08.29  mike chin,version 2
#   2013.10.30  mike chin,version 2 (bug fix)
#   2016.01.29  mike chin,defaults to GDS2 version



##################################
# user parameters to be editted: #
##################################

# Caution: This is a Python script,and Python takes indentation seriously.
# DO NOT CHANGE INDENTATION OF ANY LINE BELOW!


# Here is the web-address (URL) for the GHRSST L4 file OPeNDAP server.
# You probably do not need to change this URL.  In fact,you can
# use this URL to search for the filename of the product you want to download.

#L4URL='http://podaac-opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/L4/'
#L4URL='http://opendap.jpl.nasa.gov/opendap/hyrax/allData/ghrsst/data/L4/'
#L4URL='http://seastore.jpl.nasa.gov/opendap/hyrax/allData_nc4/ghrsst/data/L4/'
#L4URL='http://opendap.jpl.nasa.gov/opendap/OceanTemperature/ghrsst/data/GDS2/L4/'
L4URL='https://opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/GDS2/L4/'


# Here you set the product names in 3 parts:
#   ncHead = main directory of the product.
#   ncBody = main file name of the product (file name minus "yyyymmdd").
#   ncTail = the part that indicates the compression method.
#
# You also specify the grid dimension of the product,which you need to
# know in advance,by setting the following 6 variables:
#   nlon = x-grid (longitudes) dimension in integer.
#   nlat = y-grid (latitudes) dimension in integer. 
#   dint = grid interval in degrees in float (assuming it's the same for x & y).
#   lon0 = the smallest longitude of the grid,in degrees in float.
#   lat0 = the smallest latitude of the grid,in degrees in float.
#   order = how "time","lon","lat" dimensions are ordered in the L4 file,#           in array of three integers where 0=time,1=lon,2=lat.
#
# The code below might look complex,but it's only setting these 
# 3 names (strings) and 6 variables listed above.

def strmatch(a,b):
  return (a in b) and (b in a)

def parameters(product):

  productlist=[ \
  'mur/v4gds2',\
  'mur/v4',\
  'mur/v3',\
  'mur/ncamerica',\
  ]


  if strmatch( productlist[0],product.lower() ):
    ncHead='GLOB/JPL/MUR/v4.1/'
    ncBody='090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.nc'
    ncTail=''
    nlon=36000; nlat=17999 
    dint=0.01; lon0=-180.; lat0=-90.+dint
    order=[0,2,1]

  elif strmatch( productlist[1],product.lower() ):
    ncHead='GLOB/JPL/MUR/'
    ncBody='-JPL-L4UHfnd-GLOB-v01-fv04-MUR.nc'
    ncTail='.bz2'
    nlon=32768; nlat=16384 
    dint=45./(2**12); lon0=-180.+dint/2; lat0=-90.+dint/2
    order=[0,1]

  elif strmatch( productlist[2],product.lower() ):
    ncHead='GLOB/JPL/MUR/'
    ncBody='-JPL-L4UHfnd-GLOB-v01-fv03-MUR.nc'
    ncTail='.bz2'
    nlon=32768; nlat=16384 
    dint=45./(2**12); lon0=-180.+dint/2; lat0=-90.+dint/2
    order=[0,1]

  elif strmatch( productlist[3],product.lower() ):
    ncHead='NCAMERICA/JPL/MUR/'
    ncBody='-JPL-L4UHfnd-NCAMERICA-v01-fv02-MUR.nc'
    ncTail='.gz'
    nlon=13501; nlat=8201; 
    dint=0.01; lon0=-165.; lat0=-20. 
    order=[0,1]

  else:
    msg='\nNo such "product".\nAvailable products are:\n'
    for i in range(len(productlist)):
      msg=msg+'   '+productlist[i]+'\n'
    import sys
    sys.exit(msg)

  return(ncHead,ncBody,ncTail,nlon,nlat,dint,lon0,lat0,order)


# Done!!  
#
# Now get out of the editor and issue the command
#   opendapL4.py -h
# or
#   python opendapL4.py --help
# to see how you could specify
# the dates of the files and lon-lat box from the command line.

#############################################
# You're done.  No need to edit lines below #
#############################################


import sys,os
from math import floor,ceil
from optparse import OptionParser


###############
# subroutines #
###############

def ncname(body,year,yday):
  (day,month)=calday(yday,year)
  return('%04d%02d%02d%s'%(year,month,day,body))  # for GDS1.x and GDS2.0

def pathname(head,body,tail,y,d):
  return( '%s%04d/%03d/%s%s' %(head,d,ncname(body,d),tail) )

def yearday(day,year):
  months=[0,31,28,30,31]
  if isLeap(year):
    months[2]=29
  for m in range(month):
    day=day+months[m]
  return(day)

def span(i1,i2,i3=1):
   return range(i1,i2+i3/abs(i3),i3)

def isLeap(year):
  flag = ( (year%4)==0) and ( not ( (year%100)==0 and (year%400)!=0 ))
  return(flag)

def calday(yday,31]
  if isLeap(year):
    months[2]=29
  for m in span(1,12):
    months[m]=months[m]+months[m-1]
  for m in span(1,12):
    if (yday-1)/months[m]==0:
      month=m
      day=yday-months[m-1]
      return (day,month)
  import sys
  sys.exit('ERROR calday: yearday value out of range')

def cal2mjd(year,day):
  import math
  a = (14 - month) // 12
  y = year + 4800 - a
  m = month + (12 * a) - 3
  p = day + (((153 * m) + 2) // 5) + (365 * y)
  q = (y // 4) - (y // 100) + (y // 400) - 32045
  return int( math.floor(p + q - 2400000.5) )

def mjd2cal(mjd):
  y=(mjd-409)//366+1860
  while cal2mjd(y+1,1,1)<=mjd:
      y=y+1
  m=1
  while cal2mjd(y,m+1,1)<=mjd:
      m=m+1
  d=1
  while cal2mjd(y,m,d+1)<=mjd:
      d=d+1
  return(y,d)

def today(daysago=0):
  import datetime
  thisday=datetime.date.fromordinal(datetime.date.today().toordinal()-daysago)
  return( thisday.year,thisday.month,thisday.day )


def parseoptions(L4URL):
  usage = "usage: %prog [options] "
  parser = OptionParser(usage)
  parser.add_option("-p","--product",help="product name [default: %default]",dest="product",default="MUR/v4GDS2")
  parser.add_option("-s","--start",help="start date: yyyy mm dd [default: yesterday %default]",type="int",nargs=3,dest="date0",default=today(1))
  parser.add_option("-f","--finish",help="finish date: yyyy mm dd [default: start date]",dest="date1",default=-1)
  parser.add_option("-d","--dayspan",help="sampling period in days [default: %default]",dest="period",default=1)
  parser.add_option("-r","--region","-b","--subset",help="limit the domain to a box given by lon_min,lon_max,lat_min,lat_max",type="float",nargs=4,dest="box",default=(-180.,180.,-90.,90.))
  parser.add_option("-g","--gridspan",help="sampling interval over grid [default: %default]",dest="gridpoints",default=1)
  parser.add_option("-e","--error",help="include uncertainty error field",action="store_true",dest="includeError",default=False)
  parser.add_option("-l","--landmask",help="include landmask field",dest="includeLandMask",default=False)
  parser.add_option("-i","--ice",help="include ice concentration field",dest="includeIce",default=False)
  parser.add_option("-n","--noSST",help="exclude SST field",action="store_false",dest="includeSST",default=True)
  parser.add_option("-w","--wget",help="use wget instead of curl",dest="useWget",default=False)
  parser.add_option("-u","--url",help="URL for GHRSST L4 OPeNDAP server [default: %default]",dest="URL",default=L4URL)
  parser.add_option("-t","--test",help="only prints,without issuing,the OPeNDAP commands.",dest="testing",default=False)
  (options,args) = parser.parse_args()
  if len(args) != 0:
        parser.error("incorrect number of arguments")
  return( options )



# get command line options:

options=parseoptions(L4URL)

L4URL = options.URL

date0 = options.date0
if options.date1==-1:
    date1 = date0
else:
    date1 = options.date1
year0=date0[0]; month0=date0[1]; day0=date0[2];
year1=date1[0]; month1=date1[1]; day1=date1[2];

dday = options.period

box = list( options.box )

ig = options.gridpoints

product = options.product
p=parameters(product)
ncHead=p[0];ncBody=p[1];ncTail=p[2]
nlon=p[3];nlat=p[4];dint=p[5];lon0=p[6];lat0=p[7];order=p[8]


# find index set based on the given "box":
def boundingindex(dmin,length,boundary0,boundary1):
  inx0=max(int(ceil((boundary0-dmin)/dint)),0)
  inx1=min(int(floor((boundary1-dmin)/dint)),length-1)
  return [inx0,inx1]

[i0,i1]=boundingindex(lon0,box[0],box[1])
[j0,j1]=boundingindex(lat0,box[2],box[3])
if i0>i1 or j0>j1:
  sys.exit('No grid point in your domain box.')

# modify the max grid indices,as necessary:
if ig>1:
  i1=max(span(i0,i1,ig))
  j1=max(span(j0,j1,ig))

# modify the finish day,as necessary:
if dday>1:
  maxmjd=max(span(cal2mjd(year0,month0,day0),cal2mjd(year1,month1,day1),dday))
  (year1,day1)=mjd2cal(maxmjd)


# download size information:
print(' ')
print('First file: '+ncname(ncBody,year0,yearday(day0,year0)))
print('Last file:  '+ncname(ncBody,year1,yearday(day1,year1)))
print('  files obtained at %d-day interval'%(dday))
print(' ')
print('Longitude range: %f to %f'%(box[0],box[1]))
print('Latitude range: %f to %f'%(box[2],box[3]))
print('  every %d pixel(s) is obtained'%(ig))
print(' ')
print('grid dimensions will be ( %d x %d )'%(len(span(i0,ig)),len(span(j0,ig))))
print(' ')

r=raw_input('OK to download?  [yes or no]: ')
if len(r)==0 or (r[0]!='y' and r[0]!='Y'):
  print('... no download')
  sys.exit(0)


# form the index set for the command line:
inx=[[0,0],[i0,ig,i1],[j0,j1]]
index=''
for i in order:
  index=index+'[%d:%d:%d]'%(inx[i][0],inx[i][1],inx[i][2])

# main loop:
for mjd in span(cal2mjd(year0,dday):

    (year,day)=mjd2cal(mjd)
    yday=yearday(day,year)

    cmd=L4URL+pathname(ncHead,yday)
    cmd=cmd+'.nc?'
    if options.includeSST:
      cmd=cmd+'analysed_sst'+index+','
    if options.includeError:
      cmd=cmd+'analysis_error'+index+','
    if options.includeLandMask:
      cmd=cmd+'mask'+index+','
    if options.includeIce:
      cmd=cmd+'sea_ice_fraction'+index+','
    cmd=cmd[0:(len(cmd)-1)]  # remove the extra "," at the end.

    if options.useWget:
      cmd='wget "'+cmd+'" -O '+ncname(ncBody,yday)
    else:
      cmd='curl -g "'+cmd+'" -o '+ncname(ncBody,yday)

    if options.testing:  # just test command:
      print(cmd)
    else:  # run opendap
      os.system( cmd )

我已经尝试使用 ubuntu 终端和 windows 上的命令通过 anaconda 终端

python opendapL4.py --start 2020 01 01 --finish 2020 12 31 --region 178 179 -19 -18

但是我一直收到错误并且没有下载,

错误是

Traceback (most recent call last):
File "opendapL4.py",line 282,in <module>
print('First file: '+ncname(ncBody,year0)))
File "opendapL4.py",line 130,in ncname
(day,year)
File "opendapL4.py",line 155,in calday
for m in span(1,12):
File "opendapL4.py",line 145,in span
return range(i1,i3)
TypeError: 'float' object cannot be interpreted as an integer

非常感谢您对我做错了什么的任何提示。

亲切的问候, J

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-