colors of trajectories

Topics about the HYSPLIT trajectory model.

colors of trajectories

Postby Martina » October 29th, 2013, 10:57 am

Hi all,

I am currently comparing trajectories from different meteorological datasets and some specific locations and I'm struggling a bit with the colouring.
I would like to have at each of my points the same colour per model.

First I simply run hysplit once per model - each time with my 3 points. However what ever options I used with the -k options in trajplot, I only got different colours per point, but not per model.
Then I did it the other way around: looping over my 3 points and running for each of it hysplit with the different meterological datasets.
This worked well as long as I had 3 models with the command
Code: Select all
 ${MDL}/exec/trajplot -i+filelist -otrajplot_${number}.ps -g0:1200 -h71:-45

where filelist contains my different trajectories in the order
point1model1
point1model2
point1model3
point2model1
point2model2
point2model3
point3model1
point3model2
point3model3

But now I have four models, and I can't convince trajplot to use more than 3 colours and thus I do not have anymore one colour per model at each point, but at the first point one trajectory of color 1, one of color 2 and two of color 3 - and similar at the other points.
I tried -k12:123412341234 and -k4:1234 and k12:111222333444, but nothing is giving me the effect that I'm looking for. Basicly whatever I put leads to haveing one and the same colour everywhere!

Is there anyway to prescribe the colors? Did I misunderstood the use of the -k option?

Also, I was wondering, is there a simple way to set up a legend, i.e. saying that color red corresponds to model 1, color blue to model 2 etc?

Thanks a lot for your help,
Martina
Martina
 
Posts: 17
Joined: September 27th, 2013, 10:26 am

Re: colors of trajectories

Postby yaqiang » October 29th, 2013, 8:55 pm

MeteoInfo can plot trajectories with many options which should meet your need.
yaqiang
 
Posts: 38
Joined: November 22nd, 2012, 4:02 am

Re: colors of trajectories

Postby Martina » October 30th, 2013, 3:09 pm

Hi,

ok, true, so far I wasn't exploring the options of doing the plots outside of hysplit!
I'll be away now for around a week, but I'll look into that option then once I'm back.
What I liked so far with trajplot was that I could run it directly from my script (it would be difficult otherwise since I'm looping over days, points and meteodata) and do get one single pdf-file with multiple pages with all my runs by pressing one button. So I would be hoping to get something similar also with MeteoInfo (at least the plotting part, even if the simulation part would be done separately).

Thanks for your advice,
Martina
Martina
 
Posts: 17
Joined: September 27th, 2013, 10:26 am

Re: colors of trajectories

Postby yaqiang » October 31st, 2013, 8:53 pm

All MeteoInfo functions can be auto run using the script, but the knowledge of the MeteoInfo library is needed. I will post some sample scripts in near future.
yaqiang
 
Posts: 38
Joined: November 22nd, 2012, 4:02 am

Re: colors of trajectories

Postby Martina » November 1st, 2013, 7:13 am

That sounds great, I would be looking foward to that!

Martina
Martina
 
Posts: 17
Joined: September 27th, 2013, 10:26 am

Re: colors of trajectories

Postby Martina » November 21st, 2013, 10:31 am

Hi all,

after the traveling and spending time on other projects, I'm no back to my trajectory-hysplit projects.
I tried now the plotting with MeteoInfo and I agree, it works very nicely - a pity however that there wasn't any feedback from any hysplit (non MetoInfo) users or developpers :-(.
I started now looking into the usage of scripts in MeteoInfo, since all the clicking otherwise is too timeconsuming and not possible when working with my larger simulation sets. For the start I have one main question: The documentation about scripts that I found deals with the "normal" MeteoInfo version, while I'm using the Java Version.
Is it also possible to do that also with the Java Version and could someone outline if so the basic steps (instead of the usage of MIScript.exe)? Or maybe you could point me to some other documentation? (I'm had some troubles to install the normal MeteoInfo version, so I'd like to know if I should now go back to that or if I can continue with the Java version.)

Thanks,
Martina
Martina
 
Posts: 17
Joined: September 27th, 2013, 10:26 am

Re: colors of trajectories

Postby yaqiang » November 22nd, 2013, 11:15 am

It is a huge job to write an integrated MeteoInfo script document, and unfortunately I can not find much time to do it. For general, Jython (or Groovy) and MeteoInfo Java library knowledge are needed to write script programs. I write two small scripts to describe how to calculate and plot trajectories.

The script to write CONTROL file and calculate trajectories using HYSPLIT:
Code: Select all
#-----------------------------------------------------
# Author: Yaqiang Wang
# Date: 2013-11-22
# Purpose: Write control file and run HYSPLIT trajectory model
# Note: Sample
#-----------------------------------------------------
import os
import time
from datetime import datetime

# Set working directory
workingDir = 'C:/hysplit4/working'
os.chdir(workingDir)
print 'Current directory: ' + os.getcwd()

# Set start time
stime = datetime(1995,10,16)

# Set meteorological file
metFile = 'oct1618.BIN'

# Write CONTROL file
print 'Write CONTROL file ...'
ctFile = './CONTROL'
ctf = open(ctFile, 'w')
ctf.write(stime.strftime('%y %m %d %H') + "\n")
ctf.write("3\n")
ctf.write("40.0 -90.0    10.0\n")
ctf.write("40.0 -90.0    500.0\n")
ctf.write("40.0 -90.0    1000.0\n")
ctf.write("12\n")
ctf.write("0\n")
ctf.write("10000.0\n")
ctf.write("1\n")
ctf.write("./" + "\n")
ctf.write(metFile + "\n")
ctf.write("./" + "\n")
trajFile = 'Traj_test'
ctf.write(trajFile)
ctf.close()

# Run HYSPLIT trajectory
print 'Run HYSPLIT trajectory ...'
os.system("c:\\hysplit4\\exec\\hyts_std.exe ")

print 'Finish...'


The script to open trajectory file, create and add trajectory layer in the MeteoInfo application, then output a figure:
Code: Select all
#-----------------------------------------------------
# Author: Yaqiang Wang
# Date: 2013-11-22
# Purpose: Add traj data as a layer and output figure
# Note: Sample
#-----------------------------------------------------
import os
from org.meteoinfo.data.meteodata import MeteoDataInfo
from org.meteoinfo.legend import LegendScheme
from org.meteoinfo.shape import ShapeTypes

# Set working directory
workingDir = 'C:/hysplit4/working'
outDir = 'D:/Temp/traj'

# Open trjactory data file and add trjectory layer
print 'Open trajectory data file ...'
# Create a MeteoDataInfo object
mdi = MeteoDataInfo()
# Open trajectory data file
trajFile = 'Traj_test'
trajfn = os.path.join(workingDir, trajFile)
print 'Trajectory file: ' + trajfn
mdi.openHYSPLITTrajData(trajfn)
# Create trajectory layer
trajLayer = mdi.getDataInfo().createTrajLineLayer()
trajLayer.setLayerName('Trajectories')
# Load a legend scheme from the previous saved legend file
aLS = LegendScheme(ShapeTypes.Polyline)
legendfn = os.path.join(outDir, 'traj.lgs')
aLS.importFromXMLFile(legendfn)
trajLayer.setLegendScheme(aLS)
# Create a start point layer
stLayer = mdi.getDataInfo().createTrajStartPointLayer()
# Add the layers into the MeteoInfo application (miapp)
mf = miapp.getMapDocument().getActiveMapFrame()
mf.addLayer(trajLayer)
mf.addLayer(stLayer)

# Output figure
figurefn = os.path.join(outDir, 'Traj_figure.png')
miapp.getMapDocument().getMapLayout().exportToPicture(figurefn)

print 'Finish...'


Image00060.png
yaqiang
 
Posts: 38
Joined: November 22nd, 2012, 4:02 am

Re: colors of trajectories

Postby Martina » November 27th, 2013, 10:34 am

Thanks a lot for these examples, that gives me a good starting point for my own work.
I have solved in the meanwhile also my actual question of my last post, when I was wondering what to do instead of using MIScript.exe + script. I realized that I could simply put these scripts in the Script window from the Java version and everything works fine now.

Thanks!
Martina
Martina
 
Posts: 17
Joined: September 27th, 2013, 10:26 am

Re: colors of trajectories

Postby Martina » November 29th, 2013, 8:52 am

Hi Yaqiang,

I am makeing progress with my jython scripts, however there is a few points that I'm struggling with.

First, is there any kind of documentation? I found a chinese forum which I google translated partly but didn't really found what I'm looking for. For the moment I'm just using javap -v on the *.class files in the MeteoInfo.jar, but it's not a very handy way of getting infos about existing attributes and subroutines....

In your example scripts:
What kind of object is "miapp"? Why is it nowhere defined in your script? I tried things like miapp = mdi.app(), but that's not going to work, so somehow it's automatically created. Can I create it also by myself to use the script outside of the GUI?

Then I was trying to add my background image (currently it's a shapefile or an imagefile), so I was searching for the equivalent of createTrajLineLayer() or createRasterLayer() but couldn't find anything that would digest my input files.

Then I need to make several separate figures, however all my figures are the same and contain what should be distributed over severals:
Code: Select all
for day in days:
       # Add the layers into the MeteoInfo application (miapp)
       mf = miapp.getMapDocument().getActiveMapFrame()
       #...
       #.... do some stuff
       mf.addLayer(trajLayer)
       # Output figure
       figfile='Traj_figure_day'+day+'.png' #this fig should only contain what was drawn on the iteration "day"
       if os.path.isfile(figfile):
            os.remove(figfile)
       figurefn = os.path.join(outDir,figfile)
       miapp.getMapDocument().getMapLayout().exportToPicture(figurefn)

I tried to use difference instances of mf, but that didn't help, my feeling is that I somehow would need different MapDocument or even several miapps?

And last but not least the legends are working fine in the sens that the colors are chosen as I like it, however the legend is not depicted on the figure. How can I switch it on and place it in a suitable place? Could give me a hint in which of the class file to find the corresponding commands?

Thanks a lot for your support.

Martina
Martina
 
Posts: 17
Joined: September 27th, 2013, 10:26 am

Re: colors of trajectories

Postby yaqiang » December 2nd, 2013, 10:33 am

1. 'jd-gui' is a good tool to check the classes and functions in jar file. The main functions of MeteoInfo are included in MeteoInfoLib.jar file.
2. The basic struct of MeteoInfo library can be found in my paper of MeteoInfo (http://onlinelibrary.wiley.com/doi/10.1 ... 5/abstract). There are some script samples in my Chinese blog (http://hi.baidu.com/meteoinfo), but has not many Jython scripts at present.
3. 'miapp' is the object of the main form of MeteoInfo GUI which is defined inside in the script engine, so from it you can control the GUI and you need not to define it in script program. You can write a script using the MapView or MapLayout object without GUI by using the MapView or MapLayout class in MeteoInfo library, but more lines are needed to do it.
4. The static function of 'loadLayer(String aFile)' in MapDataManage class which located in org.meteoinfo.data.mapdata is developed for creating a layer of an existing shape or image file.
5. If running script in GUI is acceptable, You can prepare the background layers, legend, title and so on by hand and save a project file (.mip) which can be used by loading it. So in the script you will only focus on meteorological data.
6. Another sample Jython script:
Code: Select all
#-----------------------------------------------------
# Author: Yaqiang Wang
# Date: 2013-12-2
# Purpose: Open MICAPS station data and plot precipitation point figures
# Note: Sample
#-----------------------------------------------------
from org.meteoinfo.data.meteodata import MeteoDataInfo
from org.meteoinfo.data.meteodata import DrawMeteoData
from org.meteoinfo.legend import LegendScheme
from org.meteoinfo.shape import ShapeTypes
import os.path
import time
from datetime import datetime
from datetime import timedelta
from calendar import monthrange

#---- Set directory
legendDir = "D:/Temp/micaps/"
dataDir = "D:/SampleData/micaps"
outDir = "D:/Temp/test/"

#---- Set legend
ls = LegendScheme(ShapeTypes.Point)
ls.importFromXMLFile(os.path.join(legendDir,'test.lgs'))

#---- Get title
title = miapp.getMapDocument().getMapLayout().getTexts()[0]

#---- Set MeteoDataInfo
mdi = MeteoDataInfo()

#---- Set start end time
sTime = datetime(2013,1,1,2,0,0)
eTime = datetime(2013,1,2,2,0,0)

#---- Loop
while sTime < eTime:
   #---- Set file name   
   inFile = sTime.strftime('%y%m%d%H') + ".000"
   print inFile
   #---- Open data file
   mdi.openMICAPSData(os.path.join(dataDir, inFile))
   #---- Get precipitation data
   stData = mdi.getStationData("Precipitation6h")
   #---- Create station point layer
   layer = DrawMeteoData.createSTPointLayer(stData, ls, "Rain_" + inFile, "Rain")
   miapp.getMapDocument().getActiveMapFrame().addLayer(layer)   
   #---- Set title
   title.setLabelText('Precipitation_' + sTime.strftime('%Y%m%d %H:00'))
   #---- Set output file
   outFile = "Prec_" + sTime.strftime('%Y%m%d%H') + ".png"
     print outFile
   miapp.getMapDocument().getMapLayout().exportToPicture(os.path.join(outDir, outFile))
   miapp.getMapDocument().getActiveMapFrame().removeLayer(layer)
   sTime = sTime + timedelta(hours=6)
   
print 'Finished!'
yaqiang
 
Posts: 38
Joined: November 22nd, 2012, 4:02 am

Next

Return to Trajectory Model

Who is online

Users browsing this forum: No registered users and 1 guest

cron