From e68db742c53cc82883c69facb2c2fb618dc9f9a7 Mon Sep 17 00:00:00 2001 From: Carlotta Date: Mon, 23 Jun 2025 13:22:07 +0200 Subject: [PATCH 1/3] Variable months removed from plot_2D_observations and plot_2D_num_obs --- mapies/mapies.py | 23 +++++++++++------------ run/run_viirs.py | 8 ++++---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/mapies/mapies.py b/mapies/mapies.py index 7bde689c..1be32cca 100644 --- a/mapies/mapies.py +++ b/mapies/mapies.py @@ -515,7 +515,6 @@ class MAPIES: @logger.catch def plot_2D_observations( self, - months: List[int] = [0], filename: str = None, outdir: str = None ): @@ -523,7 +522,7 @@ class MAPIES: Mapies main plotting function for 2d surface obs """ - if months == [0]: + if hasattr(self, "obs"): try: lon_values = self.lon lat_values = self.lat @@ -543,7 +542,7 @@ class MAPIES: filename=filename, ) return - elif months == [1]: + elif hasattr(self, "avg_results") and len(self.avg_results) > 0: for i, (date, lon_values, lat_values, obs_values, count_obs) in enumerate(self.avg_results): # if obs_values is None or len(obs_values) == 0: # continue @@ -561,15 +560,15 @@ class MAPIES: title=title, filename=filename, ) + return else: - logger.error("Error: months can be either [0] for all data, [1] for averages by frequency.") + logger.error("Nothing to plot: neither full observations nor frequency-averaged results are available.") return def plot_2D_num_obs( - self, - months: List[int] = [0], + self, filename: str = None, outdir: str = None ): @@ -577,7 +576,7 @@ class MAPIES: Mapies main plotting function for observation counts at the surface """ - if months == [0]: + if hasattr(self, "obs"): try: lon_values = self.lon lat_values = self.lat @@ -586,7 +585,7 @@ class MAPIES: logger.error(f"Error plotting all data: {e}") return title = f"Plot of the number of valid observations from {self.start_date} to {self.end_date}" - filename = f"{self.datatype}_2D_obs_count_from_{self.start_date}_to_{self.end_date}.png" + filename = filename or f"{self.datatype}_2D_obs_count_from_{self.start_date}_to_{self.end_date}.png" self.plotter.plot_2D_num_obs_custom( lon_values=lon_values, lat_values=lat_values, @@ -597,11 +596,11 @@ class MAPIES: ) return - elif months == [1]: + elif hasattr(self, "avg_results") and len(self.avg_results) > 0: for i, (date, lon_values, lat_values, obs_values, count_obs) in enumerate(self.avg_results): date_obj = datetime.strptime(date, "%Y%m%d%H%M") title = f"Plot of the number of valid observations - {date_obj}, average {i}" - filename = filename or f"{self.datatype}_2D_obs_count_from_{self.start_date}_to_{self.end_date}_{date}_average_{i}.png" + filename = f"{self.datatype}_2D_obs_count_from_{self.start_date}_to_{self.end_date}_{date}_average_{i}.png" self.plotter.plot_2D_num_obs_custom( lon_values=lon_values, lat_values=lat_values, @@ -610,9 +609,9 @@ class MAPIES: title=title, filename=filename, ) - + return else: - logger.error("Error: months can be either [0] for all data, [1] for averages by frequency.") + logger.error("Nothing to plot: neither full observations nor frequency-averaged results are available.") return @staticmethod diff --git a/run/run_viirs.py b/run/run_viirs.py index 3bfbea60..b81bb58b 100644 --- a/run/run_viirs.py +++ b/run/run_viirs.py @@ -11,7 +11,7 @@ if __name__ == "__main__": - outdir="/home/cgile/Documents/mapies/figures/averages/11062025" + outdir="/home/cgile/Documents/mapies/figures/averages/23062025" indir="/home/cgile/Documents/mapies/VIIRS" @@ -28,12 +28,12 @@ if __name__ == "__main__": min_num_obs = 0 - c.process_avg_data(frequency_avg=frequency_avg, min_num_obs = min_num_obs, batch_size = 100, save=True, save_format = "gridded", apply_qa = False, geospatial_crop = geospatial_crop) + c.process_avg_data(frequency_avg=None, min_num_obs = min_num_obs, batch_size = 100, save=False, save_format = "gridded", apply_qa = False, geospatial_crop = geospatial_crop) # c.plot_2D_observations(months=[0], filename="plot_10062025.png", outdir=outdir) # c.plot_2D_observations(months=[1], outdir=outdir) - - c.plot_2D_num_obs(months=[1], outdir=outdir) + c.plot_2D_observations(filename='Trial1', outdir=outdir) + c.plot_2D_num_obs(filename='Trial1_count', outdir=outdir) # c.process_lazy_data(apply_qa=True, save=True) -- GitLab From 27fa8c86d42326f4d20f208f5e673c74c0791976 Mon Sep 17 00:00:00 2001 From: Carlotta Date: Mon, 23 Jun 2025 15:46:56 +0200 Subject: [PATCH 2/3] Chenges in names of the plots --- mapies/mapies.py | 16 ++++++++++++---- run/run_viirs.py | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/mapies/mapies.py b/mapies/mapies.py index 1be32cca..ccc60c57 100644 --- a/mapies/mapies.py +++ b/mapies/mapies.py @@ -531,7 +531,9 @@ class MAPIES: logger.error(f"Error plotting all data: {e}") return title = f"Observation 2D plot from {self.start_date} to {self.end_date}" - filename = filename or f"{self.datatype}_2D_obs_from_{self.start_date}_to_{self.end_date}.png" + start_date_obj = self.start_date.strftime("%Y%m%d%H%M") + end_date_obj = self.end_date.strftime("%Y%m%d%H%M") + filename = filename or f"{self.datatype}_2D_obs_from_{start_date_obj}_to_{end_date_obj}.png" self.plotter.plot_2D_obs_custom( lon_values=lon_values, lat_values=lat_values, @@ -549,7 +551,9 @@ class MAPIES: logger.debug(f"Plotting date: {date}, average {i}") date_obj = datetime.strptime(date, "%Y%m%d%H%M") title = f"Observation 2D plot - {date_obj}, average {i}" - filename = f"{self.datatype}_2D_obs_from_{self.start_date}_to_{self.end_date}_{date}_average_{i}.png" + start_date_obj = self.start_date.strftime("%Y%m%d%H%M") + end_date_obj = self.end_date.strftime("%Y%m%d%H%M") + filename = f"{self.datatype}_2D_obs_from_{start_date_obj}_to_{end_date_obj}_{date}_average_{i}.png" self.plotter.plot_2D_obs_custom( lon_values=lon_values, @@ -585,7 +589,9 @@ class MAPIES: logger.error(f"Error plotting all data: {e}") return title = f"Plot of the number of valid observations from {self.start_date} to {self.end_date}" - filename = filename or f"{self.datatype}_2D_obs_count_from_{self.start_date}_to_{self.end_date}.png" + start_date_obj = self.start_date.strftime("%Y%m%d%H%M") + end_date_obj = self.end_date.strftime("%Y%m%d%H%M") + filename = filename or f"{self.datatype}_2D_obs_count_from_{start_date_obj}_to_{end_date_obj}.png" self.plotter.plot_2D_num_obs_custom( lon_values=lon_values, lat_values=lat_values, @@ -600,7 +606,9 @@ class MAPIES: for i, (date, lon_values, lat_values, obs_values, count_obs) in enumerate(self.avg_results): date_obj = datetime.strptime(date, "%Y%m%d%H%M") title = f"Plot of the number of valid observations - {date_obj}, average {i}" - filename = f"{self.datatype}_2D_obs_count_from_{self.start_date}_to_{self.end_date}_{date}_average_{i}.png" + start_date_obj = self.start_date.strftime("%Y%m%d%H%M") + end_date_obj = self.end_date.strftime("%Y%m%d%H%M") + filename = f"{self.datatype}_2D_obs_count_from_{start_date_obj}_to_{end_date_obj}_{date}_average_{i}.png" self.plotter.plot_2D_num_obs_custom( lon_values=lon_values, lat_values=lat_values, diff --git a/run/run_viirs.py b/run/run_viirs.py index b81bb58b..e70aa270 100644 --- a/run/run_viirs.py +++ b/run/run_viirs.py @@ -28,7 +28,7 @@ if __name__ == "__main__": min_num_obs = 0 - c.process_avg_data(frequency_avg=None, min_num_obs = min_num_obs, batch_size = 100, save=False, save_format = "gridded", apply_qa = False, geospatial_crop = geospatial_crop) + c.process_avg_data(frequency_avg=frequency_avg, min_num_obs = min_num_obs, batch_size = 100, save=False, save_format = "gridded", apply_qa = False, geospatial_crop = geospatial_crop) # c.plot_2D_observations(months=[0], filename="plot_10062025.png", outdir=outdir) # c.plot_2D_observations(months=[1], outdir=outdir) -- GitLab From a3ff68d38a621e3a6266b5b07003b1fc54fb04c2 Mon Sep 17 00:00:00 2001 From: Carlotta Date: Mon, 23 Jun 2025 15:52:26 +0200 Subject: [PATCH 3/3] Updateted CHANGELOG and setup.py files --- CHANGELOG | 7 +++++++ setup.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 3006f6c7..be9f9a01 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,11 @@ CHANGELOG +## 0.1.4 - 2025/06/23 - Frequency by average and gridded format + +### Features +- Data can be saved in a "gridded" format inside the netCDF files, so that it can be easily read and opened in ncview or Panoply +- Number of observations are added in the netCDF +- Average by frequency implementation +- Naming convention for plots updated ## 0.1.3 - 2025/03/07 - Logging implemented diff --git a/setup.py b/setup.py index 68f1e785..a1499a10 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ from setuptools import find_packages from setuptools import setup # Could update this using versioneer -version="0.1.3" +version="0.1.4" setup( name="mapies", -- GitLab