Skip to main content

基于 https://github.com/ecjoliver/marineHeatWaves 的快速海洋热浪和极端事件检测器

项目描述

MHW探测器

基于https://github.com/ecjoliver/marineHeatWaves的海洋热浪探测器。

该软件包集成了 ecjoliver 的 MHW 检测实现的 numba 优化版本,具有多处理功能,可计算数据集每个坐标的检测。

此代码不仅用于检测 MHW。它还可用于检测任何变量的极端事件,如 chla、pH、O2 等...

安装

pip install mhw-detect

依赖项

  • 数组
  • 麻木
  • scipy
  • 黎明
  • 麻木的
  • 熊猫
  • netcdf4
  • 点击

用法

配置文件

使用 mhw-detect 命令行中不需要数公里的参数。您只需要编写一个配置文件,在其中放置每个参数,例如您下次检测的身份证。

data:
  data :
    path : '/folder/sst.nc'
    var : 'sst'
  clim :
    path : '/folder_clim/clim.nc'
    var : 'sst'
  percent :
    path : '/folder_percent/percentile.nc'
    var : 'sst'

params:
    depth : 0
    climatologyPeriod : [null, null]
    pctile : 90
    windowHalfWidth : 5
    smoothPercentile : True
    smoothPercentileWidth : 31
    minDuration : 5
    joinAcrossGaps : True
    maxGap : 2
    maxPadLength: False
    coldSpells : False
    Ly : False

cut:
  nb_lat : 157
  nb_lon : 72

output_detection : '/my/path/to/folder_result/'
  • data:指定要使用的路径和变量。如果您希望在检测期间计算它们,请不要指定 clim 和 percent。
  • params:指定检测的参数。请参阅下面的部分。
  • cut:指定地理空间数据集切割的经纬度数。
  • output_detection:指定保存结果的文件夹。

检测参数

来自https://github.com/ecjoliver/marineHeatWaves。

climatologyPeriod      Period over which climatology is calculated, specified
                        as list of start and end years. Default ([null, null]) is to calculate
                        over the full range of years in the supplied time series.
                        Alternate periods suppled as a list e.g. [1983,2012].
                        Unused if precalculated clim and percentile are set.

pctile                 Threshold percentile (%) for detection of extreme values
                        (DEFAULT = 90)

windowHalfWidth        Width of window (one sided) about day-of-year used for
                        the pooling of values and calculation of threshold percentile
                        (DEFAULT = 5 [days])

smoothPercentile       Boolean switch indicating whether to smooth the threshold
                        percentile timeseries with a moving average (DEFAULT = True)

smoothPercentileWidth  Width of moving average window for smoothing threshold
                        (DEFAULT = 31 [days])

minDuration            Minimum duration for acceptance detected MHWs
                        (DEFAULT = 5 [days])

joinAcrossGaps         Boolean switch indicating whether to join MHWs
                        which occur before/after a short gap (DEFAULT = True)

maxGap                 Maximum length of gap allowed for the joining of MHWs
                        (DEFAULT = 2 [days])

maxPadLength           Specifies the maximum length [days] over which to interpolate
                        (pad) missing data (specified as nans) in input temp time series.
                        i.e., any consecutive blocks of NaNs with length greater
                        than maxPadLength will be left as NaN. Set as an integer.
                        (DEFAULT = False, interpolates over all missing values).

coldSpells             Specifies if the code should detect cold events instead of
                        heat events. (DEFAULT = False)

数据集坐标

所有数据集必须以纬度/纬度、经度/经度和时间作为坐标。depth主数据集允许使用坐标。当前,通过其在坐标数组中的索引来指定深度。稍后将添加直接给出想要的深度。

百分位数数据集必须有一个quantile坐标作为变量的维度。如果您想使用不同的分位数 (90, 99) 进行检测,这很有用。

第 1 步:地理空间切割(可选但推荐)

为了有效地使用多处理,数据集必须在纬度/经度维度上切割成几个较小的数据集。使用您的配置文件调用mhw-cut以实现它。每个子数据集将被称为 Cut_X.nc,其中 X 是剪切的编号(这就是为什么您的数据集(数据、clim、百分位数)必须位于不同文件夹中的原因)。

切割的数量无关紧要,块大小很重要。要找到合适的 nb_lat 和 nb_lon,最好使用笔记本。

导入 xarray 作为 xr ds = xr.open_dataset('dataset.nc', chunks={'latitude': nb_lat, 'longitude': nb_lon}) ds

nb_lat 和 nb_lon 应该是纬度和经度维度的倍数,并谨慎选择大小超过 10Mb 的块(有关更多详细信息,请参阅 Dask 文档)。在笔记本上打印 ds 可以得到块的大小(切割)。

请注意,此步骤将使磁盘中使用的空间增加一倍。

第 2 步:检测

调用mhw-detect检测MHW。使用多重处理,每个剪辑都是并行处理的。对于剪辑,您将获得output_detection一个包含检测结果的文本文件。最后,当所有检测完成后,每个文本文件都被连接成一个 csv(用 ; 作为分隔符)。

如果您不想仅使用多处理来对小的地理空间子集进行检测,则可以-g lat_min lat_max lon_min lon_max为该命令提供选项。

命令

地理空间切割

mhw-cut -c config.yml

检测

使用多处理计算检测:

mhw-检测-c config.yml

计算地理空间子集的检测(无多重处理):

mhw-detect -c config.yml -g lat_min lat_max lon_min lon_max

去做

  • 添加绘图命令。
  • 添加 shapefile 使用。
  • 添加删除文本文件的选项。
  • 添加指定深度而不是其索引。

参考

霍布迪,AJ 等人。(2016), 定义海洋热浪的分层方法, 海洋学进展, 141, pp. 227-238, doi: 10.1016/j.pocean.2015.12.014 pdf

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

mhw-detect-0.1.7.ta​​r.gz (24.3 kB 查看哈希)

已上传 source

内置分布

mhw_detect-0.1.7-py3-none-any.whl (23.5 kB 查看哈希)

已上传 py3