6/28/2012

A dip into NCL

NCL is an interpreted language designed for scientific data analysis and visualization. I use it mostly for visualization, but not seriously, because there is another developed platform for visualization. For NCL, I just use it to check the model results.

So I just got a dip of NCL for the last three days, in an attempt to plot a wind vertical profile with eta level. The wind vector goes along the terrain and the plot is blank where there is a hill, so that the impact of topography could be seen. Shame on myself, I still haven't gone through it. And in terms of time, I have to give up. Here I'd lie to summarize up what I've learned with NCL.

Coordinate variables are the key information to plot right. Variables from model results (in my case, WRF, CMAQ, and SMOKE) usually bear no coordinate, but columns and rows. It is fine if you just want to see the patterns. However, if you want a base map overlaid, the right coordinates have to be assigned. Coordinates are usually stored in another output variable, e.g. XLAT for latitude and XLONG for longitude in WRF. What you have to do is to assign lat/lon to the right dimension of, say, wind. Here is the code:

f         = addfile(filename, "r")
U        = f->U                             ; wind in east-west direction, time*lev*lat*lon
W        = f->W                            ; wind in bottom-up direction
lat       = f->XLAT(0,:,0)             ; time*lat*lon
lon      = f->XLON(0,0,:)
znu     = f->ZNU(0,:)                 ; time*lev

lat@units  = "degrees_north" 
lon@units = "degrees_east"
lat!0          = "lat"
lon!0         = "lon"
lat&lat      =  lat
lon&lon     =  lon

lev                      = znu*1000            ; [-105.1526..-82.84741]
lev@long_name  = "eta*1000"
lev@units           = "hPa"
lev!0                   = "lev"
lev&lev               =  lev

U!0      = "lev"
U!1      = "lat"
U!2      = "lon"
U&lev    =  lev
U&lat    =  lat
U&lon    =  lon

; And the same for w, left out here
But wait, there is a mistake here. NCL would prompt dimension inconsistent between U and W. Let's take a close look at it. By the funtion printVarSummary we find the dimension of both U and W is time*level*latitude*longitude. So, why inconsistent?

It comes out that there are two grids in WRF, the staggered grid and the mass grid. Value in mass grid is refers to value in the center of the grid while value in staggered grid means value in the boundary of the grid. So the dimension size of staggered grids is always greater than mass grids by 1. To solve the inconsistency, we average the value to mass grid points.

dimU = dimsizes(U)
nlonU = dimU(3)
u = 0.5 * (U(:,:,:,0:nlonU-2) + U(:,:,:,1:nlonU-1))
In this case, u is on the common grid. And the same is for w.

Finally gsn_csm_pres_hgt_vector (example is here and here) is used to plot the vector. However, the result (shown in figure below, at 24.5N along 113-114E) is quite different from the example, mainly for the three points:

 1. I am not sure whether the eta level is terrain-following. Though there are "ups and downs", no specific "hills" are to be found. Of course, it may be a problem of scales.
2. The temperature contour goes along eta level, which is weird.
3. Wind always flows to the east. There seems no "up" wind.
Some other resources:
To plot vectors:
gsn_vector(), gsn_csm_vector(). And the latter is more advanced.
gsn_csm_vector_map() overlays the vector plot on a base map.

To draw vector and scalar simultaneously.
gsn_csm_vector_scalar_map()

6/25/2012

完成论文

查看了下上一篇日志,还是在上月初写的。一晃就是50天,时间过得真快。

没写日志的一个原因是这期间确实没取得实质性的进展。除了为WRF和CMAQ写了两个顶层的控制脚本,就为在其他机器上安装CMAQ进行尝试。这不是技术问题,而是沟通与制度的问题。结果实验室新买的电脑因为权限问题到现在还没配置好,而中大的集群也因升级而暂时无法使用。结果白白浪费了一些时间。不过在此期间,发现CMAQ竟然升级了。最新的CMAQ 为5.0版本,加入了 CMAQ-WRF two-way couple 的新特性。这个升级非常让人兴奋。众所周知,气象场对污染物的分布产生很大的影响,是污染物扩散的驱动力;反过来,污染物的浓度也会对局部地区的温度、相对湿度等产生影响。因此,将这种双向的反馈反应到模式中,会使模拟结果更加准确。

在此期间,还写了MSc的毕业论文。本打算非常认真、严谨地对待这篇文章,但是时间紧迫,平时积累不够(想起Robert说的,每天读半小时文献,写半小时文摘,这些积累使他最后写论文时简单的copy-paste就完成了。真是汗颜)。因此论文不是很让我满意,模拟的结果也没有时间再做改善。

在做毕业论文内容的过程中,我也发现了一些问题:

1. 我拿到的污染源数据中,香港的排放源不完整,甚至是空白的。具体的数据还没有分析,但从CMAQ模拟的结果来看,香港地区除了塔门这个监测点,其他监测点的污染浓度值都与模拟值相差较大。这可以用排放源解释:塔门附近没有大型的排放源,它监测的是背景浓度,而且它离深圳较近。相对而言,深圳的排放源更准确,模拟的污染物浓度也更符合实际。所以塔门模拟得较好。而其他站点,因为排放源的缺失,模拟的浓度值大大低于实际值。

2. 跑模式分析污染物是一件很荒诞的事。在我看来,很多这方面的论文就是为了发表而发表。很多人跑模式,是为了分析过去的某个空气污染事件。当模拟值与实际值不符时,就提高或减少排放源的排放量,直到结果较为满意。试问,这样有什么意义?当然,有些人依此得到较为可信的排放源数据,并希望将它用于未来的模拟。可问题是,怎么证明适用于那个事件的污染源同样适用于其他事件、其他时期?

很高兴我今后不再研究这个领域。

5/06/2012

所谓认知

一直以为“认知”是心理学领域的东西,而且因为其抽象、玄乎,而本能的排斥它。后来才知道,“认知”早与“地理”扯上关系,在国外,地理是一门“社会科学”,研究地理是为了更好地研究人,将人与地理结合,或者说将人与环境结合,是地理学的崭新的研究方向,而地理、行为、认知则构成了这新方向的关键词。

可是,认知究竟是什么?在我看来,科学的意义就是用逻辑来解释某种现象,而这种现象必须是可重复发生、可用数据定量描述的。那么认知,符合这样的条件吗?

最近看了一篇心理学的论文,虽不足以解开我所有的疑惑,但让我有所启发;更让我印象深刻的是,之前一些模糊的、关于主客观的“思想”,原来可以用严谨的科学语言来表达,让我重新认识了心理学。

这是广州大学心理与脑科学研究中心的叶浩生老师写的《有关具身认知思潮的理论心理学思考》,对具身认知、离身认知等一些“人如何看待世界”的方式进行了综述,并认为具身认知才是正确的理解心理学的基础。

离身认知(disembodied cognition)认为思维和身体是分离的,身体只是意识的载体。所谓身心二元论,即心和身分属两个世界,主体和客体是一个“表征与被表征”的关系,主体若能镜像般地表征世界,则能真正认识世界。以计算机为比喻,身体就像硬件,负责数据的输入和信息的输出,而思维像程序一样负责信息的加工处理。从这个意义上讲,认知就是信息的表征和操控,“以抽象的符号表征着外在于我们的带我,然后通过操纵这些符号完成思维”。

反过来说,如今的计算机其实正在模拟人的认知过程,只不过如今的程序还非常稚嫩,如今的硬件也无法如人的身体那样感知到足够丰富的信息。另一方面,既然思维和身体是分离的,那就代表它们是可以替换的;那么如果有一天,物理系统足够复杂,就可以承担人类的智能。这与当时陈老师们在吃饭时谈笑的内容多么相似:随着计算机系统越来越复杂,计算机能自动完成的事件越来越多,可以预见,当计算机足够复杂时,它们能够自己debug,自己reflection,那么它们与人类的距离又有多大呢?这或许是所有计算机专家的梦想,也是许多像《黑客帝国》之类的科幻片的灵感来源。

我本人也非常信仰这种观点。可如今,一种新的看法,即具身认知(embodied cognition)被越来越多人认可,也似乎更“高级”,如同当时只研究环境,后来加入的“人”的因素一样,后者显得更合理。这种观点认为,认知在很大程度上与身体的物理属性相关,脑神经水平上的细节、身体的结构、运动系统等都对认知的形成有重要的影响。“人认识世界的方式是用我们的身体以合适的方式与世界中的其他物体互动,在互动的过程中获得对世界的认识”。它认为认知在本质上并非使用抽象符号的表征和加工,而是一种模拟(simulation),而所谓模拟,是“身体、世界和心智互动过程中产生的知觉、运动和内海状态的复演”。我对此并不十分理解,紧接着文章举了个例子,认为同情心的产生即是因为我们“通过大脑与身体的特殊通道模拟了他人的感受”,同样让我不太理解。

文章还举了一个更有说服力的例子。Yale大学的研究者在2010年做了一个实验,把41个大学生随机分成两组,A组学生双手捧着一杯热咖啡,B组学生捧着一杯冰咖啡。然后两组学生分别对同一个想象中的中性人物的人格特征进行评分。结果显示,A组学生比B组学生更有可能把这个人评估为热情、友好。从而认为,身体上感知到的温暖影响了学生认知上的判断。这个结果的确让人惊讶,但仔细一想却也不是那么奇怪。正如所有人都知道的那样,同样的风景给不同的人可能有不同的感受,有人喜有人悲,最简单的,如果人身体健康,那很可能就是乐观的心态,反之如果他正遭受疾病,他更趋向于悲观的心情,这似乎是理所当然的。

最后说说具身认知的方法论。具身认知告诉我们要把有机体放在它的环境中,视有机体、行为和环境紧密相连。这就回到文首的问题,有关“有机体”的变量是可重复出现的吗?我们知道环境是可以量化的,可人在那一刻是喜是悲却无法估计,也不可能重复发生,那如何用科学的方法来研究?另外,具身认知认为,神经科学和心理学是对同一问题的两种不同的解释,应该将这两种方法结合起来,可是具体如何结合呢?

这些都是具身认知让我不可接受的地方。尽管现代科学都越来越重视“人”的因素,都试图把“人”加入研究的范畴(是否和兴起的社交网络有关?),但我还是很难理解怎样用科学、用数字和规则来研究人的行为,甚至人的认知。






3/31/2012

A first glimpse of CMAQ

In the last three weeks, I did three things:
1. Modify the python script written before to interpolate preciser DEM into WRF.
2. Learn NCL
3. Successfully run CMAQ model.

DEM Interpolation

As mentioned in the last post, I wrote a small python script to interpolate our 30-meter-resolution DEM data into WRF, and tried to make the result more accurate. After the script has been written, however, the validation is another challenging work. First we just used geogrid.exe to take in the output data, and compared the result with that using coarser resolution data, say 30 s(econd) and 2 m(inus), to see the rough trend. The result was OK, but not persuasive enough to claim the correctness, because the terrain is too complex and you can not reach every detail with only eyes!

Then we did more accurate validation. First, we made up some experimental data, say, a block of DEM where four quarters were different constant values. The simplified data was easy to check if the output was right or not. Then real data were transferred in WPS, and we did an overlay on the coarser data, and made a "minus" computation in the topography height. In this way, the correctness of the script can be fully validated.

The following work should be to check how much the more precise topography influences WRF. From the geogrid result, you can hardly tell the difference between 1s and 30s terrain. However, from reports by other researchers, the topography does make a difference. The same method is applied: overlay and minus.

NCL

NCL is an interpreted language (like python) designed specifically for scientific data analysis and visualization. As far as I see, the tool has following advantages:
1. Interpreted language. It's easy to use, with compiling and linking problems. Any change can be immediately applied. It is much like python, and can also be run in both interactive mode and batch mode.
2. Powerful I/O ability. It can read almost all scientific data, from ASCII to binary, and netcdf, grib1 & grib2, and shapefile, etc. That's why we abandon GrADS, which can only deal with specific format, and may not be used for WPS, CMAQ and SMOKE.
3. Programming freedom. The language is rather flexible, and give users enough freedom to do what they want. And it is easy to be extended to wrap C and Fortran.
4. Numerous built-in functions. Though I haven't used these mathematical functions, but it is good to know there are many available tools at hands, something like Matlab.
5. Easy map overlay. As it is especially designed for atmospheric and oceanic models, map overlay is very important to study a specific issue.

More features:
There are several different kinds of data in NCL. A variable can have attribute data, coordinate data and missing values. Attribute data explains additional info apart from the "real data", like variable descriptions. Coordinate data facilitates the mapping procedure. Missing value support is another feature that highlights. Many models have a special value that is assigned to those with no sufficient info (e.g. initial condition) to simulate. NCL can recognize these data and do some special tricks.

Also, unlike C, NCL can deal with the whole array. On the other hand, loop though every element in an array is inefficient and not recommended.

CMAQ

It finally comes to CMAQ. Thanks to Prof. Zheng Junyu, now we have SMOKE output, and can run CMAQ. CMAQ consists of  many sub-programs. It is annoying to set up configurations one by one. So I write a top script to control these sub-scripts.

It's interesting to learn the shell programming. Linux shell is much more powerful than Windows Dos. It not only has basic commands, but also variables, statements, functions and procedures, and logical expressions. Some confusions I now have is Linux has various shells, like sh, bash, csh, and different shells has some different syntax. Besides, the concept "process" is important, and affects the pass of variables between functions and scripts.

It is really time-consuming to run CMAQ. For basic configurations, there are six output files, including pollution concentration and average concentration, and wet and dry deposition. One problem I recently solved is variables in CCTM output has no coordinates, but only rows and columns, making it difficult to overlay with the map. Actually there is such info, and it resides in MCIP output, in GRDCRO2D file. There are variables LON AND LAT. They are 4-dimension array, with time steps, layers, rows and columns. In fact for coordinates the array is duplicated. Only one dimension is enough, which is also required by NCL (in NCL, coordinate variables must be one dimensional. For longitude, pick columns and for latitude, pick rows).

3/16/2012

读《激荡三十年》

很早就听说这本书了,由赫赫有名的吴晓波老师写的,当初因为他与我们强化班的导师同名而让我印象深刻。自然,和其他经济学类书一样,这本书受到了强化班同学的追捧。很多人表示“赞”,或想读,或者读过了的出来发表一堆宏论。我自然不喜这些,因此也就耽搁了。

不过,对经济学类的书的好奇让我又翻看了这本书。似乎第一次看这么“务实”的书。书的内容让我很意外,写的很浅显,也很真实,让不谙世事的我第一次对这些“身边的最实实在在的事”有了一个认识。尤其是读到台州的李书福甚至玉环的那些事时,我深切地体会到书中讲的事情是多么的现实。

所以说经济学是很有意思的一门学科,它不像我平时做的学科如计算机等那么抽象、那么脱离现实,它是研究这个社会如何动作的学科,与古时读书人的清风傲骨隔隔不入。

或许以后也该多读点这类务实的书。有时想想,何必执着于那些所谓的技术呢?

3/12/2012

Topography in WPS

Two weeks ago, I tried to run CMAQ. However, it was really beyond my expectation that the pollution emission source data were so difficult to deal with, and finally we had to give up.

SMOKE is a set of programs responsible for the emission data. It takes in pollution inventory and turns it into CMAQ permitted format. In addition, it also divides the inventory spatially into grids and temporally into hours and days as most inventory data we get are annual. The problem is, SMOKE is developed by Americans and for USA use. The standards and administrative divisions are totally different. To take advantage of SMOKE, a specific methodology to adapt to the local is needed. Spanish scholars (R. Borge, et al)  have done that. In China, Prof. Zheng Junyu from South China University of Technology spent two years finishing that.

We are lucky that on 2nd March, Prof. Zheng came here and gave us a speech, exactly about pollution inventory preparation. He promised to give us his fruit so that we can go further. This Wednesday we are going there to learn about the skills.

Last week, I tried to replace topography data for WPS with my own data. WPS is the pre-processing software of WRF, preparing geographical and meteorological data for real-case weather simulation. It consists of three sub-programs, among which geogrid is responsible for interpolating static geographical data into grids. WPS is equipped with global geographical data issued by USGS, with 10m, 5m, 2m, 30s resolutions. For better precision, we have to add customized data to geogrid. We've got 1s (30 meters) PRD DEM data, and we can replace the topography data with it. Later, we are going to collect landuse data and do the same replacement.

The work is not so difficult as it seems. Both DEM data and geogrid formatted data are in grids. All I have to do is to read DEM into memory and then output it to static data. GDAL facilitates us greatly with dealing with DEM and WPS provides the output routine. We have to pay attention to obeying the WPS program interface. Also, data sequence in these two data formats are different. GDAL tends to read data from the first row (from north to south), but geogrid routine writes data from the south to the north. 

Ater the static data are ready, some configurations have to be modified to instruct geogrid to use the data we specified. After geo_em.d* have been output, we can use NCL to view the result. A sample ncl script can be downloaded here

In this way, terrain data with better resolution can be applied to WRF, which should affect the simulation result, like wind direction. Of course, the simulation grid is important in determining the significance of this work. Simulation with large domains and low resolution care less about course geography.

Fig1. Terrain with USGS 10m data

Fig2. Terrain with 1s data

3/05/2012

人生的转折点?

此刻,我正坐在303,听着小萝莉的 phd qualify,看着一页一页很华丽的图文,百感交集:这就是我以后要做的?

昨天看了一篇日志,一个满怀壮志的青年不甘于过着每天上班哄妻子带小孩的平淡日子,决意出国,只有外面的大千世界才能容下他博大的雄心。时隔四年,当他每天忙于看paper、做project、写本子,他最大的愿望就是早点毕业,过上高级知识分子应该有的高薪生活,然后有一个幸福的家庭。他不禁感叹到,到最后,我竟然回到了原点。

这或许是困扰所有人的一个问题:我们为什么活着?几天前,我收到了PSU的offer,我当然很兴奋,但我知道我并没有做好准备。我的兴奋只是因为我赢得了【申请】这一仗,我的【被认可】让我有很大的成就感。但是,这其实只是最初的一小步,后面还有5年6年甚至更长的时间。每天,我要做的就是看paper,写paper,申项目,做presentation,很明显我并不愿意过这样的生活,这只是为我今后有更好的生活付出的代价。不知将来我是否会为我今天这样“牺牲”的决定后悔?

美国,多么令人向往的国家。从小,我妈就希望我出人头地,而一个标竿就是出国,留洋。而我也从小迫切地希望能出去走走,去看我妈妈、我外婆、我曾外婆都从没看过的世界。可是,就在两年前,我真的到了美国,三个星期的时间里给我的只有无助、寂寞,也正是这三周灰色的印象,让我在本科毕业时放弃了出国的想法。如今,为何我又萌生了出国的想法呢?说实话,连我自己也说不清楚。或许小池子说的对吧,我心里还是有一颗出去走走的火苗,如果我出去了,或许有一天我会后悔;可如果我没有出去,我将来肯定会后悔。Follow your heart.

Young and to be young, follow your heart.

题目是“人生的转折点?”,这个出国的决定或许会影响我的一生,甚至改变我今后的职业和发展环境。之所以加个问号,是我又怀疑这个决定真的重大到会“改变”我的人生轨迹吗?会不会如其他决定一样,当我面对它的时候,它总是无限倍地放大,而当几年后我回头再看时,它只是我人生中轻描淡写的一笔。或许根本没有什么能真正改变人生,事实上也根本没有改变之说,谁也不知道“人生”原来怎么样。这就是人生,没什么东西是大不了的。对的错的,好的坏的,都筑成了人生的一分子。

最后想起了你的一句话:

我会勇敢的走下去,只要牵着你的手。

这里的路,已不再只是你我的爱情之路,而是你我的人生长路。