Given the following world images:
night = Import["http://eoimages.gsfc.nasa.gov/images/imagerecords/55000/55167/earth_lights_lrg.jpg"]
day = Import["http://eoimages.gsfc.nasa.gov/images/imagerecords/57000/57752/land_shallow_topo_2048.tif"]
how would you use Mathematica to create an accurate “day and night map” (examples here and there) of the Earth for a given date and time?
Answer
Let me first name your maps correctly (you switched night and day maps):
night= Import["http://eoimages.gsfc.nasa.gov/images/imagerecords/55000/55167/earth_lights_lrg.jpg"];
day= Import["http://eoimages.gsfc.nasa.gov/images/imagerecords/57000/57752/land_shallow_topo_2048.tif"];
The images have different sizes:
ImageDimensions[day]
(*
==> {2048, 1024}
*)
ImageDimensions[night]
(*
==> {2400, 1200}
*)
so, I rescale the night image. Artefacts (if any) will probably be less visible there.
night = ImageResize[night, ImageDimensions[day]];
Now, for the calculation of the mask we don't need to use external sources. AstronomicalData
will do:
mask =
Rasterize[
RegionPlot[
AstronomicalData["Sun", {"Altitude", {2012, 6, 21}, {lat, long}}] <
0, {long, -180, 180}, {lat, -90, 90}, Frame -> None,
PlotRange -> Full, PlotStyle -> Black, PlotRangePadding -> 0,
AspectRatio -> (#2/#1 & @@ ImageDimensions[day])],
ImageSize -> ImageDimensions[day]
]
Then, stealing the ImageCompose
idea from Yu-Sung:
pl=ImageCompose[night, SetAlphaChannel[day, mask]]
Borrowing and adapting some code from the Texture
doc page:
Show[
Graphics3D[{White, Tube[{{0, 0, -1.4}, {0, 0, 1.4}}, .04]}],
SphericalPlot3D[1 , {u, 0, Pi}, {v, 0, 2 Pi}, Mesh -> None,
TextureCoordinateFunction -> ({#5, 1 - #4} &),
PlotStyle -> Texture[Show[pl, ImageSize -> 1000]],
Lighting -> "Neutral", Axes -> False, RotationAction -> "Clip"],
Lighting -> "Neutral", Boxed -> False,
Method -> {"ShrinkWrap" -> True}
]
Comments
Post a Comment