Skip to content

Commit

Permalink
made all imports relative; package now works with pip install
Browse files Browse the repository at this point in the history
I finally have a reason to move away from the iPython environment, and so now all imports should be done properly
  • Loading branch information
ray-chew committed May 20, 2024
1 parent 4d1fa53 commit 78ee0b6
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*.json
*.bat
*.log

*.egg-info

/docs/build/*
.VSCodeCounter/*
Expand Down
8 changes: 5 additions & 3 deletions inputs/icon_regional_run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
from src import var, utils
from inputs import local_paths
from ..src import var, utils
from ..inputs import local_paths

params = var.params()

Expand All @@ -23,6 +23,8 @@

params.tri_set = [13, 104, 105, 106]

params.merit_cg = 20

# Setup the Fourier parameters and object.
params.nhi = 24
params.nhj = 48
Expand All @@ -34,7 +36,7 @@
params.rect = True

params.debug = False
params.dfft_first_guess = True
params.dfft_first_guess = False
params.refine = False
params.verbose = False

Expand Down
2 changes: 1 addition & 1 deletion inputs/local_paths_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src import var
from ..src import var

paths = var.obj()

Expand Down
27 changes: 27 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
[project]
name = "pyCSAM"
version = "0.95.1"

dependencies = [
"Cartopy==0.21.1",
"h5py==3.9.0",
"ipython==8.12.3",
"matplotlib==3.7.2",
"netCDF4==1.6.5",
"noise==1.2.2",
"numba==0.57.1",
"numpy==1.24.3",
"pandas==2.0.3",
"scikit_learn==1.3.0",
"scipy==1.12.0",
]

# Packaging
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
package-dir = {"pycsam" = ""}


[tool.towncrier]
directory = "changelog.d"
filename = "CHANGELOG.rst"
Expand Down
40 changes: 26 additions & 14 deletions src/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
from datetime import datetime

from src import utils
from ..src import utils


class ncdata(object):
Expand Down Expand Up @@ -570,40 +570,52 @@ def __init__(self, params):

rootgrp = nc.Dataset(self.path + self.fn, "w", format="NETCDF4")

for key, value in vars(params).items():

# if params attribute is None but check passed, then the attribute is not necessary for the run; skip it
if value is None:
continue
# NetCDF does not accept Boolean types; convert to int
if type(value) is bool:
value = int(value)
# Else, write attribute
setattr(rootgrp, key, value)

_ = rootgrp.createDimension("nspec", params.n_modes)

self.n_modes = params.n_modes
rootgrp.close()

def output(self, id, clat, clon, analysis):
def output(self, id, clat, clon, is_land, analysis=None):

rootgrp = nc.Dataset(self.path + self.fn, "a", format="NETCDF4")

grp = rootgrp.createGroup(str(id))

is_land_var = grp.createVariable("is_land","i4")
is_land_var[:] = 1
is_land_var[:] = is_land

clat_var = grp.createVariable("clat","f8")
clat_var[:] = clat
clon_var = grp.createVariable("clon","f8")
clon_var[:] = clon

dk_var = grp.createVariable("dk","f8")
dk_var[:] = analysis.dk
dl_var = grp.createVariable("dl","f8")
dl_var[:] = analysis.dl
if analysis is not None:
dk_var = grp.createVariable("dk","f8")
dk_var[:] = analysis.dk
dl_var = grp.createVariable("dl","f8")
dl_var[:] = analysis.dl

pick_idx = np.where(analysis.ampls > 0)
pick_idx = np.where(analysis.ampls > 0)

H_spec_var = grp.createVariable("H_spec","f8", ("nspec",))
H_spec_var[:] = self.__pad_zeros(analysis.ampls[pick_idx], self.n_modes)
H_spec_var = grp.createVariable("H_spec","f8", ("nspec",))
H_spec_var[:] = self.__pad_zeros(analysis.ampls[pick_idx], self.n_modes)

kks_var = grp.createVariable("kks","f8", ("nspec",))
kks_var[:] = self.__pad_zeros(analysis.kks[pick_idx], self.n_modes)
kks_var = grp.createVariable("kks","f8", ("nspec",))
kks_var[:] = self.__pad_zeros(analysis.kks[pick_idx], self.n_modes)

lls_var = grp.createVariable("lls","f8", ("nspec",))
lls_var[:] = self.__pad_zeros(analysis.lls[pick_idx], self.n_modes)
lls_var = grp.createVariable("lls","f8", ("nspec",))
lls_var[:] = self.__pad_zeros(analysis.lls[pick_idx], self.n_modes)

rootgrp.close()

Expand Down
14 changes: 13 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,4 +818,16 @@ def transfer_attributes(params, cls, prefix=""):
if not hasattr(params, key):
setattr(params, key, value)
elif getattr(params, key) == None:
setattr(params, key, value)
setattr(params, key, value)


def is_land(cell, simplex_lat, simplex_lon, topo, height_tol=0.5, percent_tol=0.95):

get_lat_lon_segments(
simplex_lat, simplex_lon, cell, topo, load_topo=True, filtered=False
)

if not (((cell.topo <= height_tol).sum() / cell.topo.size) > percent_tol):
return False
else:
return True
2 changes: 1 addition & 1 deletion src/var.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import numpy as np
from src import utils, io
from ..src import utils, io


class grid(object):
Expand Down
4 changes: 2 additions & 2 deletions wrappers/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""


from src import fourier, lin_reg, physics, reconstruction
from src import utils, var
from ..src import fourier, lin_reg, physics, reconstruction
from ..src import utils, var
from copy import deepcopy
import numpy as np

Expand Down

0 comments on commit 78ee0b6

Please sign in to comment.