【ERDDAP】本地部署教程-第四节(dataset增加维度)

上一节 https://blog.csdn.net/mxy2572185/article/details/84580632 datasets.xml文件配置

通过文件名或全局元数据进行聚合

EDDGridFromFiles的所有子类还可以通过添加一个新的维度(通常是时间维度)来聚合一组文件,该维度基于从每个文件名或每个文件中的全局属性派生的值。例如,文件名可能包含文件中数据的时间值。然后ERDDAP将创建一个新的时间维度。

与thredd中类似的特性不同,ERDDAP总是使用数值(CF需要)创建axisVariable,从不使用字符串值(CF不允许)。ERDDAP也会聚合中的文件基于数字axisVariable值分配给每个文件,这样轴变量总是有排序的值根据CF。基于文件名进行字典排序的THREDDS方法会导致聚合,当文件名排序与派生的axisVariable值不同时,轴值不会排序(CF不允许这样做)。

要在ERDDAP中设置这些聚合之一,您将使用一个特殊、固定的 <sourceName>。定义一个新的axisVariable,它告诉ERDDAP在哪里以及如何从每个文件中找到新维度的值。

从文件名获取值固定的< sourceName >的格式为:

***fileName,dataType,extractRegex,captureGroupNumber 

从全局属性获取固定的<sourceName>的格式为:

***global:attributeName,dataType,extractRegex,captureGroupNumber 

你需要提供的部分描述如下:

attributeName - 每个文件中包含维度值的全局属性的名称。

dataType -它指定用于存储值的数据类型。允许的数据类型有double(64位浮点数)、float(32位浮点数)、long(64位有符号整数,不建议)、int(32位有符号整数)、short(16位有符号整数)、byte(8位无符号整数,强烈不建议)和char(本质上:16位无符号整数,强烈不建议),这与ERDDAP支持的标准数据类型列表略有不同。

还有一个附加的固定的数据类型,timeFormat=stringTimeFormat,它告诉ERDDAP,该值是字符串时间戳,格式由stringTimeFormat指定,使用java.time.DateTimeFormatter规范。在大多数情况下,您需要的stringtime格式是这些格式之一的变体:

yyyy-MM-dd'T'HH:mm:ss.SSSZ - ISO 8601:2004(E)日期及时间格式。缩写格式:yyyy-MM-dd 'HH:mm:ss或yyyy-MM-dd。

yyyyMMddHHmmss.SSS - ISO 8601日期及时间格式的精简版。缩写格式:yyyyMMddHHmmss或yyyyMMdd。

M/d/yyyy H:mm:ss.SSS -  U.S. slash日期格式。你可能需要这个的缩写,例如M/d/yyyy。

yyyyDDDHHmmssSSS – 日期换算成月日格式。(例如: 001 = 1月1日,365 = 12月31日在非闰年;这种日期格式为儒略日期)。缩写格式:yyyddd。

extractRegex - 这就是正则表达式,它包含一个捕获组(括号中),描述如何从文件名或全局属性值提取值。例如,给定一个文件名S19980011998031.L3b_MO_CHL.nc,捕获组 #1, "\d{7}",捕捉正则表达式S(\d{7})\d{7}\.L3b.*会捕捉“S”后的前7位数字:1998001。

captureGroupNumber -这是正则表达式中包含感兴趣信息的捕获组(在一对括号内)的编号。通常是1,第一个捕获组。有时您需要在regex中为其他目的使用捕获组,因此重要的捕获组号将是2(第二个捕获组)或3(第三个捕获组),等等。

下面是axisVariable的一个完整示例使用一个新的时间轴创建聚合数据集,该时间轴从每个文件的文件名获取时间值:

<axisVariable>

<sourceName>***fileName,timeFormat=yyyyDDD,S(\d{7})\.L3m.*,1</sourceName>

<destinationName>time</destinationName>

</axisVariable>

当您使用“timeFormat=”固定数据类型时,ERDDAP将向axisVariable添加2个属性,以便它们看起来来自源数据:

<att name="standard_name">time</att> 
<att name="units">seconds since 1970-01-01T00:00:00Z</att> 

因此,在本例中,ERDDAP将通过提取S之后和. L3m之前的7位数字,创建一个名为“time”、double格式的新轴,(以秒为单位从1970-01-01T00:00:00Z开始的时间),并按照yyyddd的时间格式进行格式化,解析为时间值。

您可以通过添加addAttribute来覆盖默认的基本时间(1970-01-01T00:00:00Z),该addAttribute指定具有不同基本时间的不同units属性。是一种很常见的情况:有组数据文件,每一个都有1天的综合卫星数据集,要让时间价值的中午天提到的文件名(每天)的集中时间和想要变量的long_name“集中时间”。如下:

<axisVariable>

    <sourceName>***fileName,timeFormat=yyyyDDD,S(\d{7})\.L3m.*,1</sourceName>

    <destinationName>time</destinationName>

    <addAttributes>

      <att name="long_name">Centered Time</att>

      <att name="units">seconds since 1970-01-01T12:00:00Z</att>

</addAttributes>

</axisVariable>

注:小时=基准时间12小时,相对于1970-01-01T00:00:00Z的原始基准时间增加了12小时。

 

下面是根据全局属性创建聚合数据集的完整示例。它使用一个新的“run”轴(具有int值)创建聚合数据集,该轴从每个文件中的“runID”全局属性(具有类似“r17_global”的值,其中17是运行号)获取运行值。

  <axisVariable>

    <sourceName>***global:runID,int,(r|s)(\d+)_global,2</sourceName>

    <destinationName>run</destinationName>

    <addAttributes>

      <att name="ioos_category">Other</att>

      <att name="units">count</att>

    </addAttributes>

  </axisVariable>

注意捕捉组号2用于捕捉出现在“r”或“s”之后、“_global”之前的数字。这个例子还展示了如何向axis变量添加额外的属性(例如ioos_category和units)。https://coastwatch.pfeg.noaa.gov/erddap/download/setupDatasetsXml.html#EDDGridFromFiles_AggregationViaFileNames

实例

接下来以EDDGridFromNcFiles为例,以文件名新的纬度参数进行说明。数据目录格式如下图所示,nc文件名为ewateryyyyMMdd.nc的格式进行命名的,具有时间规律。我们需要在原始的dataset的维度上新增时间维度。

原始利用GenerateDatasetsXml.bat生成的dataset说明内容,可以看到<axisVariable>标签只有连个,分别为lat和lon,这连个维度的数据来自于nc文件自己本来的维度数据。

<dataset type="EDDGridFromNcFiles" datasetID="__ac05_7c73_29e4" active="true">
    <reloadEveryNMinutes>10080</reloadEveryNMinutes>
    <updateEveryNMillis>10000</updateEveryNMillis>
    <fileDir>C:\C\database\EDDGridFromNcFiles\</fileDir>
    <fileNameRegex>.*\.nc</fileNameRegex>
    <recursive>true</recursive>
    <pathRegex>.*</pathRegex>
    <metadataFrom>last</metadataFrom>
    <matchAxisNDigits>20</matchAxisNDigits>
    <fileTableInMemory>false</fileTableInMemory>
    <accessibleViaFiles>true</accessibleViaFiles>
    <!-- sourceAttributes>
        <att name="Conventions">COARDS, CF-1.5</att>
        <att name="description">109.595 18.0878 0 0 0 0 0 0 42.0636 [x, y, M, D, Y, hh, mm, ss, rate (s/km)]</att>
        <att name="GMT_version">5.4.4 (r20314) [64-bit] [MP]</att>
        <att name="history">grdconvert ttt_auto_5m.b -Gttt.nc</att>
        <att name="title">Produced by grdconvert</att>
    </sourceAttributes -->
    <addAttributes>
        <att name="cdm_data_type">Grid</att>
        <att name="Conventions">COARDS, CF-1.6, ACDD-1.3</att>
        <att name="infoUrl">???</att>
        <att name="institution">???</att>
        <att name="keywords">data, grdconvert, hours, produced, time</att>
        <att name="license">[standard]</att>
        <att name="standard_name_vocabulary">CF Standard Name Table v29</att>
        <att name="summary">109.595 18.0878 0 0 0 0 0 0 42.0636 [x, y, M, D, Y, hh, mm, ss, rate (s/km)]</att>
    </addAttributes>	
    <axisVariable>
        <sourceName>lat</sourceName>
        <destinationName>latitude</destinationName>
        <!-- sourceAttributes>
            <att name="actual_range" type="doubleList">-90.0 90.0</att>
            <att name="long_name">latitude</att>
            <att name="units">degrees_north</att>
        </sourceAttributes -->
        <addAttributes>
            <att name="ioos_category">Location</att>
            <att name="long_name">Latitude</att>
            <att name="standard_name">latitude</att>
        </addAttributes>
    </axisVariable>
    <axisVariable>
        <sourceName>lon</sourceName>
        <destinationName>longitude</destinationName>
        <!-- sourceAttributes>
            <att name="actual_range" type="doubleList">-180.0 180.0</att>
            <att name="long_name">longitude</att>
            <att name="units">degrees_east</att>
        </sourceAttributes -->
        <addAttributes>
            <att name="ioos_category">Location</att>
            <att name="long_name">Longitude</att>
            <att name="standard_name">longitude</att>
        </addAttributes>
    </axisVariable>
    <dataVariable>
        <sourceName>z</sourceName>
        <destinationName>z</destinationName>
        <dataType>float</dataType>
        <!-- sourceAttributes>
            <att name="_ChunkSizes" type="intList">136 131</att>
            <att name="_FillValue" type="float">NaN</att>
            <att name="actual_range" type="doubleList">0.0 82.33256530761719</att>
            <att name="long_name">hours</att>
        </sourceAttributes -->
        <addAttributes>
            <att name="_ChunkSizes">null</att>
            <att name="colorBarMaximum" type="double">100.0</att>
            <att name="colorBarMinimum" type="double">0.0</att>
            <att name="ioos_category">Time</att>
        </addAttributes>
    </dataVariable>
</dataset>

 如下图所示,利用Panoply打开对应的.nc文件可以看到这个nc文件的数据结构,dataset的<axisVariable>标签对应nc文件结构中的dimensions,所以在dataset中只有两个维度。但这并不满足我们的业务需求,我们需要把时间维度新增进来。

 根据说明文档,在addAttributes标签下新增如下配置内容:

	<axisVariable>
        <sourceName>***fileName,timeFormat=yyyyMMdd,ewater(\d{8}).*,1</sourceName>
        <destinationName>time</destinationName>
        <addAttributes>
			<att name="standard_name">time</att> 
			<att name="units">seconds since 1970-01-01T00:00:00Z</att>
        </addAttributes>
    </axisVariable>

其中最为关键的设置为sourceName标签的设置,4个参数以逗号隔开。***fileName为固定内容,表示这个维度的参数从文件名来获取;timeFormat=yyyyMMdd表示字符串的数据格式,具体内容请查看开头说明;ewater(\d{8}).*为文件名的正则表达式,这个参数十分关键,也十分容易出现错误;1表示正则表达式的捕获组编号。

正则表达式可以利用正则表达式测试工具进行测试,如下图所示表示测试成功。但这里貌似有一个坑,ewater(\d{1,8}).*和ewater(\d{8}).*都能测试成功,但是第一种书写方式会导致dataset报错,报错信息为sourceName信息不合法,不能正常加载。所有这里输入正则表达式最好使用简写形式。

再利用DasDds.bat检查完dataset没有错误之后启动erddap服务,如下图所示,可以看到我们新增加的time维度信息。

这样,就可以根据time获取发布目录下所有的.nc数据,满足业务需求。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值