diff --git a/.DS_Store b/.DS_Store index dae0805..c5b5c73 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/README.md b/README.md index d8ba997..b658df6 100755 --- a/README.md +++ b/README.md @@ -114,6 +114,8 @@ Calculate the temperatures, densities including anomalous oxygen using the NRLMS ``` ## Change log +- **1.1.2 — Jul 26, 2020** + - Added progress bar for downloading data - **1.1.0 — Mar 29, 2020** - Added the International Standard Atmosphere(ISA) Model up to 86km diff --git a/pyatmos/.DS_Store b/pyatmos/.DS_Store index fd0e248..279bd60 100644 Binary files a/pyatmos/.DS_Store and b/pyatmos/.DS_Store differ diff --git a/pyatmos/StandardAtmosphere/__init__.py b/pyatmos/StandardAtmosphere/__init__.py index b136d90..4483aa1 100644 --- a/pyatmos/StandardAtmosphere/__init__.py +++ b/pyatmos/StandardAtmosphere/__init__.py @@ -3,11 +3,9 @@ pyatmos StandardAtmosphere subpackage This subpackage defines the following functions: -# =================== Standard Atmosphere Model================= # +# StandardAtmosphere.py isa - Implements the International Standard Atmosphere(ISA) Model up to 86km. -# ===================== utility functions ==================== # - lapse_tp - Calculate the temperature and pressure at a given geopotential altitude above base of a specific layer. ''' \ No newline at end of file diff --git a/pyatmos/msise/__init__.py b/pyatmos/msise/__init__.py index 8577228..05dd1c9 100644 --- a/pyatmos/msise/__init__.py +++ b/pyatmos/msise/__init__.py @@ -3,25 +3,15 @@ pyatmos msise subpackage This subpackage defines the following functions: -# ==================== nrlmisise-00 model =================== # +# nrlmsise00.py - Implements the NRLMSISE 00 model -nrlmsise00 - Implements the NRLMSISE 00 model - -# =================== spaceweather functions ================= # +# spaceweather.py download_sw - Download or update the space weather file from www.celestrak.com -read_sw - Read the space weather file +read_sw - Read the space weather file -get_sw - Extract the space weather data - -# ===================== utility functions ==================== # - -wraplon - Wrap a longitude in range of [0,360] to [-180,180] - -hms2s - Convert hour/minute/second to seconds - -hms2h - Convert hour/minute/second to hours +get_sw - Extract the space weather data ''' from .spaceweather import download_sw,read_sw \ No newline at end of file diff --git a/pyatmos/msise/nrlmsise00.py b/pyatmos/msise/nrlmsise00.py index 4d2e1ed..b2c49b2 100644 --- a/pyatmos/msise/nrlmsise00.py +++ b/pyatmos/msise/nrlmsise00.py @@ -55,7 +55,7 @@ from pyshtools.legendre import PLegendreA,PlmIndex import pkg_resources from .spaceweather import get_sw -from .utils import wraplon,hms2s,hms2h +from ..utils.utils import wraplon,hms2s,hms2h # ======================== read data block ========================== # diff --git a/pyatmos/msise/spaceweather.py b/pyatmos/msise/spaceweather.py index 9b4e810..8eaa2c5 100644 --- a/pyatmos/msise/spaceweather.py +++ b/pyatmos/msise/spaceweather.py @@ -1,26 +1,9 @@ -# -------------------------------------------------------------------- # -# ------------------------ space weather --------------------------- # -# -------------------------------------------------------------------- # - -''' -pyatmos spaceweather - -This submodule defines the following functions: - -download_sw - Download or update the space weather file from www.celestrak.com - -read_sw - Read the space weather file - -get_sw - Extract the space weather data -''' - import numpy as np from datetime import datetime,timedelta from os import path,makedirs,remove from pathlib import Path -from urllib.request import urlretrieve -# =================== download and update sw data =================== # +from ..utils.try_download import tqdm_request def download_sw(direc=None): ''' @@ -69,8 +52,6 @@ def download_sw(direc=None): print('The space weather data in {:s} is already the latest.'.format(direc)) return swfile -# =========================== read sw file ========================== # - def read_sw(swfile): ''' Parse and read the space weather file @@ -122,11 +103,12 @@ def read_sw(swfile): SW_OBS_PRE = np.vstack((np.array(SW_OBS),np.array(SW_PRE))) # inverse sort SW_OBS_PRE = np.flip(SW_OBS_PRE,0) - return SW_OBS_PRE - -# ========================== extract sw data ========================== # + return SW_OBS_PRE def get_sw(SW_OBS_PRE,t_ymd,hour): + ''' + Extract space weather data + ''' j = 0 for ymd in SW_OBS_PRE[:,:3]: if np.array_equal(t_ymd,ymd): break diff --git a/pyatmos/utils/__init__.py b/pyatmos/utils/__init__.py new file mode 100644 index 0000000..e7b3ecf --- /dev/null +++ b/pyatmos/utils/__init__.py @@ -0,0 +1,16 @@ +''' +pyatmos utils subpackage + +This subpackage defines the following functions: + +# try_download.py + +wraplon - Wrap a longitude in range of [0,360] to [-180,180] + +hms2s - Convert hour/minute/second to seconds + +hms2h - Convert hour/minute/second to hours + +tqdm_request - Try to download files from a remote server by request. + +''' \ No newline at end of file diff --git a/pyatmos/msise/utils.py b/pyatmos/utils/try_download.py similarity index 54% rename from pyatmos/msise/utils.py rename to pyatmos/utils/try_download.py index e1e0d6f..7d436bc 100644 --- a/pyatmos/msise/utils.py +++ b/pyatmos/utils/try_download.py @@ -1,40 +1,11 @@ import requests from tqdm import tqdm from colorama import Fore -# ------------------------------------------------------------------- # -# ----------------------------- utilities --------------------------- # -# ------------------------------------------------------------------- # - -''' -pyatmos utils - -This submodule defines the following functions: - -wraplon - Wrap a longitude in range of [0,360] to [-180,180] - -hms2s - Convert hour/minute/second to seconds - -hms2h - Convert hour/minute/second to hours -''' - -# ========================= convert position ======================== # - -def wraplon(lon): - if lon > 180: - lonwrap = lon - 360 - else: - lonwrap = lon - return lonwrap - -# =========================== convert time ========================== # - -def hms2s(h,m,s): - return h*3.6E3 + m*60 + s - -def hms2h(h,m,s): - return h + m/60 + s/3.6E3 def tqdm_request(url,dir_to,file,desc): + ''' + Try to download files from a remote server by request. + ''' block_size = 1024 bar_format = "{l_bar}%s{bar}%s{r_bar}" % (Fore.BLUE, Fore.RESET) for idownload in range(5): @@ -56,5 +27,6 @@ def tqdm_request(url,dir_to,file,desc): print('No response, skip this file.') finally: pbar.close() - local_file.close() + local_file.close() + res.close() diff --git a/pyatmos/utils/utils.py b/pyatmos/utils/utils.py new file mode 100644 index 0000000..74ef998 --- /dev/null +++ b/pyatmos/utils/utils.py @@ -0,0 +1,21 @@ +def wraplon(lon): + ''' + Wrap a longitude in range of [0,360] to [-180,180] + ''' + if lon > 180: + lonwrap = lon - 360 + else: + lonwrap = lon + return lonwrap + +def hms2s(h,m,s): + ''' + Convert hour/minute/second to seconds + ''' + return h*3.6E3 + m*60 + s + +def hms2h(h,m,s): + ''' + Convert hour/minute/second to hours + ''' + return h + m/60 + s/3.6E3 \ No newline at end of file diff --git a/setup.py b/setup.py index df7cfb4..44cc27a 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup( name='pyatmos', - version='1.1.1', + version='1.1.2', long_description_content_type='text/markdown', description='A package to estimate the atmosphere parameters', long_description=open('README.md', 'rb').read().decode('utf-8'),