Skip to content

Commit

Permalink
Issue/374/introspection (#381)
Browse files Browse the repository at this point in the history
* added stages/__init__.py for introspection functions

* added os.path.expandvars to data

* updated stages/__init__.py

* tweek docstrings in src/rail/creation/degradation/observing_condition_degrader.py to avoid issues with sphinx

* fix up gitignore

* updated unit tests for rail.stages

* fix up coverages

* fix up stages

* updated introspection stuff

* added src/rail/core/introspection.py
  • Loading branch information
eacharles committed May 12, 2023
1 parent 142a156 commit 09739f6
Show file tree
Hide file tree
Showing 7 changed files with 440 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ __pycache__/

# Distribution / packaging
.Python
src/rail/core/_version.py
build/
develop-eggs/
dist/
Expand All @@ -28,6 +27,7 @@ wheels/
.installed.cfg
*.egg
MANIFEST
_version.py

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down Expand Up @@ -131,4 +131,4 @@ venv.bak/
# data for testing
/tests/data/
/examples/estimation/*.hdf5
/examples/estimation/*.pkl
/examples/estimation/*.pkl
5 changes: 5 additions & 0 deletions src/rail/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Core code for RAIL"""
import pkgutil
import setuptools
import rail
import os

def find_version():
"""Find the version"""
Expand All @@ -15,3 +19,4 @@ def find_version():
from .stage import RailPipeline, RailStage
from .utilPhotometry import PhotormetryManipulator, HyperbolicSmoothing, HyperbolicMagnitudes
from .utilStages import ColumnMapper, RowSelector, LSSTFluxToMagConverter, TableConverter, Dereddener
from .introspection import RailEnv
12 changes: 6 additions & 6 deletions src/rail/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def open(self, **kwargs):
"""
if self.path is None:
raise ValueError("DataHandle.open() called but path has not been specified")
self.fileObj = self._open(self.path, **kwargs)
self.fileObj = self._open(os.path.expandvars(self.path), **kwargs)
return self.fileObj

@classmethod
Expand All @@ -59,7 +59,7 @@ def read(self, force=False, **kwargs):
"""Read and return the data from the associated file """
if self.data is not None and not force:
return self.data
self.set_data(self._read(self.path, **kwargs))
self.set_data(self._read(os.path.expandvars(self.path), **kwargs))
return self.data

def __call__(self, **kwargs):
Expand All @@ -78,10 +78,10 @@ def write(self, **kwargs):
raise ValueError("TableHandle.write() called but path has not been specified")
if self.data is None:
raise ValueError(f"TableHandle.write() called for path {self.path} with no data")
outdir = os.path.dirname(os.path.abspath(self.path))
outdir = os.path.dirname(os.path.abspath(os.path.expandvars(self.path)))
if not os.path.exists(outdir): #pragma: no cover
os.makedirs(outdir, exist_ok=True)
return self._write(self.data, self.path, **kwargs)
return self._write(self.data, os.path.expandvars(self.path), **kwargs)

@classmethod
def _write(cls, data, path, **kwargs):
Expand All @@ -91,7 +91,7 @@ def initialize_write(self, data_lenght, **kwargs):
"""Initialize file to be written by chunks"""
if self.path is None: #pragma: no cover
raise ValueError("TableHandle.write() called but path has not been specified")
self.groups, self.fileObj = self._initialize_write(self.data, self.path, data_lenght, **kwargs)
self.groups, self.fileObj = self._initialize_write(self.data, os.path.expandvars(self.path), data_lenght, **kwargs)

@classmethod
def _initialize_write(cls, data, path, data_lenght, **kwargs):
Expand Down Expand Up @@ -159,7 +159,7 @@ def is_written(self):
"""Return true if the associated file has been written """
if self.path is None:
return False
return os.path.exists(self.path)
return os.path.exists(os.path.expandvars(self.path))

def __str__(self):
s = f"{type(self)} "
Expand Down
Loading

0 comments on commit 09739f6

Please sign in to comment.