Keywords and properties (in function graphics) [message #87488] |
Fri, 07 February 2014 11:12  |
Gordon Farquharson
Messages: 48 Registered: December 2010
|
Member |
|
|
Hi All
The IDL documentation states that keywords are applied only during the initial creation of the graphic, whereas properties can be set as keywords to the function during creation, or retrieved or changed using the "." notation after creation (e.g., [1]).
Below is a simple program to display an image using a map projection. In the first case (im1), I set all keywords and properties in the function call. In the second case (im2), I only set keywords in the function call, and set properties after the function call.
---
file1 = FILEPATH('Night.jpg', SUBDIRECTORY=['examples','data'])
ret = query_jpeg(file1, info)
lon = findgen(info.dimensions[0]) / info.dimensions[0] * 360. - 180.
lat = findgen(info.dimensions[1]) / info.dimensions[1] * 180. - 90.
read_jpeg, file1, data
im1 = image(data, lon, lat, DIMENSIONS=[1024,512], MARGIN=0., $
GRID_UNITS="degrees", MAP_PROJECTION="Mollweide")
im2 = image(data, lon, lat, DIMENSIONS=[1024,512], MARGIN=0.)
im2.grid_units = "degrees"
im2.map_projection = "Mollweide"
END
---
im1 displays the image as I would expect (warped to the map projection). However, IDL returns the following error when the map_projection property is set for im2.
% Unable to retrieve map projection.
% Execution halted at: $MAIN$ 16 /home/gordon/tmp/test_map.pro
For reference, line 16 is
im2.map_projection = "Mollweide"
Why? Specifically, why I can't change the map projection *property* after the image has been created?
Gordon
[1] http://www.exelisvis.com/docs/image.html
|
|
|
Re: Keywords and properties (in function graphics) [message #87489 is a reply to message #87488] |
Fri, 07 February 2014 12:13   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Gordon Farquharson writes:
>
> Hi All
>
> The IDL documentation states that keywords are applied only during the initial creation of the graphic, whereas properties can be set as keywords to the function during creation, or retrieved or changed using the "." notation after creation (e.g., [1]).
>
> Below is a simple program to display an image using a map projection. In the first case (im1), I set all keywords and properties in the function call. In the second case (im2), I only set keywords in the function call, and set properties after the function call.
>
> ---
> file1 = FILEPATH('Night.jpg', SUBDIRECTORY=['examples','data'])
>
> ret = query_jpeg(file1, info)
>
> lon = findgen(info.dimensions[0]) / info.dimensions[0] * 360. - 180.
> lat = findgen(info.dimensions[1]) / info.dimensions[1] * 180. - 90.
>
> read_jpeg, file1, data
>
> im1 = image(data, lon, lat, DIMENSIONS=[1024,512], MARGIN=0., $
> GRID_UNITS="degrees", MAP_PROJECTION="Mollweide")
>
> im2 = image(data, lon, lat, DIMENSIONS=[1024,512], MARGIN=0.)
>
> im2.grid_units = "degrees"
> im2.map_projection = "Mollweide"
>
> END
> ---
>
> im1 displays the image as I would expect (warped to the map projection). However, IDL returns the following error when the map_projection property is set for im2.
>
> % Unable to retrieve map projection.
> % Execution halted at: $MAIN$ 16 /home/gordon/tmp/test_map.pro
>
> For reference, line 16 is
>
> im2.map_projection = "Mollweide"
>
> Why? Specifically, why I can't change the map projection *property* after the image has been created?
This probably *would* work if the image *had* a map projection object to
change. But, you didn't create this image with a map projection object,
so you can't exactly change what isn't there. You can check to see if
the image *has* a map projection object with the MAPPROJECTION property:
IF im2.mapprojection EQ !Null THEN Print, 'No map projection here!'
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: Keywords and properties (in function graphics) [message #87490 is a reply to message #87489] |
Fri, 07 February 2014 12:41   |
Gordon Farquharson
Messages: 48 Registered: December 2010
|
Member |
|
|
Hi David
You raise a good point. I had not considered what would have to happen internally. However, it seems that the behavior is an inconsistency in IDL, and that therefore, it should be documented. One is supposed to able to change properties after creation of the graphic, and since map_projection is a property, I would expect to be able to apply a map projection after creating of the graphic. Now, I can see that applying a map projection after the creating the graphic could cause all sorts of problems, e.g., axes, honoring aspect ratio, etc., so probably the documentation should be updated. Maybe there is a way to handle things gracefully.
This inconsistency makes me a little grumpy because I had settled on the idea of only setting keywords in the call, and properties after the call to remind me which were which.
Gordon
On Friday, February 7, 2014 12:13:18 PM UTC-8, David Fanning wrote:
> Gordon Farquharson writes:
>
>
>
>>
>
>> Hi All
>
>>
>
>> The IDL documentation states that keywords are applied only during the initial creation of the graphic, whereas properties can be set as keywords to the function during creation, or retrieved or changed using the "." notation after creation (e.g., [1]).
>
>>
>
>> Below is a simple program to display an image using a map projection. In the first case (im1), I set all keywords and properties in the function call. In the second case (im2), I only set keywords in the function call, and set properties after the function call.
>
>>
>
>> ---
>
>> file1 = FILEPATH('Night.jpg', SUBDIRECTORY=['examples','data'])
>
>>
>
>> ret = query_jpeg(file1, info)
>
>>
>
>> lon = findgen(info.dimensions[0]) / info.dimensions[0] * 360. - 180.
>
>> lat = findgen(info.dimensions[1]) / info.dimensions[1] * 180. - 90.
>
>>
>
>> read_jpeg, file1, data
>
>>
>
>> im1 = image(data, lon, lat, DIMENSIONS=[1024,512], MARGIN=0., $
>
>> GRID_UNITS="degrees", MAP_PROJECTION="Mollweide")
>
>>
>
>> im2 = image(data, lon, lat, DIMENSIONS=[1024,512], MARGIN=0.)
>
>>
>
>> im2.grid_units = "degrees"
>
>> im2.map_projection = "Mollweide"
>
>>
>
>> END
>
>> ---
>
>>
>
>> im1 displays the image as I would expect (warped to the map projection). However, IDL returns the following error when the map_projection property is set for im2.
>
>>
>
>> % Unable to retrieve map projection.
>
>> % Execution halted at: $MAIN$ 16 /home/gordon/tmp/test_map.pro
>
>>
>
>> For reference, line 16 is
>
>>
>
>> im2.map_projection = "Mollweide"
>
>>
>
>> Why? Specifically, why I can't change the map projection *property* after the image has been created?
>
>
>
> This probably *would* work if the image *had* a map projection object to
>
> change. But, you didn't create this image with a map projection object,
>
> so you can't exactly change what isn't there. You can check to see if
>
> the image *has* a map projection object with the MAPPROJECTION property:
>
>
>
> IF im2.mapprojection EQ !Null THEN Print, 'No map projection here!'
>
>
>
> Cheers,
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: Keywords and properties (in function graphics) [message #87492 is a reply to message #87490] |
Fri, 07 February 2014 13:02   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Gordon Farquharson writes:
> You raise a good point. I had not considered what would have to happen internally. However, it seems that the behavior is an inconsistency in IDL, and that therefore, it should be documented. One is supposed to able to change properties after creation of the graphic, and since map_projection is a property, I would expect to be able to apply a map projection after creating of the graphic. Now, I can see that applying a map projection after the creating the graphic could
cause all sorts of problems, e.g., axes, honoring aspect ratio, etc., so probably the documentation should be updated. Maybe there is a way to handle things gracefully.
>
> This inconsistency makes me a little grumpy because I had settled on the idea of only setting keywords in the call, and properties after the call to remind me which were which.
Well, there are a LOT of things about IDL that make me grumpy. I guess
you just get used to it. ;-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
|