colors of trajectories

Topics about the HYSPLIT trajectory model.

Re: colors of trajectories

Postby Martina » December 5th, 2013, 10:46 am

Hi,

thanks once more for your infos. (Comment aside, maybe it would be good to have a subforum about MeteoInfo things if MeteoInfo is used more frequently with hysplit)?
1. jd-gui is great, thanks for the hint.
2. Yes, I have seen your chinese blog, but there is more IronPython than Jython examples which did rather confuse me :-(.
3. But where is this miapp to be fount in the MetoInfo class/function tree? For example, "miapp.getMapDocument().getMapLayout().getTexts()[0]" is not working for me, it says AttributeError: 'org.meteoinfo.layout.MapLayout' object has no attribute 'getTexts', so I guess I have not loaded all what I would have needed, but I can't find this getMapDocument() in the class-tree.
4. So far I have
Code: Select all
mdi = MeteoDataInfo()
mdm = MapDataManage()
mf = miapp.getMapDocument().getActiveMapFrame()
backFile = 'country1.shp'
backn1 = os.path.join(mapDir, backFile)
backlayer = mdm.loadLayer(backn1)
mf.addLayer(backlayer)

what crashes with NullPointerException at addLayer.
5. It' not my favorite solution, but that would of course work. However, for the moment it doesn't work for the legend: If I save a project file with 3 legend entries and I reopen the project again, there is still 3 legend entries, but 3 times the same and not those that I had chosen!
6. I'm still haveing troubles with the loop over figures since I do have another loop inside my time-loop. So I think I'd need somehow an array of trajectory layers or a something like "remove all layers".
Code: Select all
for day in days:
   # Add the layers into the MeteoInfo application (miapp)
   mf = miapp.getMapDocument().getActiveMapFrame()
   for point in points:
      # Open trajectory data file
        trajFile = 'CFSR_'+point+'_'+day
      trajfn1 = os.path.join(workingDir, trajFile)
      print 'Trajectory file: ' + trajfn1
      mdi.openHYSPLITTrajData(trajfn1)
      # Create trajectory layer
      trajLayer1 = mdi.getDataInfo().createTrajLineLayer()
      trajLayer1.setLayerName('CFSR')
      # Load a legend scheme from the previous saved legend file
      aLS = LegendScheme(ShapeTypes.Polyline)
      legendfn = os.path.join(legendDir, 'blue.lgs')
      aLS.importFromXMLFile(legendfn)
      trajLayer1.setLegendScheme(aLS)
      mf.addLayer(trajLayer1)
   figfile='Traj_figure_day'+day+'.png'
   if os.path.isfile(figfile):
      os.remove(figfile)
   figurefn = os.path.join(outDir,figfile)
   miapp.getMapDocument().getMapLayout().exportToPicture(figurefn)
   mf.removeLayer(trajLayer1)#this removes now only the layer for my last point, but not for the others!


Thanks a lot again for your help,

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

Re: colors of trajectories

Postby yaqiang » December 6th, 2013, 4:53 am

This is HYSPLIT forum from ARL which has no duty to prompt third party software such as MeteoInfo, so forget MeteoInfo subforum. But I think it's good for ARL to see any contribution to HYSPLIT from third party.

1.
2. Most functions are similar between C# and Java version of MeteoInfo, but still many diversities exist. Same condition between IronPython and Jython.
3. miapp is the object of FrmMain class in MeteoInfo.jar. miapp.getMapDocument() will return the LayersLegend object in miapp. miapp.getMapDocument().getMapLayout() will return the MapLayout object in miapp. there may be one or more MapFrames in a LayersLegend, but just has one active MapFrame which can be got by miapp.getMapDocument.getActiveMapFrame() function. MapLayout class has getTexts() function in my side. You can check it using jd-gui and make sure you are using newest 0.9.6 Java version of MeteoInfo. Please let me know if there is still no it in the newest version online for updating remind.
4. I didn't find any error in your script. The error message clues maybe backlayer is null, so please check if backn1 is really exist.
5. You can run MeteoInfo script program outside GUI application by command "java -jar MeteoInfo.jar sample.py". But you have to define miapp variable and load a project file if GUI functions are needed. A sample script:
Code: Select all
#-----------------------------------------------------
# Author: Yaqiang Wang
# Date: 2013-11-22
# Purpose: Create a FrmMain object
#          Add traj data as a layer and output figure
# Note: Sample
#-----------------------------------------------------
from meteoinfo.forms import FrmMain
import os
from org.meteoinfo.data.meteodata import MeteoDataInfo
from org.meteoinfo.legend import LegendScheme
from org.meteoinfo.shape import ShapeTypes

# Create a FrmMain object
miapp = FrmMain()
fn = 'D:\\MyProgram\\java\\MeteoInfoDev\\MeteoInfo\\default.mip'
miapp.openProjectFile(fn)

# 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...'

#miapp.setVisible(True)


6. Using removeMeteoLayers() function in MapFrame object.
yaqiang
 
Posts: 38
Joined: November 22nd, 2012, 4:02 am

Re: colors of trajectories

Postby Martina » December 13th, 2013, 4:50 am

Hei Yaqiang,
thanks once more for your helpfull answers and sorry for the delay, but it took me a while to explore everything.

3: You were right, I wasn't using the newest MeteoInfo version (version 0.9.6 is online available, but I had an older one and not had the idea to check if there might be a newer one available). That has solved some issues, for example the one with the Text.
4: I still can't add shape files in my script, however I'm doing that now in the gui and saving in the projectfile and that works well (I need only one and the same as background for all figures).
5: Running MeteoInfo without GUI works perfectly fine now, that's a great option!
6: removeMeteoLayers() is also doing it's job.

Everything seams to work now, besides the legends. I have prepared in my .mip files all legends that I want, however when I run my script, I get the same legend 3 times instead of 3 different ones drawn in the figure (in the example below I get 2 red instead of one blue and one red legend. However the trajectories are drawn with the correct color.) Probably I have to set them up differently in my .mip file?

Code: Select all
for day in days:
   title.setLabelText('this is day '+day)
   for point in points:
      # Open trajectory data file
      trajFile = 'CFSR_'+point+'_'+day
      trajfn1 = os.path.join(workingDir, trajFile)
      mdi.openHYSPLITTrajData(trajfn1)
      # Create trajectory layer
      trajLayer1 = mdi.getDataInfo().createTrajLineLayer()
      trajLayer1.setLayerName('CFSR')
      # Load a legend scheme from the previous saved legend file
      aLSblue = LegendScheme(ShapeTypes.Polyline)
      legendblue = os.path.join(legendDir, 'blue.lgs')
      aLSblue.importFromXMLFile(legendblue)
      trajLayer1.setLegendScheme(aLSblue)
      mf.addLayer(trajLayer1)
      trajFile = 'GDASnew_'+point+'_'+day
      trajfn2 = os.path.join(workingDir, trajFile)
      print 'Trajectory file: ' + trajfn2
      mdi.openHYSPLITTrajData(trajfn2)
      # Create trajectory layer
      trajLayer2 = mdi.getDataInfo().createTrajLineLayer()
      trajLayer2.setLayerName('GDASnew')
      # Load a legend scheme from the previous saved legend file
      aLSred = LegendScheme(ShapeTypes.Polyline)
      legendred = os.path.join(legendDir, 'red.lgs')
      aLSred.importFromXMLFile(legendred)
      trajLayer2.setLegendScheme(aLSred)
      mf.addLayer(trajLayer2)
   # Output figure
   figfile='Traj_figure_day'+day+'.png'
   if os.path.isfile(figfile):
      os.remove(figfile)
   figurefn = os.path.join(outDir,figfile)
   miapp.getMapDocument().getMapLayout().exportToPicture(figurefn)
        mf.removeMeteoLayers() #there is no intent in this codeline, it's just the forum that adds it and I can't get rid of it


Thanks and have a nice week-end,

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

Re: colors of trajectories

Postby yaqiang » December 13th, 2013, 9:33 am

Legend in MapLayout is an object of LayoutLegend which has some auto update options such as show the legend of the first meteorological layer. If there are two legends in a MapLayout with same update option, then they will be plotted same. In fact, a legend is controlled by the layer associated with it, so the function 'public void setLegendLayer(MapLayer layer)' of LayoutLegend is essential to change the legend behavious.

For example:
Code: Select all
mapLayout = miapp.getMapDocument().getMapLayout()
legends = mapLayout.getLgends()   
#----If two legends exist
legends[0].setLegendLayer(trajLayer1)
legends[1].setLegendLayer(trajLayer2)
.
yaqiang
 
Posts: 38
Joined: November 22nd, 2012, 4:02 am

Re: colors of trajectories

Postby Martina » December 17th, 2013, 10:41 am

Thanks, that's doing the job!
Now I have to solve my time-problem, and then I'm hopefully done and can start doing science after getting the tools ready!

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

Previous

Return to Trajectory Model

Who is online

Users browsing this forum: No registered users and 1 guest

cron