From 13793e108e4b7e28b85875b825b3c4ee720c94f0 Mon Sep 17 00:00:00 2001 From: toddn Date: Tue, 10 Oct 2023 16:28:28 -0500 Subject: [PATCH] cleaning up docker file --- preview.netcdf/Dockerfile | 4 -- preview.netcdf/extractor_info.json | 8 +++ preview.netcdf/ncsa.geo.netcdf.extractor.py | 2 + preview.netcdf/netcdfutils.py | 46 ++++++++++++------ preview.netcdf/netcdfutils_ASJP.py | 54 --------------------- 5 files changed, 40 insertions(+), 74 deletions(-) delete mode 100644 preview.netcdf/netcdfutils_ASJP.py diff --git a/preview.netcdf/Dockerfile b/preview.netcdf/Dockerfile index 832bca5..4496ecf 100644 --- a/preview.netcdf/Dockerfile +++ b/preview.netcdf/Dockerfile @@ -1,9 +1,5 @@ FROM ubuntu:20.04 -ARG VERSION="unknown" -ARG BUILDNUMBER="unknown" -ARG GITSHA1="unknown" - RUN apt-get update &&\ DEBIAN_FRONTEND=noninteractive apt-get install -y \ python3 \ diff --git a/preview.netcdf/extractor_info.json b/preview.netcdf/extractor_info.json index 118222b..039714e 100644 --- a/preview.netcdf/extractor_info.json +++ b/preview.netcdf/extractor_info.json @@ -31,6 +31,14 @@ ], "dependencies": [], "bibtex": [], + "parameters": { + "schema": { + "directory": { + "type": "string", + "title": "projection" + } + } + }, "labels": [ "Type/Image", "Domain/Geo" diff --git a/preview.netcdf/ncsa.geo.netcdf.extractor.py b/preview.netcdf/ncsa.geo.netcdf.extractor.py index b097c27..9e41faf 100644 --- a/preview.netcdf/ncsa.geo.netcdf.extractor.py +++ b/preview.netcdf/ncsa.geo.netcdf.extractor.py @@ -4,6 +4,7 @@ import logging import subprocess +import json import pyclowder from pyclowder.extractors import Extractor import pyclowder.files @@ -44,6 +45,7 @@ def process_message(self, connector, host, secret_key, resource, parameters, pro # Process the file and upload the results logger = logging.getLogger(__name__) + params = json.loads(parameters['parameters']) inputfile = resource["local_paths"][0] file_id = resource['id'] diff --git a/preview.netcdf/netcdfutils.py b/preview.netcdf/netcdfutils.py index 1266702..c3e14f6 100644 --- a/preview.netcdf/netcdfutils.py +++ b/preview.netcdf/netcdfutils.py @@ -9,12 +9,16 @@ plt.rcParams['figure.figsize'] = (16.0, 12.0) # -# sample_file_1 = 'ASJP_Year_2023_Day_218.nc4' -# sample_file_2 = 'soilw.mon.1991-2020.ltm.v2.nc' -# path_to_file = os.path.join(os.getcwd(), sample_file_2) +sample_file_1 = 'ASJP_Year_2023_Day_218.nc4' +sample_file_2 = 'soilw.mon.1991-2020.ltm.v2.nc' +sample_file_3 = 'air.2x2.250.mon.1991-2020.ltm.comb.nc' +sample_file_4 = 'air.mon.mean.nc' +sample_file_5 = 'adaptor.mars.internal-1696624738.5653653-18904-2-b0069ad2-7c40-4404-acd9-d7cf76870e2a.nc' +sample_file_6 = 'adaptor.mars.internal-1696625608.8176327-14431-17-11b1bdd3-05c6-42ee-b9d4-dee178830ba1.nc' +path_to_file = os.path.join(os.getcwd(), sample_file_1) # -# print(os.path.exists(path_to_file)) -# print('exists?') +print(os.path.exists(path_to_file)) +print('exists?') @@ -78,15 +82,22 @@ def generate_maps_for_file(path_to_file, projection='merc'): units = current_variable.units except Exception as e: print("no units") - non_matching_index = [] + not_lat_lon_indices = [] current_variable_shape = current_variable.shape current_variable_shape_list = list(current_variable_shape) for i in range(0, len(current_variable_shape_list)): if current_variable.shape[i] not in lat_lon_shape_values: - non_matching_index.append(i) + not_lat_lon_indices.append(i) + print('what does this variable have') variable_data = current_variable[:] - if len(non_matching_index) == 1: - non_matching_shape_size = current_variable.shape[non_matching_index[0]] + if len(not_lat_lon_indices) == 2: + print('it is more than one') + print('we need to find the time variable') + for index in not_lat_lon_indices: + value = current_variable[:][index] + print('value') + if len(not_lat_lon_indices) == 1: + non_matching_shape_size = current_variable.shape[not_lat_lon_indices[0]] quarter_time = int(np.floor(non_matching_shape_size / 4)) # with time series data, we will show quarterly previews @@ -106,8 +117,8 @@ def generate_maps_for_file(path_to_file, projection='merc'): squeezed_data = np.squeeze(current_time_variable_data) max = np.nanmax(squeezed_data) min = np.nanmin(squeezed_data) - if min > 0: - min = 0 + # if min > 0: + # min = 0 cs2 = m2.pcolor(xi, yi, squeezed_data) m2.drawcoastlines() m2.drawcountries() @@ -119,14 +130,14 @@ def generate_maps_for_file(path_to_file, projection='merc'): title = long_name if units: title = title + '('+str(units)+')' - plt.title(title) + plt.title(title , fontdict={'fontsize': 26}) plot_name = long_name + str(i) + '_' + str(non_matching_shape_size) + '.png' plt.savefig(plot_name) previews_returned.append(plot_name) plt.clf() # if it is NOT time series data - if len(non_matching_index) == 0: + if len(not_lat_lon_indices) == 0: m2 = Basemap(projection='merc', llcrnrlat=-80, urcrnrlat=80, llcrnrlon=-180, urcrnrlon=180, lat_ts=20, resolution='c') # if we need to use a meshgrid for 1 dimensional lat and lon @@ -138,8 +149,8 @@ def generate_maps_for_file(path_to_file, projection='merc'): squeezed_data = np.squeeze(variable_data) max = np.nanmax(squeezed_data) min = np.nanmin(squeezed_data) - if min > 0: - min = 0 + # if min > 0: + # min = 0 cs2 = m2.pcolor(xi, yi, squeezed_data) m2.drawcoastlines() m2.drawcountries() @@ -152,4 +163,7 @@ def generate_maps_for_file(path_to_file, projection='merc'): plt.savefig(plot_name) previews_returned.append(plot_name) plt.clf() - return previews_returned \ No newline at end of file + return previews_returned + +if __name__ == "__main__": + generate_maps_for_file(path_to_file=path_to_file) \ No newline at end of file diff --git a/preview.netcdf/netcdfutils_ASJP.py b/preview.netcdf/netcdfutils_ASJP.py deleted file mode 100644 index 2da3c65..0000000 --- a/preview.netcdf/netcdfutils_ASJP.py +++ /dev/null @@ -1,54 +0,0 @@ -import os -import netCDF4 as nc -import sys -from netCDF4 import Dataset as Dataset -import matplotlib.pyplot as plt -import numpy as np -import mpl_toolkits -from mpl_toolkits.basemap import Basemap -plt.rcParams['figure.figsize'] = (16.0, 12.0) - - -sample_file = 'ASJP_Year_2023_Day_218.nc4' - -def generate_plots(current_filename, projection="Mercator"): - ds = Dataset(current_filename) - - variable_names = ds.variables.keys() - - lats = ds.variables['Latitude'][:] - lons = ds.variables['Longitude'][:] - - plt.clf() - for variable_name in variable_names: - try: - if 'Latitude' != variable_name and 'Longitude' != variable_name: - current_variable_values = ds[variable_name][:] - current_variable_data = current_variable_values.data - # if there is more than one array (this looks like an error with the original data) - if len(current_variable_data.shape) > 2: - current_variable_data = current_variable_data[0] - new_shape = current_variable_data.shape - if projection == 'Mercator': - m2 = Basemap(projection='merc', llcrnrlat=-80, urcrnrlat=80, - llcrnrlon=-180, urcrnrlon=180, lat_ts=20, resolution='c') - elif projection == 'Polar Stereographic': - m2 = Basemap(projection='npstere', boundinglat=10, lon_0=270, resolution='l') - - - xi, yi = m2(lons, lats) - squeezed_data = np.squeeze((current_variable_data)) - cs2 = m2.pcolor(xi, yi, np.squeeze(current_variable_data)) - - m2.drawcoastlines() - # m2.drawcountries() - m2.drawparallels(np.arange(-90., 91., 30.)) - m2.drawmeridians(np.arange(-180., 181., 60.)) - - plot_name = current_filename + '_' + variable_name + '.png' - plt.savefig(plot_name) - plt.clf() - except Exception as e: - print("Error with variable", variable_name) - -generate_plots(current_filename=sample_file) \ No newline at end of file