Skip to content

Commit

Permalink
update omegapy to v2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
AStcherbinine committed Feb 15, 2021
1 parent e0ff04e commit 4452281
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 35 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![version](https://img.shields.io/badge/version-2.0-blue)
![version](https://img.shields.io/badge/version-2.1-blue)
![pythonversion](https://img.shields.io/badge/Python-3.7-blue)

# OMEGA-Py : Python tools for OMEGA data
Expand Down Expand Up @@ -57,4 +57,4 @@ See [`docs/*.md`](docs/) or the interactive IPython help for more details.
## Credits
Developped at the Institut d'Astrophysique Spatiale (IAS), Université Paris-Saclay, Orsay, France

© Aurélien Stcherbinine (2020)
© Aurélien Stcherbinine (2020–2021)
44 changes: 25 additions & 19 deletions omegapy/omega_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## omega_data.py
## Created by Aurélien STCHERBININE
## Last modified by Aurélien STCHERBININE : 15/10/2020
## Last modified by Aurélien STCHERBININE : 15/02/2021

##----------------------------------------------------------------------------------------
"""Importation and correction of OMEGA/MEx observations from binaries files.
Expand Down Expand Up @@ -34,7 +34,7 @@

# Name of the current file
_py_file = 'omega_data.py'
_Version = 2.0
_Version = 2.1

# Path of the package files
package_path = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -263,7 +263,7 @@ def _readomega(cube_id, disp=True, corrV=True, corrL=True):
Parameters
==========
cube_id : str
The observation ID (format XXXX_X).
The observation ID (format ORBXXXX_X).
disp : bool, optional (default True)
Enable or disable the display of informations during the file reading.
| True -> Enable display.
Expand All @@ -285,7 +285,8 @@ def _readomega(cube_id, disp=True, corrV=True, corrL=True):
nomfic0 = cube_id + '.QUB'
nomfic = os.path.join(_omega_bin_path, nomfic0)
nomgeo = os.path.join(_omega_bin_path, nomgeo0)
print('\n\033[1mComputing OMEGA observation {0:s}\033[0m'.format(cube_id))
if disp:
print('\n\033[1mComputing OMEGA observation {0:s}\033[0m'.format(cube_id))
# Orbit number in base 10
orbnum = int.from_bytes(str.encode(nomfic0[3]), byteorder='big') - 48
if orbnum > 9:
Expand Down Expand Up @@ -730,6 +731,9 @@ class OMEGAdata:
If True, compute the correction on the visible channel (Vis).
corrL : bool, optional (default True)
If True, compute the correction on the long-IR channel (L).
disp : bool, optional (default True)
Enable or disable the display of informations during the file reading.
| True -> Enable display.
Attributes
==========
Expand Down Expand Up @@ -831,16 +835,16 @@ class OMEGAdata:
| False -> No atmospheric correction.
atm_corr_infos : dict
Information about the atmospheric correction (date, method).
version : float
The version of the omegapy.omega_data.py file used.
version : int
The major release version of the omegapy.omega_data.py file used.
add_infos : str
Additional informations about the observation.
Show in the OMEGAdata representation.
"""

def __init__(self, obs='', empty=False, data_path=_omega_bin_path, corrV=True, corrL=True):
def __init__(self, obs='', empty=False, data_path=_omega_bin_path, corrV=True, corrL=True, disp=True):
# Infos
self.version = _Version
self.version = int(_Version)
self.therm_corr = False
self.atm_corr = False
self.therm_corr_infos = {'datetime': None, 'method': None}
Expand Down Expand Up @@ -903,9 +907,10 @@ def __init__(self, obs='', empty=False, data_path=_omega_bin_path, corrV=True, c
print("\033[1;33mAborted\033[0m")
return None
nomfic0 = obs_name[obs_name.rfind('/')+1:-4] # Récupération nom + décodage UTF-8
data_dict, geom_dict = _readomega(nomfic0, disp=True, corrV=corrV, corrL=corrL)
data_dict, geom_dict = _readomega(nomfic0, disp=disp, corrV=corrV, corrL=corrL)

print("\n\033[01;34mComputing data extraction and correction...\033[0m", end=' ')
if disp:
print("\n\033[01;34mComputing data extraction and correction...\033[0m", end=' ')
# Extract values
ldat = data_dict['ldat']
jdat = data_dict['jdat']
Expand Down Expand Up @@ -1046,7 +1051,8 @@ def __init__(self, obs='', empty=False, data_path=_omega_bin_path, corrV=True, c
self.add_infos = corrupted_orbits_comments[i_obs]
#--------------------------
# End of data extraction & correction
print("\033[01;32m[done]\033[0m")
if disp:
print("\033[01;32m[done]\033[0m")


def __copy__(self):
Expand Down Expand Up @@ -1565,7 +1571,7 @@ def autoload_omega(obs_name, folder='auto', version=_Version, base_folder=_omega
The observation ID.
folder : str, optional (default 'auto')
The subfolder where the data is.
| If 'auto' -> folder = 'vX.X', where X.X is the given value of code version.
| If 'auto' -> folder = 'vX', where X is the major release version of the used code.
version : float, optional (default _Version)
The version of the target file (if folder is 'auto').
base_folder : str, optional (default _omega_py_path)
Expand Down Expand Up @@ -1600,7 +1606,7 @@ def autoload_omega(obs_name, folder='auto', version=_Version, base_folder=_omega
excl.append('atm')
filename = '*{name}*{corr_ext}*.pkl'.format(name=obs_name, corr_ext=ext)
if folder == 'auto':
folder = 'v' + str(version)
folder = 'v' + str(int(version))
filename2 = uf.myglob(os.path.join(base_folder, folder, filename), exclude=excl)
if filename2 is None:
if (therm_corr in [None, False]) and (atm_corr in [None, False]):
Expand Down Expand Up @@ -2083,7 +2089,7 @@ def corr_save_omega(obsname, folder='auto', base_folder=_omega_py_path, security
The name of the OMEGA observation.
folder : str, optional (default 'auto')
The subfolder to save the data.
| If 'auto' -> folder = 'vX.X', where X.X is the OMEGAdata version.
| If 'auto' -> folder = 'vX', where X is the major release version of the used code.
base_folder : str, optional (default _omega_py_path)
The base folder path.
security : bool, optional (default True)
Expand All @@ -2100,7 +2106,7 @@ def corr_save_omega(obsname, folder='auto', base_folder=_omega_py_path, security
Number of parallelized worker process to use.
"""
if folder == 'auto':
folder = 'v' + str(_Version)
folder = 'v' + str(int(_Version))
omega = OMEGAdata(obsname)
name = omega.name
# path synthax
Expand Down Expand Up @@ -2138,7 +2144,7 @@ def corr_save_omega_list(liste_obs, folder='auto', base_folder=_omega_py_path,
The list of the name of the OMEGA observations.
folder : str, optional (default 'auto')
The subfolder to save the data.
| If 'auto' -> folder = 'vX.X', where X.X is the Version of the current code.
| If 'auto' -> folder = 'vX', where X is the major release version of the used code.
base_folder : str, optional (default _omega_py_path)
The base folder path.
security : bool, optional (default True)
Expand All @@ -2156,7 +2162,7 @@ def corr_save_omega_list(liste_obs, folder='auto', base_folder=_omega_py_path,
"""
N = len(liste_obs)
if folder == 'auto':
folder = 'v' + str(_Version)
folder = 'v' + str(int(_Version))
for i, obsname in enumerate(liste_obs):
print('\n\033[01mComputing observation {0} / {1} : {2}\033[0m\n'.format(i+1, N, obsname))
corr_save_omega(obsname, folder, base_folder, security, overwrite, compress, npool)
Expand Down Expand Up @@ -2280,7 +2286,7 @@ def update_cube_quality(obs_name='ORB*.pkl', folder='auto', version=_Version,
The files basename.
folder : str, optional (default 'auto')
The subfolder where the data is.
| If 'auto' -> folder = 'vX.X', where X.X is the given value of code version.
| If 'auto' -> folder = 'vX', where X is the major release version of the used code.
version : float, optional (default _Version)
The version of the target file (if folder is 'auto').
Default is the current code version.
Expand All @@ -2291,7 +2297,7 @@ def update_cube_quality(obs_name='ORB*.pkl', folder='auto', version=_Version,
if obs_name[-4] != '.pkl':
obs_name += '.pkl'
if folder == 'auto':
folder = 'v' + str(version)
folder = 'v' + str(int(version))
basename = uf.myglob(os.path.join(base_folder, folder, obs_name))
# Load list corrupted obs
OBC = readsav(os.path.join(package_path, 'OMEGA_dataref', 'OBC_OMEGA_OCT2017.sav'))
Expand Down
35 changes: 24 additions & 11 deletions omegapy/omega_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## omega_plots.py
## Created by Aurélien STCHERBININE
## Last modified by Aurélien STCHERBININE : 07/10/2020
## Last modified by Aurélien STCHERBININE : 15/02/2021

##----------------------------------------------------------------------------------------
"""Display of OMEGAdata cubes.
Expand Down Expand Up @@ -846,7 +846,7 @@ def show_data_v2(omega, data, cmap='viridis', vmin=None, vmax=None, alpha=None,
##----------------------------------------------------------------------------------------
## Projection grille
def proj_grid(omega, data, lat_min=-90, lat_max=90, lon_min=0, lon_max=360,
pas_lat=0.1, pas_lon=0.1):
pas_lat=0.1, pas_lon=0.1, negative_values=False):
"""Sample the data from the input OMEGA/MEx observation on a given lat/lon grid.
Parameters
Expand All @@ -868,6 +868,8 @@ def proj_grid(omega, data, lat_min=-90, lat_max=90, lon_min=0, lon_max=360,
The latitude intervals of the grid.
pas_lon : float, optional (default 0.1)
The longitude intervals of the grid.
negative_values : bool, optional (default False)
Set if the negative values are considered as relevant data or not.
Returns
=======
Expand Down Expand Up @@ -897,9 +899,15 @@ def proj_grid(omega, data, lat_min=-90, lat_max=90, lon_min=0, lon_max=360,
i_lon = int(longi/pas_lon - lon_min/pas_lon)
j_lat = int(lati/pas_lat - lat_min/pas_lat)
data_tmp = data[i,j]
if (not np.isnan(data_tmp)) & (data_tmp > 0): # Filtrage régions sans données
grid_data[i_lon,j_lat] += data_tmp
mask[i_lon,j_lat] += 1
# if (not np.isnan(data_tmp)) & (data_tmp > 0): # Filtrage régions sans données
if negative_values:
if (not np.isnan(data_tmp)) & (not np.isinf(data_tmp)): # Filtrage régions sans données
grid_data[i_lon,j_lat] += data_tmp
mask[i_lon,j_lat] += 1
else: # negative values = No data
if (not np.isnan(data_tmp)) & (data_tmp > 0) & (not np.isinf(data_tmp)): # Filtrage régions sans données
grid_data[i_lon,j_lat] += data_tmp
mask[i_lon,j_lat] += 1
grid_data[grid_data==0] = np.nan
grid_data2 = grid_data / mask # Normalisation
mask2 = np.clip(mask, 0, 1)
Expand Down Expand Up @@ -952,8 +960,8 @@ def check_list_mask_omega(omega_list, mask_list, disp=True):
def show_omega_list_v2(omega_list, lam=1.085, lat_min=-90, lat_max=90, lon_min=0, lon_max=360,
pas_lat=0.1, pas_lon=0.1, cmap='Greys_r', vmin=None, vmax=None,
title='auto', Nfig=None, polar=False, cbar=True, cb_title='auto',
data_list=None, mask_list=None, plot=True, grid=True, out=False,
negatives_longitudes=False, **kwargs):
data_list=None, mask_list=None, negative_values=False, plot=True,
grid=True, out=False, negatives_longitudes=False, **kwargs):
"""Display an composite map from a list OMEGA/MEx observations, sampled on a new lat/lon grid.
Parameters
Expand Down Expand Up @@ -998,6 +1006,8 @@ def show_omega_list_v2(omega_list, lam=1.085, lat_min=-90, lat_max=90, lon_min=0
corrupted pixels of each observaiton, in the **same order** than the observations of
`omega_list`.
Each mask is a 2D array, filled with 1 for good pixels and NaN for bad ones.
negative_values : bool, optional (default False)
Set if the negative values are considered as relevant data or not.
plot : bool, optional (default True)
If True -> Diplay the final figure.
grid : bool, optional (default True)
Expand Down Expand Up @@ -1042,7 +1052,7 @@ def show_omega_list_v2(omega_list, lam=1.085, lat_min=-90, lat_max=90, lon_min=0
else:
data_tmp = omega.cube_rf[:,:,i_lam] * mask_list[i] # Reflectance with mask
data0, mask0 = proj_grid(omega, data_tmp, lat_min, lat_max,
lon_min, lon_max, pas_lat, pas_lon)[:2]
lon_min, lon_max, pas_lat, pas_lon, negative_values)[:2]
data += np.nan_to_num(data0) # Conversion NaN -> 0 pour somme des images
mask += mask0
mask_obs[mask0 == 1] += (omega.name + ',')
Expand All @@ -1054,7 +1064,7 @@ def show_omega_list_v2(omega_list, lam=1.085, lat_min=-90, lat_max=90, lon_min=0
else:
data_tmp = data_list[i] * mask_list[i] # Data with mask
data0, mask0 = proj_grid(omega, data_tmp, lat_min, lat_max,
lon_min, lon_max, pas_lat, pas_lon)[:2]
lon_min, lon_max, pas_lat, pas_lon, negative_values)[:2]
data += np.nan_to_num(data0) # Conversion NaN -> 0 pour somme des images
mask += mask0
mask_obs[mask0 == 1] += (omega.name + ',')
Expand Down Expand Up @@ -1136,7 +1146,7 @@ def show_omega_list_v2(omega_list, lam=1.085, lat_min=-90, lat_max=90, lon_min=0
## Sauvegarde résultats
def save_map_omega_list(omega_list, lat_min=-90, lat_max=90, lon_min=0, lon_max=360,
pas_lat=0.1, pas_lon=0.1, lam=1.085, data_list=None, data_desc='',
mask_list=None, sav_filename='auto', ext='',
mask_list=None, negative_values=False, sav_filename='auto', ext='',
base_folder='../data/OMEGA/sav_map_list_v2/', sub_folder=''):
"""Save the output of the omega_plots.show_omega_list_v2() function with the requested
parameters as a dictionary.
Expand Down Expand Up @@ -1169,6 +1179,8 @@ def save_map_omega_list(omega_list, lat_min=-90, lat_max=90, lon_min=0, lon_max=
corrupted pixels of each observaiton, in the **same order** than the observations of
`omega_list`.
Each mask is a 2D array, filled with 1 for good pixels and NaN for bad ones.
negative_values : bool, optional (default False)
Set if the negative values are considered as relevant data or not.
sav_filename : str, optional (default 'auto')
The saving file name.
| If 'auto' -> Automatically generated.
Expand All @@ -1193,7 +1205,8 @@ def save_map_omega_list(omega_list, lat_min=-90, lat_max=90, lon_min=0, lon_max=
# Compute the data sampling
data, mask, grid_lat, grid_lon, mask_obs = show_omega_list_v2(omega_list,
lam, lat_min, lat_max, lon_min, lon_max, pas_lat, pas_lon,
data_list=data_list, mask_list=mask_list, plot=False, out=True)
data_list=data_list, mask_list=mask_list, negative_values=negative_values,
plot=False, out=True)
# Sav file
input_params = {
'omega_list' : od.get_names(omega_list),
Expand Down
4 changes: 2 additions & 2 deletions omegapy/useful_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## useful_functions.py
## Created by Aurélien STCHERBININE
## Last modified by Aurélien STCHERBININE : 06/10/2020
## Last modified by Aurélien STCHERBININE : 15/02/2021

##-----------------------------------------------------------------------------------
"""Useful generics functions.
Expand Down Expand Up @@ -239,7 +239,7 @@ def where_closer(value, array):
The index of the closer value to value in array.
"""
array2 = np.abs(array - value)
i_closer = np.where(array2 == array2.min())[0][0]
i_closer = np.where(array2 == np.nanmin(array2))[0][0]
return i_closer

def where_closer_array(values, array):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setuptools.setup(
name='omegapy',
version='2.0.1',
version='2.1',
author='Aurélien Stcherbinine',
author_email='[email protected]',
description='Python tools for OMEGA/MEx observations analysis',
Expand Down

0 comments on commit 4452281

Please sign in to comment.