Healpix / Healpy: How can I use healpy to do SHT for a patch on the sky? - fft

Healpix is a very useful software to do spherical analysis on a sphere. For example, we can use map2alm to analyze a Healpix RING ordered map and return spherical harmonics. Here the argument of map should be an array with $Npix = 12*Nside^2$. If I only want to do analysis on a patch, but not on a full-sky. Some ring-weights can be used to mask the map in Healpix. But if Npix is very big, actually the array of map will too big to be allocated in memory. Thus, how can I do the spherical harmonics transform on a sky-patch?

Unfortunately in healpy and HEALPix, spherical transforms are always executed full-sky.
If you are working on a small patch of sky you could use rectangular pixelization instead, see the pixell package at https://github.com/simonsobs/pixell, then you can use FFT transforms instead of spherical harmonics.
You can also checkout the CMB Analysis Summer School notebooks: https://github.com/jeffmcm1977/CMBAnalysis_SummerSchool/blob/master/CMB_School_Part_04.ipynb

Related

QGIS slope calculator not producing expected result

I am trying to visualize slope for an elevation raster using QGIS terain analysis tool. The results are no what I would expect.
Elevation raster is from NASA's SRTM program. I picked a relatively mountainous region to run a test N39W121.
elevation model looks like this
but resulting slope raster only has two values 0 and 89.9 .
I used default setting's in QGIS' DEM tool, set to slope mode. Can anyone help me firgure out what I'm doing wrong. Is it a problem with the original data, or is it settings? I am at a loss. Calculating hillshade and ruggedness index with the same tool produced results as expected
By default, SRTM's map horizaontal units are in degrees (WGS84), where the vertical units for SRTM is in meters. This either needs to be compensated for in QGIS's DEM analysis settings or the SRTM raster needs to be converted to a projection that uses meters for its map units.

Applying a Kalman filter on a leg follower robot

I was asked to create a leg follower robot (I already did it) and in the second part of this assignment I have to develop a Kalman filter in order to improve the following process of the robot. The robot gets from the person the distance where she is to the robot and also the angle (it is a relative angle, because the reference is the robot itself, not absolute x-y coordinates)
About this assignment I have a serious doubt. Everything I have read, every sample I have seen about kalman filter has been in one dimension (a car running distance or a rock falling from a building) and according to the task I would have to apply it in 2 dimensions. Is it possible to apply a kalman filter like this?
If it is possible to calculate kalman filter in 2 dimensions then I would understand that what is asked to do is to follow the legs in a linnearized way, despite a person walks weirdly (with random movements) --> About this I have the doubt of how to establish the function of the state matrix, could anyone please tell me how to do it or to tell me where I can find more information about this?
thanks.
Well you should read up on Kalman Filter. Basically what it does is estimate a state through its mean and variance separately. The state can be whatever you want. You can have local coordinates in your state but also global coordinates.
Note that the latter will certainly result in nonlinear system dynamics, in which case you could use the Extended Kalman Filter, or to be more correct the continuous-discrete Kalman Filter, where you treat the system dynamics in a continuous manner and the measurements in discrete time.
Example with global coordinates:
Assuming you have a small cubic mass which can drive forward with velocity v. You could simply model the dynamics in local coordinates only, where your state s would be s = [v], which is a linear model.
But, you could also incorporate the global coordinates x and y, assuming we are moving on a plane only. Then you would have s = [x, y, phi, v]'. We need phi to keep track of the current orientation since the cube can only move forward in respect to its orientation of course. Let's define phi as the angle between the cube's forward direction and the x-axis. Or in other words: With phi=0 the cube would move along the x-axis, with phi=90° it would move along the y-axis.
The nonlinear system dynamics with global coordinates can then be written as
s_dot = [x_dot, y_dot, phi_dot, v_dot]'
with
x_dot = cos(phi) * v
y_dot = sin(phi) * v
phi_dot = ...
v_dot = ... (Newton's Law)
In EKF (Extended Kalman Filter) Prediction step you would use the (discretized) equations above to predict the mean of the state in the first step of and the linearized (and discretized) equations for prediction of the Variance.
There are two things to keep in mind when you decide what your state vector s should look like:
You might be tempted to use my linear example s = [v] and then integrate the velocity outside of the Kalman Filter in order to obtain the global coordinate estimates. This would work, but you would lose the awesomeness of the Kalman Filter since you would only integrate the mean of the state, not its variance. In other words, you would have no idea what the current uncertainties for your global coordinates are.
The second step of the Kalman Filter, the measurement or correction update, requires that you can describe your sensor output as a function of your states. So you may have to add states to your representation just so that you can express your measurements correctly as z[k] = h(s[k], w[k]) where z are measurements and w is a noise vector with Gaussian distribution.

Can I use healpy to stack sky?

I would like to stack WMAP maps at the locations of galaxies. Is it possible to perform this using healpy? Which function in healpy allows me to get a projection of the sky around a point?
thanks
with gnomview you can specify the central point with rot, then set return_projected_map=True to get a 2D array of the projected map back.

2D Open Street Map Data Representation in Meters

I am in the process of converting OSM data into an open source Minecraft port (written in javascript - voxel.js). The javascript rendition is written such that each voxel (arbitrarily defined as a cubic meter) is created as a relation from a single point of origin (x,y,z)(0,0,0).
As an example, if one wanted to create a cubic chunk of voxels, one would simply generate voxels as a relation to the origin (0,0,0) : [(0,0,0),(1,0,0), (0,1,0)...].
My question is this: I've exported OSM data, and the standard XML output (.osm) plots nodes in latitude and longitude. My initial thought is that I can create a map by calculating the distance of each node from an arbitrary point of origin (0,0,0) = (37.77559, -122.41392) using the Haversine formula, convert the distance to meters, find the bearing, and plot it as a relation to (0,0,0).
I've noticed, however, that there are a number of other export formats available: (.osm.pbf, .osm2pgsql, .imposm). I'm assuming they plot nodes in a similar fashion (lat, lng), but some of them have the ability to import directly into a database (e.g. PostgreSQL).
I've heard of people using PG add-ons like PostGIS, but (as this is my first dive into GIS) I'm unfamiliar with their capabilities and whether something like PostGIS would help me in plotting OSM data into a 2D voxel grid.
Are there functions within add-ons like PostGIS that would enable me to dynamically calculate the distance between two Lat/Lng points, and plot them in an x,y fashion?
I guess, fundamentally, my question is: if I create a script that plots OSM data into an x,y grid would I be reinventing the wheel, or is there a more efficient way to do this?
You need to transform from the spherical coordinates (LatLon, using WGS84) to cartesian coordinates, like googles spherical mercator.
In pseudo code
transform(double lat, double lon) {
double wgs84radius = 6378137;
double shift = PI * wgs84radius;
double x = lon * shift / 180;
double y = log(tan((90+lat)*PI/360)/ (PI/180);
return {x,y}
}
This is the simplest way. Keep in mind that Lat/Lon are angles, while x and y are distances from (0/0)
The OSM data is by default in the WGS84 (EPSG:4326) projection which is based on an ellipsoidal Earth and measures latitude and longitude in degrees.
Most map tiles are generated in the EPSG:900913 "Google" spherical mercator projection. This projection is based on a spherical Earth and latitude and longitude are measured in metres from the origin.
It really seems like the 900913 projection will fit quite nicely with your requirements.
Here is some code for converting between the two.
You might like to consider using osm2psql. During the import process all of the OSM map data is converted to the 900913 projection. What you are left with is a database of all the nodes, lines and polygons of the OSM map data in an easy to access Postgres database.
I was initially intimidated by this process but it is really quite straightforward and will give you lots of flexibility when it comes to using the OSM data.

lat long intersection

I have two sets of "lines" drawn using a mapping API in the form of (lat,long) pairs. Given 2 of these lines, how can I compute the (lat, long) of their intersection (assuming they intersect)?
Depends on what coordinate system you're in.
You'll need the geodesic along the surface of the model you're using for each line segment (you can choose any convenient altitude you want since you only care about lat and long). Then the point that's on both geodesics (if it exists) is your answer. Note also that one geodesic may be coincident with the other (superimposed).
Since you're using the Mercator projection, you can translate the lat and long to X and Y on your map, then solve for their intersection easily.