Skip to content

Commit

Permalink
Merge branch 'feat-step4-intg' of https://github.com/brown-ccv/icesat…
Browse files Browse the repository at this point in the history
…2-tracks into feat-step4-intg
  • Loading branch information
kmilo9999 committed Jan 15, 2024
2 parents 29a3fcf + f6e1580 commit 7319992
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 125 deletions.
31 changes: 12 additions & 19 deletions src/icesat2_tracks/analysis_db/A02c_IOWAGA_thredds_prior.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import os, sys

from icesat2_tracks.config.IceSAT2_startup import (
mconfig,
xr,
color_schemes,
plt,
font_for_print,
np,
)
import sys
import datetime

import h5py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_for_print
from matplotlib.gridspec import GridSpec
import xarray as xr
from siphon.catalog import TDSCatalog

from icesat2_tracks.config.IceSAT2_startup import mconfig
import icesat2_tracks.ICEsat2_SI_tools.io as io
import icesat2_tracks.ICEsat2_SI_tools.wave_tools as waves
import icesat2_tracks.local_modules.m_tools_ph3 as MT
import icesat2_tracks.local_modules.m_general_ph3 as M

from siphon.catalog import TDSCatalog

import pandas as pd

import datetime
from matplotlib.gridspec import GridSpec
from icesat2_tracks.config.IceSAT2_startup import color_schemes

color_schemes.colormaps2(21)

Expand Down Expand Up @@ -425,8 +420,6 @@ def test_nan_frac(imask):
except:
target_name = "A02_" + track_name + "_hindcast_fail"


# %%
def plot_prior(Prior, axx):
angle = Prior["incident_angle"][
"value"
Expand Down
29 changes: 8 additions & 21 deletions src/icesat2_tracks/analysis_db/B01_SL_load_single_file.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
#
"""
This file open a ICEsat2 tbeam_stats.pyrack applied filters and corections and returns smoothed photon heights on a regular grid in an .nc file.
This is python 3.11
"""
import os, sys
import sys
import datetime
import copy

import xarray as xr
from sliderule import sliderule, icesat2

from icesat2_tracks.config.IceSAT2_startup import (
mconfig,
xr,
color_schemes,
font_for_pres,
plt,
)

import geopandas as gpd

from sliderule import sliderule, icesat2, earthdata

import shapely
from ipyleaflet import basemaps, Map, GeoData

import icesat2_tracks.ICEsat2_SI_tools.sliderule_converter_tools as sct
import icesat2_tracks.ICEsat2_SI_tools.io as io
import icesat2_tracks.ICEsat2_SI_tools.beam_stats as beam_stats
import icesat2_tracks.local_modules.m_tools_ph3 as MT
from icesat2_tracks.local_modules import m_general_ph3 as M


import h5py, imp, copy
import datetime


xr.set_options(display_style="text")


Expand All @@ -39,7 +31,6 @@
sys.argv
) # loads standard experiment

# 20190502052058_05180312_005_01
plot_flag = True
hemis = batch_key.split("_")[0]

Expand Down Expand Up @@ -118,8 +109,6 @@


# main routine for defining the x coordinate and sacing table data


def make_B01_dict(table_data, split_by_beam=True, to_hdf5=False):
"""
converts a GeoDataFrame from Sliderule to GeoDataFrames for each beam witht the correct columns and names
Expand Down Expand Up @@ -166,7 +155,7 @@ def make_B01_dict(table_data, split_by_beam=True, to_hdf5=False):

# define reference point and then define 'x'
table_data = copy.copy(gdf)
imp.reload(sct)

# the reference point is defined as the most equatorward point of the polygon.
# It's distance from the equator is subtracted from the distance of each photon.
table_data = sct.define_x_coordinate_from_data(table_data)
Expand All @@ -181,7 +170,6 @@ def make_B01_dict(table_data, split_by_beam=True, to_hdf5=False):
Ti[kk]["heights_c_weighted_mean"] = Ti[kk]["h_mean"].copy()
Ti[kk]["heights_c_std"] = Ti[kk]["h_sigma"].copy()


segment = track_name.split("_")[1][-2:]
ID_name = sct.create_ID_name(gdf.iloc[0], segment=segment)
print(ID_name)
Expand All @@ -203,7 +191,6 @@ def make_B01_dict(table_data, split_by_beam=True, to_hdf5=False):
F_atl06.save_light(path=plot_path, name="B01b_ATL06_corrected.png")
plt.close()

imp.reload(beam_stats)
if plot_flag:
font_for_pres()
F = M.figure_axis_xy(8, 4.3, view_scale=0.6)
Expand Down
43 changes: 19 additions & 24 deletions src/icesat2_tracks/analysis_db/B02_make_spectra_gFT.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
import sys


"""
This file open a ICEsat2 track applied filters and corections and returns smoothed photon heights on a regular grid in an .nc file.
This is python 3
"""

from icesat2_tracks.config.IceSAT2_startup import mconfig, xr, plt, np

import copy
import datetime
import h5py
import time
import sys

from threadpoolctl import threadpool_info, threadpool_limits
import numpy as np
import xarray as xr
from pprint import pprint
from scipy.ndimage.measurements import label
from threadpoolctl import threadpool_info, threadpool_limits


import h5py
import icesat2_tracks.ICEsat2_SI_tools.generalized_FT as gFT
import icesat2_tracks.ICEsat2_SI_tools.io as io
import icesat2_tracks.ICEsat2_SI_tools.spectral_estimates as spec

import time
import imp
import copy
from icesat2_tracks.local_modules.m_spectrum_ph3 import spicke_remover
import datetime
import icesat2_tracks.ICEsat2_SI_tools.generalized_FT as gFT
from scipy.ndimage.measurements import label
import icesat2_tracks.local_modules.m_general_ph3 as M
import icesat2_tracks.local_modules.m_spectrum_ph3 as spicke_remover
import icesat2_tracks.local_modules.m_tools_ph3 as MT
from icesat2_tracks.local_modules import m_general_ph3 as M
from icesat2_tracks.config.IceSAT2_startup import mconfig, plt

import tracemalloc

Expand Down Expand Up @@ -99,7 +95,7 @@ def linear_gap_fill(F, key_lead, key_int):
Ib = Gd[group[1]]
ratio = Ia["x"][:].size / Ib["x"][:].size
if (ratio > 10) | (ratio < 0.1):
print("bad data ratio ", ratio, 1 / ratio)
# print("bad data ratio ", ratio, 1 / ratio) # TODO: add logger
bad_ratio_flag = True

if (np.array(nan_fraction).mean() > 0.95) | bad_ratio_flag:
Expand All @@ -118,7 +114,6 @@ def linear_gap_fill(F, key_lead, key_int):
exit()

# test LS with an even grid where missing values are set to 0
imp.reload(spec)
print(Gd.keys())
Gi = Gd[list(Gd.keys())[0]] # to select a test beam
dist = io.get_beam_var_hdf_store(Gd[list(Gd.keys())[0]], "dist")
Expand Down Expand Up @@ -153,10 +148,10 @@ def linear_gap_fill(F, key_lead, key_int):
print("define global xlims")
dist_list = np.array([np.nan, np.nan])
for k in all_beams:
print(k)
# print(k) # TODO: add logger
hkey = "heights_c_weighted_mean"
x = Gd[k + "/dist"][:]
print(x[0], x[-1])
# print(x[0], x[-1]) # TODO: add logger
dist_list = np.vstack([dist_list, [x[0], x[-1]]])

xlims = np.nanmin(dist_list[:, 0]) - dx, np.nanmin(dist_list[:, 1])
Expand All @@ -172,7 +167,7 @@ def linear_gap_fill(F, key_lead, key_int):
for k in all_beams:
dist_i = io.get_beam_var_hdf_store(Gd[k], "dist")
x_mask = (dist_i > xlims[0]) & (dist_i < xlims[1])
print(k, sum(x_mask["dist"]) / (xlims[1] - xlims[0]))
# print(k, sum(x_mask["dist"]) / (xlims[1] - xlims[0])) # TODO: add logger


print("-reduced frequency resolution")
Expand All @@ -199,7 +194,7 @@ def linear_gap_fill(F, key_lead, key_int):
Gi = io.get_beam_hdf_store(Gd[k])
x_mask = (Gi["dist"] > xlims[0]) & (Gi["dist"] < xlims[1])
if sum(x_mask) / (xlims[1] - xlims[0]) < 0.005:
print("------------------- not data in beam found; skip")
# print("------------------- not data in beam found; skip") # TODO: add logger
continue

Gd_cut = Gi[x_mask]
Expand All @@ -219,7 +214,7 @@ def linear_gap_fill(F, key_lead, key_int):

# compute slope spectra !!
dd = np.gradient(dd)
dd, _ = spicke_remover(dd, spreed=10, verbose=False)
dd, _ = spicke_remover.spicke_remover(dd, spreed=10, verbose=False)
dd_nans = (np.isnan(dd)) + (Gd_cut["N_photos"] <= 5)

# using gappy data
Expand Down
28 changes: 7 additions & 21 deletions src/icesat2_tracks/analysis_db/B03_plot_spectra_ov.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,31 @@
This is python 3
"""
import sys

from icesat2_tracks.config.IceSAT2_startup import (
mconfig,
xr,
color_schemes,
plt,
np,
font_for_print,
)

import icesat2_tracks.ICEsat2_SI_tools.io as io
import icesat2_tracks.ICEsat2_SI_tools.spectral_estimates as spec

import time
import numpy as np
import xarray as xr
from matplotlib.gridspec import GridSpec
import icesat2_tracks.ICEsat2_SI_tools.io as io
import icesat2_tracks.ICEsat2_SI_tools.generalized_FT as gFT
from scipy.ndimage.measurements import label
import icesat2_tracks.local_modules.m_tools_ph3 as MT
from icesat2_tracks.local_modules import m_general_ph3 as M

from icesat2_tracks.config.IceSAT2_startup import mconfig, color_schemes, plt, font_for_print

track_name, batch_key, test_flag = io.init_from_input(
sys.argv
sys.argv # TODO: Handle via CLI
) # loads standard experiment
hemis, batch = batch_key.split("_")

load_path = mconfig["paths"]["work"] + batch_key + "/B02_spectra/"
load_file = load_path + "B02_" + track_name # + '.nc'
load_file = load_path + "B02_" + track_name
plot_path = (
mconfig["paths"]["plot"] + "/" + hemis + "/" + batch_key + "/" + track_name + "/"
)
) # TODO: Update with pathlib
MT.mkdirs_r(plot_path)

Gk = xr.open_dataset(load_file + "_gFT_k.nc")
Gx = xr.open_dataset(load_file + "_gFT_x.nc")

Gfft = xr.open_dataset(load_file + "_FFT.nc")
time.sleep(2)


all_beams = mconfig["beams"]["all_beams"]
high_beams = mconfig["beams"]["high_beams"]
Expand Down
47 changes: 7 additions & 40 deletions src/icesat2_tracks/config/IceSAT2_startup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
import os
import pathlib
###
# THIS FILE IS A LOCAL FILE
# it is not maintained via git, it contains configs specific to the machine
###
import string

#os.environ["DISPLAY"] = "localhost:10.0"
# 14, 16, work
#standart libraries:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

import matplotlib.colors as colors
import pandas as pd
from icesat2_tracks.local_modules import m_colormanager_ph3 as M_color
from icesat2_tracks.local_modules import m_tools_ph3 as MT
from icesat2_tracks.local_modules import m_general_ph3 as M

import string

import xarray as xr

## Read folders and configuration paths
config_dir_path = os.path.dirname(__file__)
Expand All @@ -37,12 +22,10 @@
#load colorscheme
color_schemes=M_color.color(path=mconfig['paths']['config'], name='color_def')


lstrings =iter([i+') ' for i in list(string.ascii_lowercase)])
# define journal fig sizes
fig_sizes = mconfig['fig_sizes']['AMS']


SMALL_SIZE = 8
MEDIUM_SIZE = 10
BIGGER_SIZE = 12
Expand All @@ -52,11 +35,11 @@
plt.rc('font', size=SMALL_SIZE, serif='Helvetica Neue', weight='normal') # controls default text sizes
plt.rc('text', usetex='false')
plt.rc('axes', titlesize=MEDIUM_SIZE, labelweight='normal') # fontsize of the axes title
plt.rc('axes', labelsize=SMALL_SIZE, labelweight='normal') #, family='bold') # fontsize of the x and y labels
plt.rc('axes', labelsize=SMALL_SIZE, labelweight='normal') # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE, frameon=False) # legend fontsize
plt.rc('figure', titlesize=MEDIUM_SIZE, titleweight='bold', autolayout=True) #, family='bold') # fontsize of the figure title
plt.rc('figure', titlesize=MEDIUM_SIZE, titleweight='bold', autolayout=True) # fontsize of the figure title
plt.rc('path', simplify=True)
plt.rcParams['figure.figsize'] = (10, 8)
plt.rcParams['pcolor.shading'] = 'auto'
Expand All @@ -66,15 +49,7 @@
plt.rc('axes', labelsize= MEDIUM_SIZE, labelweight='normal')
plt.rc('axes.spines', top= False, right=False )



def font_for_print():

SMALL_SIZE = 6
MEDIUM_SIZE = 8
BIGGER_SIZE = 10 # not used. CP
legend_properties = {'weight':'bold'} # not used. CP

def font_for_print(SMALL_SIZE = 6, MEDIUM_SIZE = 8):
plt.rc('font', size=SMALL_SIZE, serif='Helvetica Neue', weight='normal') # controls default text sizes
plt.rc('text', usetex='false')
plt.rc('axes', titlesize=MEDIUM_SIZE, labelweight='normal') # fontsize of the axes title
Expand All @@ -85,21 +60,13 @@ def font_for_print():
plt.rc('figure', titlesize=MEDIUM_SIZE, titleweight='bold', autolayout=True) #, family='bold') # fontsize of the figure title
plt.rc('axes', labelsize= SMALL_SIZE, labelweight='normal')

def font_for_pres():

SMALL_SIZE = 10
MEDIUM_SIZE = 12
BIGGER_SIZE = 14 # not used. CP
legend_properties = {'weight':'bold'} # not used. CP


plt.rc('font', size=SMALL_SIZE, serif='Helvetica Neue', weight='normal') # controls default text sizes
def font_for_pres(SMALL_SIZE = 10, MEDIUM_SIZE = 12):
plt.rc('font', size=SMALL_SIZE, serif='Helvetica Neue', weight='normal') # controls default text sizes
plt.rc('text', usetex='false')
plt.rc('axes', titlesize=MEDIUM_SIZE, labelweight='normal') # fontsize of the axes title
plt.rc('axes', labelsize=SMALL_SIZE, labelweight='normal') #, family='bold') # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE, frameon=False) # legend fontsize
plt.rc('figure', titlesize=MEDIUM_SIZE, titleweight='bold', autolayout=True) #, family='bold') # fontsize of the figure title

plt.rc('figure', titlesize=MEDIUM_SIZE, titleweight='bold', autolayout=True) # fontsize of the figure title
plt.rc('axes', labelsize= SMALL_SIZE, labelweight='normal')

0 comments on commit 7319992

Please sign in to comment.