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

分割地域7-10次メッシュの対応 #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# jismesh

地域メッシュコードに関するユーティリティです
地域メッシュコード [JISX0410:2002](https://www.jisc.go.jp/app/jis/general/GnrJISNumberNameSearchList?show&jisStdNo=X0410) に関するユーティリティです

## 対応地域メッシュコード
- 1次(標準地域メッシュ 80km四方): 1
Expand All @@ -17,7 +17,16 @@
- 4次(分割地域メッシュ 500m四方): 4
- 5次(分割地域メッシュ 250m四方): 5
- 6次(分割地域メッシュ 125m四方): 6
- 7次(62.5m四方)*: 7
- 8次(31.25m四方)*: 8
- 9次(15.625m四方)*: 9
- 10次(7.8125m四方)*: 10


\* 7次以降は [JISX0410:2002](https://www.jisc.go.jp/app/jis/general/GnrJISNumberNameSearchList?show&jisStdNo=X0410) の規定外ですが、実務上のニーズに応えるため本ユーティリティでは取り扱い可能としています。
それらの次数を使用した場合は、`JismeshNonstandardWarning`の警告が表示されます。


## インストール
```bash
pip install jismesh
Expand Down
36 changes: 31 additions & 5 deletions jismesh/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from __future__ import absolute_import

import numpy as _np
import warnings
from . import _vector
from . import _scalar

class JismeshNonstandardWarning(Warning):
pass

def unit_lat(level):
warn_if_nonstandard(level)
if _np.isscalar(level):
unit_lat = _scalar.unit_lat
else:
Expand All @@ -13,6 +18,7 @@ def unit_lat(level):
return unit_lat(level)

def unit_lon(level):
warn_if_nonstandard(level)
if _np.isscalar(level):
unit_lon = _scalar.unit_lon
else:
Expand All @@ -21,7 +27,7 @@ def unit_lon(level):
return unit_lon(level)

def to_meshcode(lat, lon, level, astype=_np.int64):
warn_if_nonstandard(level)
if _np.isscalar(lat) and _np.isscalar(lon) and _np.isscalar(level):
to_meshcode = _scalar.to_meshcode
else:
Expand All @@ -35,20 +41,27 @@ def to_meshlevel(meshcode):
else:
to_meshlevel = _vector.to_meshlevel

return to_meshlevel(meshcode)
meshlevel = to_meshlevel(meshcode)
warn_if_nonstandard(meshlevel)
return meshlevel

def to_meshpoint(meshcode, lat_multiplier, lon_multiplier):
if _np.isscalar(meshcode) and _np.isscalar(lat_multiplier) and _np.isscalar(lon_multiplier):
to_meshpoint = _scalar.to_meshpoint
else:
to_meshpoint = _vector.to_meshpoint


to_meshlevel(meshcode) # for JismeshNonstandardWarning

return to_meshpoint(meshcode, lat_multiplier, lon_multiplier)

def to_envelope(meshcode_sw, meshcode_ne):
assert _np.isscalar(meshcode_sw)
assert _np.isscalar(meshcode_sw)
assert type(meshcode_sw) == type(meshcode_ne)

to_meshlevel(meshcode_sw) # for JismeshNonstandardWarning
to_meshlevel(meshcode_ne) # for JismeshNonstandardWarning

to_envelope = _scalar.to_envelope

Expand All @@ -57,8 +70,21 @@ def to_envelope(meshcode_sw, meshcode_ne):
def to_intersects(meshcode, to_level):
assert _np.isscalar(meshcode)
assert _np.isscalar(to_level)


warn_if_nonstandard(to_level)

to_intersects = _scalar.to_intersects

return to_intersects(meshcode, to_level)


def is_nonstandard(level):
if _np.isscalar(level):
is_nonstandard = _scalar.is_nonstandard
else:
is_nonstandard = _vector.is_nonstandard

return is_nonstandard(level)

def warn_if_nonstandard(level):
if is_nonstandard(level):
warnings.warn("Levels 7, 8, 9, and 10 are not standard levels.", JismeshNonstandardWarning, stacklevel=3)
Loading