Skip to content

Commit

Permalink
Merge branch 'main' into tutorial_2023
Browse files Browse the repository at this point in the history
  • Loading branch information
falconstryker committed Nov 30, 2023
2 parents ae1ce89 + 4636186 commit abde8ff
Show file tree
Hide file tree
Showing 38 changed files with 7,823 additions and 5,436 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ CAP is a set of Python 3 libraries and command-line executables that streamline

Please check the [tutorial/](./tutorial/) directory for:

* detailed installation instructions for Linux, MacOS, Windows
* a lecture presenting the functionalities of the CAP
* a set of practice exercises to get familiar with CAP
* Detailed installation instructions for Linux, MacOS, Windows [Step-by-Step Installation](./tutorial/CAP_Install.md)
* A lecture presenting the functionalities of the CAP [Introduction to CAP and Documentation of its Functions](./tutorial/CAP_lecture.md)
* Two sets of practice exercises to get familiar with CAP for the [NASA Ames MGCM](./tutorial/CAP_Exercises.md) and the [Legacy GCM outputs](./tutorial/CAP_Exercises_2021.md)


The tutorial uses outputs from GCM simulations extensively documented in [Haberle et al. 2019](https://www.sciencedirect.com/science/article/pii/S0019103518305761)
The tutorial uses outputs from MGCM simulations extensively documented in [Haberle et al. 2019](https://www.sciencedirect.com/science/article/pii/S0019103518305761) and available for download on the [MCMC Data Portal](https://data.nas.nasa.gov/mcmc/index.html)
14 changes: 14 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
MarsPlot
============

Welcome to the Mars Climate Modeling Center (MCMC) **Community Analysis Pipeline (CAP)**.

**CAP** is a set of Python3 libraries and command-line executables that streamline downloading, processing, and plotting output from the NASA Ames Mars Global Climate Models: the NASA Ames Legacy Mars GCM and the NASA Ames Mars GCM.

Please see directory for:

* Installation instructions for Linux, MacOS, and Windows
* Documentation for CAP functions
* A set of exercises to get familiar with CAP

MGCM output is extensively documented in `Haberle et al. 2019 <https://www.sciencedirect.com/science/article/pii/S0019103518305761>`_.
2,310 changes: 1,256 additions & 1,054 deletions amescap/FV3_utils.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amescap/Ncdf_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,5 +782,5 @@ def _linInterpLs(self,Ls,stride=16):
Lsdi=np.append(Lsdi,2*Lsdi[-1]-Lsdi[-2])

for i in range(len(Ls)//stride):
Ls_out[i*stride:(i+1)*stride]=np.arange(0,stride)/np.float(stride)*(Lsdi[i+1]-Lsdi[i])+Lsdi[i]
Ls_out[i*stride:(i+1)*stride]=np.arange(0,stride)/np.float32(stride)*(Lsdi[i+1]-Lsdi[i])+Lsdi[i]
return Ls_out
45 changes: 29 additions & 16 deletions amescap/Script_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@


# The functions below allow to print in different color
def prRed(skk): print("\033[91m{}\033[00m".format(skk))
def prGreen(skk): print("\033[92m{}\033[00m".format(skk))
def prCyan(skk): print("\033[96m{}\033[00m".format(skk))
def prYellow(skk): print("\033[93m{}\033[00m".format(skk))
def prPurple(skk): print("\033[95m{}\033[00m".format(skk))
def prLightPurple(skk): print("\033[94m{}\033[00m".format(skk))
def prRed(input_txt):
print(f"\033[91m{input_txt}\033[00m")
def prGreen(input_txt):
print(f"\033[92m{input_txt}\033[00m")
def prCyan(input_txt):
print(f"\033[96m{input_txt}\033[00m")
def prYellow(input_txt):
print(f"\033[93m{input_txt}\033[00m")
def prPurple(input_txt):
print(f"\033[95m{input_txt}\033[00m")
def prLightPurple(input_txt):
print(f"\033[94m{input_txt}\033[00m")

Cyan = "\033[96m"
Blue = "\033[94m"
Yellow = "\033[93m"
NoColor = "\033[00m"
Red = "\033[91m"
Green = "\033[92m"
Purple = "\033[95m"

def MY_func(Ls_cont):
'''
Expand Down Expand Up @@ -51,10 +65,10 @@ def print_fileContent(fileNcdf):
None (print in the terminal)
'''
#Define Colors for printing
def Green(skk): return"\033[92m{}\033[00m".format(skk)
def Cyan(skk): return "\033[96m{}\033[00m".format(skk)
def Yellow(skk):return"\033[93m{}\033[00m".format(skk)
def Purple(skk):return"\033[95m{}\033[00m".format(skk)
def Green(input_txt): return"\033[92m{}\033[00m".format(input_txt)
def Cyan(input_txt): return "\033[96m{}\033[00m".format(input_txt)
def Yellow(input_txt):return"\033[93m{}\033[00m".format(input_txt)
def Purple(input_txt):return"\033[95m{}\033[00m".format(input_txt)
if not os.path.isfile(fileNcdf):
print(fileNcdf+' not found')
else:
Expand Down Expand Up @@ -104,8 +118,8 @@ def print_varContent(fileNcdf,list_varfull,print_stat=False):
None (print in the terminal)
'''
#Define Colors for printing
def Cyan(skk): return "\033[96m{}\033[00m".format(skk)
def Red(skk): return "\033[91m{}\033[00m".format(skk)
def Cyan(input_txt): return "\033[96m{}\033[00m".format(input_txt)
def Red(input_txt): return "\033[91m{}\033[00m".format(input_txt)
if not os.path.isfile(fileNcdf):
print(fileNcdf+' not found')
else:
Expand Down Expand Up @@ -259,7 +273,7 @@ def FV3_file_type(fNcdf):
fNcdf: an (open) Netcdf file object
Return:
f_type (string): 'fixed', 'contineous', or 'diurn'
interp_type (string): 'pfull','pstd','zstd','zagl','zgrid'
interp_type (string): 'pfull','pstd','zstd','zagl'
'''
#Get the full path from the file
fullpath=get_Ncdf_path(fNcdf)
Expand Down Expand Up @@ -289,7 +303,6 @@ def FV3_file_type(fNcdf):
if 'pstd' in dims: interp_type='pstd'
if 'zstd' in dims: interp_type='zstd'
if 'zagl' in dims: interp_type='zagl'
if 'zgrid' in dims: interp_type='zgrid'
return f_type,interp_type

def alt_FV3path(fullpaths,alt,test_exist=True):
Expand Down Expand Up @@ -539,7 +552,7 @@ def section_content_amescap_profile(section_ID):
'''
Execude code section in /home/user/.amescap_profile
Args:
section_ID: string defining the section to loa, e.g 'Pressure definitions for pstd'
section_ID: string defining the section to load, e.g 'Pressure definitions for pstd'
Returns
return line in that section as python code
'''
Expand Down Expand Up @@ -567,7 +580,7 @@ def section_content_amescap_profile(section_ID):
except FileNotFoundError:
prRed("Error: %s config file not found "%(input_file))
prYellow("To use this feature, create a hidden config file from the template in your home directory with:")
prCyan(" cp amesCAP/mars_templates/amescap_profile ~/.amescap_profile")
prCyan(" cp AmesCAP/mars_templates/amescap_profile ~/.amescap_profile")
exit()
except Exception as exception: #Return the error
prRed('Error')
Expand Down
4 changes: 2 additions & 2 deletions amescap/Spectral_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def diurn_extract(VAR,N,tod,lon):

#Reshape input variable VAR as a 2D array (tod,Nelements) for generalization

Ndim= np.int(np.prod(dimsIN[1:])) #Ndim is the product of all dimensions but the time of day axis, e.g. time x lat x lon
Ndim= int(np.prod(dimsIN[1:])) #Ndim is the product of all dimensions but the time of day axis, e.g. time x lat x lon
dimsFLAT=np.append([nsteps],[Ndim]) # Shape of flattened array
dimsOUT_flat=np.append([N],[Ndim]) # Shape of flattened array
VAR= VAR.reshape(dimsFLAT) #Flatten array to (tod,Nelements)
Expand Down Expand Up @@ -191,7 +191,7 @@ def space_time(lon,timex, varIN,kmx,tmx):
lon_id= dims[0] # lon
time_id= dims[-1] # time
dim_sup_id=dims[1:-1] #additional dimensions stacked in the middle
jd= np.int(np.prod( dim_sup_id)) #jd is the total number of dimensions in the middle is varIN>3D
jd= int(np.prod( dim_sup_id)) #jd is the total number of dimensions in the middle is varIN>3D

varIN= np.reshape(varIN, (lon_id, jd, time_id) ) #flatten the middle dimensions if any

Expand Down
65 changes: 65 additions & 0 deletions bin/MarsCalendar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python
from amescap.FV3_utils import sol2ls,ls2sol
from amescap.Script_utils import prYellow,prRed
import argparse #parsing arguments
import numpy as np


parser = argparse.ArgumentParser(description='Gives the solar longitude from a SOL or a SOL array (start stop, step), adapted from areols.py',
formatter_class=argparse.RawTextHelpFormatter)

parser.add_argument('sol', nargs='+',type=float,
help='''Input is sol number, return solar longitude \n'''
'''Usage: ./MarsCalendar.py 750. \n'''
''' ./MarsCalendar.py start stop step''')

parser.add_argument('-ls','--ls', action='store_true',
help="""Reverse operation. Inpout is Ls, output is sol \n"""
"""> Usage: ./MarsCalendar.py start stop step' -ls \n"""
""" \n""")


parser.add_argument('-my', nargs='+',type=float,default=0.,
help=''' Mars Year For ls>sol add 668 if my=1,1336 if my=2 etc.. \n'''
'''Usage: ./MarsCalendar.py 350 -ls -my 2 \n''')

parser.add_argument('-cum', action='store_true',
help='''For sol>ls return ls as cummulative 0>360>720... instead of [0-360] \n'''
'''Usage: ./MarsCalendar.py 670 -cum \n''')


if __name__ == '__main__':


#Load in Mars YEAR (if any, default is zero) and cummulative Ls
my=np.asarray(parser.parse_args().my).astype(float)
cum=False
if parser.parse_args().cum:cum=True

data_input=np.asarray(parser.parse_args().sol).astype(float)

if len(data_input)==1:
in_array=data_input
elif len(data_input)==3:
in_array=np.arange(data_input[0],data_input[1],data_input[2]) #start stop step
else:
prRed('Wrong number of arguments: enter [sol/ls] or [start stop step]')
exit()

#Requesting ls instead
if parser.parse_args().ls:
txt_multi=' Ls | Sol '
result=ls2sol(in_array)
else:
txt_multi=' SOL | Ls '
result=sol2ls(in_array,cummulative=cum)

#Is scalar, turn as float
if len(np.atleast_1d(result))==1:result=[result]
#Display data
print(txt_multi)
print('-----------------------')
for i in range(0,len(in_array)):
print(' %7.2f | %7.3f '%(in_array[i],result[i]+my*668.))


Loading

0 comments on commit abde8ff

Please sign in to comment.