• <i id='2uOvu'><tr id='2uOvu'><dt id='2uOvu'><q id='2uOvu'><span id='2uOvu'><b id='2uOvu'><form id='2uOvu'><ins id='2uOvu'></ins><ul id='2uOvu'></ul><sub id='2uOvu'></sub></form><legend id='2uOvu'></legend><bdo id='2uOvu'><pre id='2uOvu'><center id='2uOvu'></center></pre></bdo></b><th id='2uOvu'></th></span></q></dt></tr></i><div id='2uOvu'><tfoot id='2uOvu'></tfoot><dl id='2uOvu'><fieldset id='2uOvu'></fieldset></dl></div>
    <tfoot id='2uOvu'></tfoot>

      <small id='2uOvu'></small><noframes id='2uOvu'>

      <legend id='2uOvu'><style id='2uOvu'><dir id='2uOvu'><q id='2uOvu'></q></dir></style></legend>

          <bdo id='2uOvu'></bdo><ul id='2uOvu'></ul>

        计算 xarray 数据集的平方根误差

        Calculate Root Squared Error of xarray dataset(计算 xarray 数据集的平方根误差)
          <tbody id='3GAE8'></tbody>
        <legend id='3GAE8'><style id='3GAE8'><dir id='3GAE8'><q id='3GAE8'></q></dir></style></legend>

            <small id='3GAE8'></small><noframes id='3GAE8'>

              <tfoot id='3GAE8'></tfoot>
            • <i id='3GAE8'><tr id='3GAE8'><dt id='3GAE8'><q id='3GAE8'><span id='3GAE8'><b id='3GAE8'><form id='3GAE8'><ins id='3GAE8'></ins><ul id='3GAE8'></ul><sub id='3GAE8'></sub></form><legend id='3GAE8'></legend><bdo id='3GAE8'><pre id='3GAE8'><center id='3GAE8'></center></pre></bdo></b><th id='3GAE8'></th></span></q></dt></tr></i><div id='3GAE8'><tfoot id='3GAE8'></tfoot><dl id='3GAE8'><fieldset id='3GAE8'></fieldset></dl></div>
                  <bdo id='3GAE8'></bdo><ul id='3GAE8'></ul>
                  本文介绍了计算 xarray 数据集的平方根误差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一月份的 xarray 数据集 monthly_data 包含以下信息:

                  I have xarray dataset monthly_data of just January's with following info:

                  lat: float64 (192)
                  lon: float64 (288)
                  time: object (1200)(monthly data)
                  
                  Data Variables:
                  tas: (time, lat, lon)[[[45,78,...],...]...]
                  

                  我有真实值 grnd_trth,它有 1 月的真实数据

                  I have ground truth value grnd_trth which has true data of January

                  Coordinates:
                  lat: float64 (192)
                  lon: float64 (288)
                  
                  Data Variables:
                  tas(lat and lon)
                  

                  现在我想从 monthly_data 相对于 grnd_trth 计算每个月的平方根误差,我尝试使用循环,我想它工作正常,这是我的尝试:

                  Now I want to calculate root squared error for each month from monthly_data with respect to grnd_trth, I tried using loops and I guess it's working fine, here's my try:

                  rms = []
                  
                  for i in range(1200):
                    err = 0
                    for j in (grnd_trth.tas[0] - monthly_data.tas[i]).values:
                      for k in j:
                        err += k**2
                    rms.append(err**1/2)
                  

                  我只是想知道是否有更有效的方法或任何直接功能可以做到这一点?

                  I just want to know is there more efficient way or any direct function to do so?

                  monthly_data.tas的输出:

                  xarray.Datarray 'tas': (time:1200 lat: 192 lon: 288)
                  array([[[45,46,45,4....],....]...]
                  
                  Coordinates:
                  lat:
                  array([-90. , -89.75,...])
                  
                  lon:
                  array([0., 1.25.,.... ])
                  
                  time:
                  array([cftime.DatetimeNoLeap(0001-01-15 12:00:00),
                         cftime.DatetimeNoLeap(0002-01-15 12:00:00),
                         cftime.DatetimeNoLeap(0003-01-15 12:00:00), ...,
                         cftime.DatetimeNoLeap(1198-01-15 12:00:00),
                         cftime.DatetimeNoLeap(1199-01-15 12:00:00),
                         cftime.DatetimeNoLeap(1200-01-15 12:00:00)]
                  

                  grnd_trth.tas的输出:

                  xarray.Datarray 'tas': (lat: 192 lon: 288)
                  array([[45,46,45,4....],....]
                  
                  Coordinates:
                  lat:
                  array([-90. , -89.75,...])
                  
                  lon:
                  array([0., 1.25.,.... ])
                  
                  time:
                  array([cftime.DatetimeNoLeap(0001-01-15 12:00:00)]
                  

                  但是当我只使用 .values() 函数时,它只会返回我的 tas 值数组!

                  But when I just use .values( ) function it'll only return me tas value array!

                  推荐答案

                  就以更高效"的方式执行此操作而言,有两点需要指出.

                  In terms of doing this in a more 'efficient' way, there are two things to point out.

                  1) 您可以直接对 xarray 对象进行算术运算,例如.

                  1) You're allowed to do arithmetic operations directly on xarray objects eg.

                  for time_idx in range(1200):
                      # For each time idx, find the root squared error at 
                      # each pixel between grnd_truth and monthly_data
                  
                      err2 = (grnd_truth.tas - monthly_data.tas[time_idx,...])**2
                      err  = err2**(1/2)
                  

                  2) 有一个方法调用 .sum() 将数组中的所有元素相加,因此这意味着您不必执行 for k in j:代码>行,以便对像素求和.例如.

                  2) There's a method call .sum() which sums all the elements in an array, so this means you won't have to do the for k in j: line in order to sum over the pixels. Eg.

                  rms=[]
                  
                  for time_idx in range(2000):
                      # same two lines as before...
                  
                      # sum over every pixel and extract the value from the DataArray
                      err_tot = err.sum().values
                  
                      # Add to running total
                      rms.append(err_tot)
                  

                  现在,这里要指出的一件事是,通过简单地从 DataArray 中提取值,您将丢失有关该数组的所有元数据!所以这并不是真正的最佳做法,但现在我认为这可以回答您的问题?

                  Now, one thing to point out here is that, by simply extracting the values from the DataArray, you lose all of the metadata about the array! So this isn't really best practice, but for now I think this answers your question?

                  这篇关于计算 xarray 数据集的平方根误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)

                  <small id='LA9T1'></small><noframes id='LA9T1'>

                • <tfoot id='LA9T1'></tfoot>

                  <i id='LA9T1'><tr id='LA9T1'><dt id='LA9T1'><q id='LA9T1'><span id='LA9T1'><b id='LA9T1'><form id='LA9T1'><ins id='LA9T1'></ins><ul id='LA9T1'></ul><sub id='LA9T1'></sub></form><legend id='LA9T1'></legend><bdo id='LA9T1'><pre id='LA9T1'><center id='LA9T1'></center></pre></bdo></b><th id='LA9T1'></th></span></q></dt></tr></i><div id='LA9T1'><tfoot id='LA9T1'></tfoot><dl id='LA9T1'><fieldset id='LA9T1'></fieldset></dl></div>

                        <bdo id='LA9T1'></bdo><ul id='LA9T1'></ul>
                          <tbody id='LA9T1'></tbody>

                        • <legend id='LA9T1'><style id='LA9T1'><dir id='LA9T1'><q id='LA9T1'></q></dir></style></legend>