amaurea / enlib

5 stars 12 forks source link

Projection attribute #15

Open msyriac opened 7 years ago

msyriac commented 7 years ago

Apologies if this already exists, but is there an attribute for an ndmap that tells me what projection is being used?

My use case is the following. Say I know the shape and wcs of a patch on the sky. I want to get the shape and wcs for an ndmap that is on the same region of the sky but has higher resolution. So I do the following:

shape_known = my_coarse_map.shape
wcs_known = my_coarse_map.wcs
bbox = enmap.box(shape_known,wcs_known)
my_fine_map = enmap.geometry(bbox,res=high_res_pixel,proj=projection)

Is there some way I can get the projection of the map like so?

projection = my_coarse_map.proj
amaurea commented 7 years ago

Sorry, no. There are a large number of WCS coordinate systems provided by wcslib, and I don't know of any straightforward way of extracting a simple identifier string for them. So you can't do what you want in general using geometry.

Instead, you will need to manipulate the wcs and shape yourself. There should definitely be a function for this (like scale-geometry or something), but it doesn't currently exist. But you can have a look at enmap.upgrade to see how it works (see the part under "Correct the WCS information"). It's pretty straightforward.

Of course, if the factor you want to upscale by is an integer, then you can just call enmap.upgrade directly.

msyriac commented 7 years ago

Ok, I understand. enmap.upgrade with integer factors should actually do just fine. I actually only need the shape and wcs, and not the (really large) resulting array. Is it possible to predict what the shape will be without doing the expensive numpy.tile?

amaurea commented 7 years ago

Ok, I understand. enmap.upgrade with integer factors should actually do just fine. I actually only need the shape and wcs, and not the (really large) resulting array. Is it possible to predict what the shape will be without doing the expensive numpy.tile?

I've made a convenience function for you now.

oshape, owcs = enmap.scale_geometry(shape, wcs, 2.5)

would give you the geometry needed to construct a map with 2.5 times higher resolution, but covering the same area with the same projection.