GraceFollowOn的个人博客分享 http://blog.sciencenet.cn/u/GraceFollowOn

博文

GLDAS水文数据的下载及其读取变量

已有 10754 次阅读 2019-10-11 11:01 |系统分类:科研笔记| GLDAS

       简单啰嗦两句,因为在本科的时候就瞻仰大佬们写的博客,所以也特想注册一个账户发表博文,现在机会来了,而且占用了这么好的名字——GraceFollowOn,在本领域的著名重力卫星。开博也有一段时间了,就发表我的第一篇博文吧,希望对初学者有所帮助,有问题也可以留言哦。

      1、GLDAS水文数据下载

           (1)网址:https://disc.gsfc.nasa.gov/datasets/GLDAS_NOAH10_M_2.1/summary?keywords=GLDAS    1°×1°的数据

           (2)下载方式:谷歌浏览器,添加插件DownThemAll!

      2、GLDAS的变量读取

           (1)MATLAB读取变量(老师给的代码,所以只给出提示)

               lat=ncread('C:\Users\Lenovo\Desktop\GLDAS_Read\GLDAS\GLDAS_NOAH10_M.A200001

     .021.nc4','lat');

              for循环:

              mon=num2str(imon,'%02i');  year=num2str(iyear,'%4i');

              file=strcat('C:\Users\Lenovo\Desktop\GLDAS_Read\GLDAS\GLDAS_NOAH10_M.A',year,mon,'

      .021.nc4');

          (2)将变量导出到txt文件

              fid= fopen('swe_string.txt', 'wt');

              fprintf(fid,'%g\n',swe);

              fclose(fid);

              image.png

          (3)用C#对导出的文件,增加经纬度

                

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace GLDAS_ADD_LAN_LON
{
    class Program
    {
        public class data
        {
            public double Longitude;
            public double Latitude;
            public string Value;
        }
        static void Main(string[] args)
        {
            List<string> SWEVlue = new List<string>();          
            StreamReader sr = new StreamReader(@"C:\Users\Lenovo\Desktop\GLDAS_Read\sm_string.txt");//读取文件
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                string value = line;
                SWEVlue.Add(value);
            }
            List<data> LAN_LON_SWE = new List<data>();
            int kk = 0;
            for (int n = 1; n <= 192; n++)
            {
                for (double i = -59.5; i <= 89.5; i++)
                {
                    for (double j = -179.5; j <= 179.5; j++)
                    {
                        data k = new data();
                        k.Longitude = j;
                        k.Latitude = i;
                        k.Value = SWEVlue[kk];
                        LAN_LON_SWE.Add(k);
                        kk++;
                    }
                }
            }
            FileStream fs = new FileStream(@"C:\Users\Lenovo\Desktop\lon_lat_sm.txt", FileMode.CreateNew, FileAccess.Write);
            using (StreamWriter sw = new StreamWriter(fs))
            {
                foreach (data H in LAN_LON_SWE)
                {
                    string we = H.Longitude.ToString() + "\t" + H.Latitude.ToString() + "\t" + H.Value;
                    sw.WriteLine(we);
                }
            }
            Console.WriteLine("程序已经完成了,按任意键退出程序!");
            Console.ReadKey();       
        }
    }
}

image.png

               (4)提取范围内需要的变量(以华北平原为例)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace HUABEI_gldas_pipei
{
    public class data
    {
        public string Longitude;
        public string Latitude;
        public string Value;
    }
    public class result
    {
        public string a;
        public string b;
        public string c;
    }

    class Program
    {
        static void Main(string[] args)
        {
            List<data> SWE = new List<data>();
            StreamReader sr = new StreamReader(@"C:\Users\Lenovo\Desktop\GLDAS_Read\lon_lat_sm.txt");//读取文件
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                string[] k = line.Split('\t');
                data kk = new data();
                kk.Longitude = k[0];
                kk.Latitude = k[1];
                kk.Value = k[2];
                SWE.Add(kk);
            }
            List<string[]> G1_42 = new List<string[]>();
            int mm = 1;
            for (double i = 113.5; i <= 119.5; i++)
            {

                for (double j = 40.5; j >= 35.5; j--)
                {

                    var query = from m in SWE
                                where m.Longitude == i.ToString() && m.Latitude == j.ToString()
                                select m.Value;
                    if (query.Count() > 0)
                    {

                        foreach (var l in query)
                        {
                            string[] k = new string[2];
                            k[0] = "G" + mm.ToString();
                            k[1] = l;
                            G1_42.Add(k);
                        }

                    }
                    mm++;
                }
            }
            int kkk = 0;
            List<result> outfile = new List<result>();
            for (int n = 1; n <= 42; n++)
            {           
            for(int i = 2002; i <= 2017; i++)
            {
                for(int j = 1; j <= 12; j++)
                {
                    result k = new result();
                    k.a = G1_42[kkk][0];
                    if (j <= 9)
                    {
                        k.b = i.ToString() + "0" + j.ToString();
                    }
                    else
                    {
                        k.b = i.ToString() + j.ToString();
                    }
                    k.c = G1_42[kkk][1];
                    outfile.Add(k);
                    kkk++;
                }
            }
            }
            FileStream fs = new FileStream(@"C:\Users\Lenovo\Desktop\G_year_sm.txt", FileMode.CreateNew, FileAccess.Write);
            using (StreamWriter sw = new StreamWriter(fs))
            {
                foreach (result H in outfile)
                {
                    string we = H.a + "\t" + H.b + "\t" + H.c;
                    sw.WriteLine(we);
                }
            }
            Console.WriteLine("程序已经完成了,按任意键退出程序!");
            Console.ReadKey();
        }
    }
}

image.png



https://blog.sciencenet.cn/blog-3420921-1201493.html


下一篇:全球地形起伏数据DEM
收藏 IP: 1.195.108.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-26 15:49

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部