Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update coord2area_def.py #931

Merged
merged 4 commits into from Dec 28, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 41 additions & 16 deletions utils/coord2area_def.py
Expand Up @@ -17,21 +17,46 @@
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Convert human coordinates (lon and lat) to an area definition.

Here is a usage example:
Here is a usage example.

python coord2area_def.py france stere 42.0 51.5 -5.5 8.0 1.5
(the arguments are "name proj min_lat max_lat min_lon max_lon resolution(km)")
The arguments are "name proj min_lat max_lat min_lon max_lon resolution(km)".
The command above yelds the following result.

### +proj=stere +lat_0=46.75 +lon_0=1.25 +ellps=WGS84

france:
description: france
projection:
proj: stere
ellps: WGS84
lat_0: 46.75
lon_0: 1.25
shape:
height: 703
width: 746
area_extent:
lower_left_xy: [-559750.381098, -505020.675776]
upper_right_xy: [559750.381098, 549517.351948]


The first commented line is just a sum-up. The value of "description" can be changed to any descriptive text.

Such a custom yaml configuration can be profitably saved in a local areas.yaml configuration file that won't be
overridden by future updates of SatPy package. For that purpose the local processing script may have suitable
lines as reported below.

# set PPP_CONFIG_DIR for custom composites
import os
os.environ['PPP_CONFIG_DIR'] = '/my_local_path/for_satpy_configuration'

As a further functionality this script may give a quick display of the defined area,
provided the path for the GSHHG library is supplied via the "-s" option.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should maybe be mentioned that pycoast, pillow and aggdraw need to be installed also for this functionality to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just done. Thanks for the suggestion!


python coord2area_def.py france stere 42.0 51.5 -5.5 8.0 1.5 -s /path/for/gshhs/library

and the result is:
REGION: france {
NAME: france
PCS_ID: stere_1.25_46.75
PCS_DEF: proj=stere,lat_0=46.75,lon_0=1.25,ellps=WGS84
XSIZE: 746
YSIZE: 703
AREA_EXTENT: (-559750.38109755167, -505020.6757764442,
559750.38109755167, 549517.35194826045)
};
The command above would first print the seen area definition and then launch a casual representation
of the area relying on the information about borders involved.

"""

Expand Down Expand Up @@ -100,7 +125,7 @@
" +".join(("proj=" + proj + ",lat_0=" + str(lat_0) +
",lon_0=" + str(lon_0) + ",ellps=WGS84").split(","))

print(proj4_string)
print('### ' + proj4_string)
print()
print(name + ":")
print(" description: " + name)
Expand All @@ -121,11 +146,11 @@
from PIL import Image
from pycoast import ContourWriterAGG
img = Image.new('RGB', (xsize, ysize))
#proj4_string = '+proj=geos +lon_0=0.0 +a=6378169.00 +b=6356583.80 +h=35785831.0'
#area_extent = (-5570248.4773392612, -5567248.074173444, 5567248.074173444, 5570248.4773392612)


area_def = (proj4_string, area_extent)
cw = ContourWriterAGG(args.shapes)
#cw = ContourWriterAGG('/usr/share/gshhg-gmt-shp/')

cw.add_coastlines(img, (proj4_string, area_extent),
resolution='l', width=0.5)

Expand Down