colors of trajectories

Topics about the HYSPLIT trajectory model.
Martina
Posts: 21
Joined: September 27th, 2013, 10:26 am
Registered HYSPLIT User: No

Re: colors of trajectories

Post by Martina »

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: 21
Joined: September 27th, 2013, 10:26 am
Registered HYSPLIT User: No

Re: colors of trajectories

Post by Martina »

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: 21
Joined: September 27th, 2013, 10:26 am
Registered HYSPLIT User: No

Re: colors of trajectories

Post by Martina »

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
Post Reply

Return to “Trajectory Model”