minor bug fixes

This commit is contained in:
Chunxiao Li 2020-07-27 10:38:52 +08:00
parent ae64508a1e
commit a1a723020b
11 changed files with 56 additions and 75 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -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

BIN
pyatmos/.DS_Store vendored

Binary file not shown.

View File

@ -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.
'''

View File

@ -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

View File

@ -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 ========================== #

View File

@ -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

16
pyatmos/utils/__init__.py Normal file
View File

@ -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.
'''

View File

@ -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()

21
pyatmos/utils/utils.py Normal file
View File

@ -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

View File

@ -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'),