Skip to content

Commit

Permalink
Remove legacy modules
Browse files Browse the repository at this point in the history
  • Loading branch information
pnsaevik committed Mar 18, 2024
1 parent 67df85f commit 0ac2f38
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 1,544 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.
- New grid and forcing module should have a clearer separation. Grid should
take care of coordinate system changes, while forcing should return static
fields.
### Add
- Multiplicity to the releaser module


## [Unreleased] - 2024-xx-xx
### Changed
- Legacy modules are removed


## [1.3.5] - 2024-01-30
### Added
Expand Down
72 changes: 68 additions & 4 deletions ladim/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
parameters, appending default values and converting between
different versions of config file formats.
"""
import numpy as np


def configure(module_conf):
Expand Down Expand Up @@ -32,8 +33,71 @@ def _versioned_configure(config_dict):
return config_dict


def _convert_1_to_2(config_dict):
from .legacy.configuration import configure as legacy_configure
config_dict = legacy_configure(config_dict)
config_dict['version'] = 2
def _convert_1_to_2(c):
# Read timedelta
dt_value, dt_unit = c['numerics']['dt']

# Read output variables
outvars = dict()
outvar_names = c['output_variables'].get('particle', []) + c['output_variables'].get('instance', [])
for v in outvar_names:
outvars[v] = c['output_variables'][v].copy()
for v in c['output_variables'].get('particle', []):
outvars[v]['kind'] = 'initial'
if 'release_time' in outvars and 'units' in outvars['release_time']:
outvars['release_time']['units'] = 'seconds since 1970-01-01'

# Read release variables
relvars = dict(
file=c['files']['particle_release_file'],
frequency=c['particle_release'].get('release_frequency', [0, 's']),
colnames=c['particle_release']['variables'],
formats={
c['particle_release'][v]: v
for v in c['particle_release']['variables']
if v in c['particle_release'].keys()
},
)
if c['particle_release'].get('release_type', '') != 'continuous':
del relvars['frequency']

# Read ibm vars
ibmvars = c.get('ibm', dict()).copy()
if 'ibm_module' in ibmvars:
ibmvars['module'] = ibmvars['ibm_module']
del ibmvars['ibm_module']

config_dict = dict(
version=2,
solver=dict(
start=c['time_control']['start_time'],
stop=c['time_control']['stop_time'],
step=np.timedelta64(dt_value, dt_unit).astype('int64'),
seed=c['numerics'].get('seed', None),
order=['release', 'forcing', 'output', 'tracker', 'ibm', 'state'],
),
grid=dict(
file=c['gridforce']['input_file'],
legacy_module=c['gridforce']['module'] + '.Grid',
start_time=c['time_control']['start_time'],
),
forcing=dict(
file=c['gridforce']['input_file'],
legacy_module=c['gridforce']['module'] + '.Forcing',
start_time=c['time_control']['start_time'],
stop_time=c['time_control']['stop_time'],
dt=np.timedelta64(dt_value, dt_unit).astype('int64'),
),
release=relvars,
output=dict(
file=c['files']['output_file'],
frequency=c['output_variables']['outper'],
variables=outvars,
),
tracker=dict(
method=c['numerics']['advection'],
diffusion=c['numerics']['diffusion'],
),
ibm=ibmvars,
)
return config_dict
7 changes: 4 additions & 3 deletions ladim/forcing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ class RomsForcing(Forcing):
def __init__(self, model: Model, **conf):
super().__init__(model)

from ladim.gridforce.ROMS import Forcing as LegacyForcing

grid_ref = GridReference(model)
legacy_conf = dict(
gridforce=dict(
input_file=conf['input_file'],
input_file=conf['file'],
),
ibm_forcing=conf.get('ibm_forcing', []),
start_time=conf.get('start_time', None),
stop_time=conf.get('stop_time', None),
dt=conf.get('dt', None),
)

from .model import load_class
LegacyForcing = load_class(conf.get('legacy_module', 'ladim.gridforce.ROMS.Forcing'))

# Allow gridforce module in current directory
import sys
import os
Expand Down
5 changes: 3 additions & 2 deletions ladim/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ def __init__(self, model: Model, **conf):

legacy_conf = dict(
gridforce=dict(
input_file=conf['dataset'],
input_file=conf['file'],
),
start_time=conf.get('start_time', None),
)

from ladim.gridforce.ROMS import Grid as LegacyGrid
from .model import load_class
LegacyGrid = load_class(conf.get('legacy_module', 'ladim.gridforce.ROMS.Grid'))

# Allow gridforce module in current directory
import sys
Expand Down
1 change: 0 additions & 1 deletion ladim/gridforce/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from ..legacy.gridforce import Grid, Forcing
Empty file removed ladim/legacy/__init__.py
Empty file.
Loading

0 comments on commit 0ac2f38

Please sign in to comment.