获取 geojson 中列出的几个元素的总和

Obtaining the sum of several elements listed in a geojson

如果这个问题之前在其他地方被问过或回答过,我深表歉意。我找不到它。

我对 python 还是比较陌生,我目前正在设置一个脚本,用于通过 sentinelsat 模块从 ESA sentinel hub 下载文件。

现在它可以工作了,但我希望它能够打印出所涉及的总文件大小。我已经打印了所有文件的名称及其各自的数据大小。我还列出了文件总数。现在我只需要将各个数据大小汇总为 1 个值..

这是我的代码片段:

print("Listing file name and size:")
print("")
for n in range(0, np.size(bu_images_json["features"])):
    print("Image name: ",json.dumps(bu_images_json["features"][n]["properties"]["title"]))
    print("File size: ",json.dumps(bu_images_json["features"][n]["properties"]["size"]))
print("Found", n+1, "files availible for download")
print("Total amount to download")

看起来像这样

Image name:  "S2A_OPER_PRD_MSIL1C_PDMC_20161009T061329_R010_V20160727T140022_20160727T140246"
File size:  "5.02 GB"
Image name:  "S2A_OPER_PRD_MSIL1C_PDMC_20161009T060351_R139_V20160726T142942_20160726T143122"
File size:  "5.99 GB"
Image name:  "S2A_OPER_PRD_MSIL1C_PDMC_20160720T213054_R053_V20160720T141008_20160720T141008"
File size:  "5.65 GB"
Found 131 files availible for download
Total amount to download

如果有人知道任何 github 页面或类似内容,并且有人玩过并扩展了 sentinelsat 模块 - 那么我也很想拥有一个 link。

感谢您的宝贵时间。

from re import sub
print("Listing file name and size:")
total = 0
print("")
for n in range(0, np.size(bu_images_json["features"])):
    print("Image name: ",json.dumps(bu_images_json["features"][n]["properties"]["title"]))
    print("File size: ",json.dumps(bu_images_json["features"][n]["properties"]["size"]))
    total += float(sub('[^0-9.]','',json.dumps(bu_images_json["features"][n]["properties"]["size"])))
print("Found", n+1, "files availible for download")
print("Total amount to download: ",total)