source: trunk/src/scripts_Laura/ARCTIC/Travail_CEN/distance_lon_lat.py @ 55

Last change on this file since 55 was 40, checked in by lahlod, 10 years ago

scripts ajoutes apres CEN

File size: 1.4 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3import string
4import numpy as np
5import matplotlib.pyplot as plt
6from pylab import *
7from mpl_toolkits.basemap import Basemap
8from mpl_toolkits.basemap import shiftgrid, cm
9from netCDF4 import Dataset
10#import arctic_map # function to regrid coast limits
11#import cartesian_grid_test # function to convert grid from polar to cartesian
12import scipy.special
13import ffgrid2
14import map_ffgrid
15from matplotlib import colors
16
17
18
19def distance_on_unit_sphere(lat1, lon1, lat2, lon2):
20
21    # Convert latitude and longitude to
22    # spherical coordinates in radians.
23    degrees_to_radians = math.pi/180.0
24       
25    # phi = 90 - latitude
26    phi1 = (90.0 - lat1) * degrees_to_radians
27    phi2 = (90.0 - lat2) * degrees_to_radians
28       
29    # theta = longitude
30    theta1 = lon1 * degrees_to_radians
31    theta2 = lon2 * degrees_to_radians
32       
33    # Compute spherical distance from spherical coordinates.
34       
35    # For two locations in spherical coordinates
36    # (1, theta, phi) and (1, theta, phi)
37    # cosine( arc length ) =
38    #    sin phi sin phi' cos(theta-theta') + cos phi cos phi'
39    # distance = rho * arc length
40   
41    cos = (math.sin(phi1) * math.sin(phi2) * math.cos(theta1 - theta2) + 
42           math.cos(phi1) * math.cos(phi2))
43    arc = math.acos( cos )
44
45    # Remember to multiply arc by the radius of the earth
46    # in your favorite set of units to get length.
47    return arc
48
49
Note: See TracBrowser for help on using the repository browser.