diff --git a/README.md b/README.md index c8ebd68..e86260b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) diff --git a/omegapy/omega_data.py b/omegapy/omega_data.py index 591cecf..6092b74 100644 --- a/omegapy/omega_data.py +++ b/omegapy/omega_data.py @@ -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. @@ -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__)) @@ -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. @@ -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: @@ -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 ========== @@ -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} @@ -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'] @@ -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): @@ -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) @@ -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]): @@ -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) @@ -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 @@ -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) @@ -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) @@ -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. @@ -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')) diff --git a/omegapy/omega_plots.py b/omegapy/omega_plots.py index 04222b7..0ff88fd 100644 --- a/omegapy/omega_plots.py +++ b/omegapy/omega_plots.py @@ -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. @@ -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 @@ -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 ======= @@ -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) @@ -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 @@ -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) @@ -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 + ',') @@ -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 + ',') @@ -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. @@ -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. @@ -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), diff --git a/omegapy/useful_functions.py b/omegapy/useful_functions.py index ca76b8e..2af2d3f 100644 --- a/omegapy/useful_functions.py +++ b/omegapy/useful_functions.py @@ -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. @@ -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): diff --git a/setup.py b/setup.py index 5144a40..bc236d5 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setuptools.setup( name='omegapy', - version='2.0.1', + version='2.1', author='Aurélien Stcherbinine', author_email='aurelien.stcherbinine@ias.u-psud.fr', description='Python tools for OMEGA/MEx observations analysis',