Skip to content

Commit

Permalink
Fix scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
WWGolay committed Dec 21, 2024
1 parent b8b8767 commit 7c9e156
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 48 deletions.
3 changes: 3 additions & 0 deletions pyscope/bin/scripts/start_sync_manager
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/home/$USER/anaconda3/python

start_syncfiles
33 changes: 33 additions & 0 deletions pyscope/bin/scripts/start_sync_manager.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@echo OFF
rem How to run a Python script in a given conda environment from a batch file.

rem It doesn't require:
rem - conda to be in the PATH
rem - cmd.exe to be initialized with conda init

rem Define here the path to your conda installation
set CONDAPATH=C:\Users\%USERNAME%\Anaconda3\
rem Define here the name of the environment
set ENVNAME=base

rem The following command activates the base environment.
rem call C:\ProgramData\Miniconda3\Scripts\activate.bat C:\ProgramData\Miniconda3
if %ENVNAME%==base (set ENVPATH=%CONDAPATH%) else (set ENVPATH=%CONDAPATH%\envs\%ENVNAME%)

rem Activate the conda environment
rem Using call is required here, see: https://stackoverflow.com/questions/24678144/conda-environments-and-bat-files
call %CONDAPATH%\Scripts\activate.bat %ENVPATH%

rem Run a python script in that environment
python start_syncfiles

rem Deactivate the environment
call conda deactivate

rem If conda is directly available from the command line then the following code works.
rem call activate someenv
rem python script.py
rem conda deactivate

rem One could also use the conda run command
rem conda run -n someenv python script.py
3 changes: 3 additions & 0 deletions pyscope/bin/scripts/start_telrun
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/home/$USER/anaconda3/python

start_telrun
33 changes: 33 additions & 0 deletions pyscope/bin/scripts/start_telrun.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@echo OFF
rem How to run a Python script in a given conda environment from a batch file.

rem It doesn't require:
rem - conda to be in the PATH
rem - cmd.exe to be initialized with conda init

rem Define here the path to your conda installation
set CONDAPATH=C:\Users\%USERNAME%\Anaconda3\
rem Define here the name of the environment
set ENVNAME=base

rem The following command activates the base environment.
rem call C:\ProgramData\Miniconda3\Scripts\activate.bat C:\ProgramData\Miniconda3
if %ENVNAME%==base (set ENVPATH=%CONDAPATH%) else (set ENVPATH=%CONDAPATH%\envs\%ENVNAME%)

rem Activate the conda environment
rem Using call is required here, see: https://stackoverflow.com/questions/24678144/conda-environments-and-bat-files
call %CONDAPATH%\Scripts\activate.bat %ENVPATH%

rem Run a python script in that environment
python start_telrun

rem Deactivate the environment
call conda deactivate

rem If conda is directly available from the command line then the following code works.
rem call activate someenv
rem python script.py
rem conda deactivate

rem One could also use the conda run command
rem conda run -n someenv python script.py
96 changes: 48 additions & 48 deletions pyscope/scheduling/_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,60 @@
class _Block:
def __init__(self, config, observer, name="", description="", **kwargs):
"""
A class to represent a time range in the schedule.
Represents a `~astropy.time.Time` range in a `~pyscope.scheduling.Schedule` attributed to an `~pyscope.scheduling.Observer`.
A `~pyscope.telrun._Block` are used to represent a time range in the schedule. A `~pyscope.telrun._Block` can be
used to represent allocated time with a `~pyscope.telrun.ScheduleBlock` or unallocated time with a
`~pyscope.telrun.UnallocatedBlock`. The `~pyscope.telrun._Block` class is a base class that should not be instantiated
directly. Instead, use the `~pyscope.telrun.ScheduleBlock` or `~pyscope.telrun.UnallocatedBlock` subclasses.
A `~pyscope.scheduling._Block` can be used to represent allocated time with a `~pyscope.scheduling.ScheduleBlock`
or unallocated time with an `~pyscope.scheduling.UnallocatedBlock`. The `~pyscope.scheduling._Block` class is a base
class that should not be instantiated directly. Instead, use the `~pyscope.scheduling.ScheduleBlock` or
`~pyscope.scheduling.UnallocatedBlock` subclasses.
Parameters
----------
configuration : `~pyscope.telrun.InstrumentConfiguration`, required
The `~pyscope.telrun.InstrumentConfiguration` to use for the `~pyscope.telrun._Block`. This `~pyscope.telrun.InstrumentConfiguration` will be
used to set the telescope's `~pyscope.telrun.InstrumentConfiguration` at the start of the `~pyscope.telrun._Block` and
will act as the default `~pyscope.telrun.InstrumentConfiguration` for all `~pyscope.telrun.Field` objects in the
`~pyscope.telrun._Block` if a `~pyscope.telrun.InstrumentConfiguration` has not been provided. If a `~pyscope.telrun.Field`
The `~pyscope.telrun.InstrumentConfiguration` to use for the `~pyscope.scheduling._Block`. This `~pyscope.telrun.InstrumentConfiguration` will be
used to set the telescope's `~pyscope.telrun.InstrumentConfiguration` at the start of the `~pyscope.scheduling._Block` and
will act as the default `~pyscope.telrun.InstrumentConfiguration` for all `~pyscope.scheduling.Field` objects in the
`~pyscope.scheduling._Block` if a `~pyscope.telrun.InstrumentConfiguration` has not been provided. If a `~pyscope.scheduling.Field`
has a different `~pyscope.telrun.InstrumentConfiguration`, it will override the block `~pyscope.telrun.InstrumentConfiguration` for the
duration of the `~pyscope.telrun.Field`.
duration of the `~pyscope.scheduling.Field`.
observer : `~pyscope.telrun.Observer`, required
Associate this `~pyscope.telrun._Block` with an `~pyscope.telrun.Observer`. The `~pyscope.telrun.Observer` is a
observer : `~pyscope.scheduling.Observer`, required
Associate this `~pyscope.scheduling._Block` with an `~pyscope.scheduling.Observer`. The `~pyscope.scheduling.Observer` is a
bookkeeping object for an `~pyscope.observatory.Observatory` with multiple users/user groups.
name : `str`, default : ""
A user-defined name for the `~pyscope.telrun._Block`. This parameter does not change
the behavior of the `~pyscope.telrun._Block`, but it can be useful for identifying the
`~pyscope.telrun._Block` in a schedule.
A user-defined name for the `~pyscope.scheduling._Block`. This parameter does not change
the behavior of the `~pyscope.scheduling._Block`, but it can be useful for identifying the
`~pyscope.scheduling._Block` in a schedule.
description : `str`, default : ""
A user-defined description for the `~pyscope.telrun._Block`. Similar to the `name`
parameter, this parameter does not change the behavior of the `~pyscope.telrun._Block`.
A user-defined description for the `~pyscope.scheduling._Block`. Similar to the `name`
parameter, this parameter does not change the behavior of the `~pyscope.scheduling._Block`.
**kwargs : `dict`, default : {}
A dictionary of keyword arguments that can be used to store additional information
about the `~pyscope.telrun._Block`. This information can be used to store any additional
about the `~pyscope.scheduling._Block`. This information can be used to store any additional
information that is not covered by the `configuration`, `name`, or `description` parameters.
See Also
--------
pyscope.telrun.ScheduleBlock : A subclass of `~pyscope.telrun._Block` that is used to schedule `~pyscope.telrun.Field` objects
in a `~pyscope.telrun.Schedule`.
pyscope.telrun.UnallocatedBlock : A subclass of `~pyscope.telrun._Block` that is used to represent unallocated time in a
`~pyscope.telrun.Schedule`.
pyscope.scheduling.ScheduleBlock : A subclass of `~pyscope.scheduling._Block` that is used to schedule `~pyscope.scheduling.Field` objects
in a `~pyscope.scheduling.Schedule`.
pyscope.scheduling.UnallocatedBlock : A subclass of `~pyscope.scheduling._Block` that is used to represent unallocated time in a
`~pyscope.scheduling.Schedule`.
pyscope.telrun.InstrumentConfiguration : A class that represents the configuration of the telescope.
pyscope.telrun.Field : A class that represents a field to observe.
pyscope.scheduling.Field : A class that represents a field to observe.
"""
logger.debug(
"_Block(config=%s, observer=%s, name=%s, description=%s, **kwargs=%s)"
% (config, observer, name, description, kwargs)
)
self.config = config
self._uuid = uuid4()
self.observer = observer
self.name = name
self.description = description
self.config = config
self.kwargs = kwargs
self._uuid = uuid4()
self._start_time = None
self._end_time = None

Expand All @@ -77,7 +77,7 @@ def from_string(
cls, string, config=None, observer=None, name="", description="", **kwargs
):
"""
Create a new `~pyscope.telrun._Block` from a string representation. Additional arguments can be provided to override
Create a new `~pyscope.scheduling._Block` from a string representation. Additional arguments can be provided to override
the parsed values.
Parameters
Expand All @@ -86,7 +86,7 @@ def from_string(
config : `~pyscope.telrun.InstrumentConfiguration`, default: `None`
observer : `~pyscope.telrun.Observer`, default: `None`
observer : `~pyscope.scheduling.Observer`, default: `None`
name : `str`, default : ""
Expand All @@ -96,7 +96,7 @@ def from_string(
Returns
-------
block : `~pyscope.telrun._Block`
block : `~pyscope.scheduling._Block`
"""
logger.debug(
Expand Down Expand Up @@ -159,7 +159,7 @@ def from_string(

def __str__(self):
"""
A `str` representation of the `~pyscope.telrun._Block`.
A `str` representation of the `~pyscope.scheduling._Block`.
Returns
-------
Expand All @@ -181,7 +181,7 @@ def __str__(self):

def __repr__(self):
"""
A `str` representation of the `~pyscope.telrun._Block`.
A `str` representation of the `~pyscope.scheduling._Block`.
Returns
-------
Expand All @@ -193,7 +193,7 @@ def __repr__(self):
@property
def config(self):
"""
The default `~pyscope.telrun.InstrumentConfiguration` for the `~pyscope.telrun._Block`.
The default `~pyscope.telrun.InstrumentConfiguration` for the `~pyscope.scheduling._Block`.
Returns
-------
Expand All @@ -205,7 +205,7 @@ def config(self):
@config.setter
def config(self, value):
"""
The default `~pyscope.telrun.InstrumentConfiguration` for the `~pyscope.telrun._Block`.
The default `~pyscope.telrun.InstrumentConfiguration` for the `~pyscope.scheduling._Block`.
Parameters
----------
Expand All @@ -228,23 +228,23 @@ def config(self, value):
@property
def observer(self):
"""
The `~pyscope.telrun.Observer` associated with the `~pyscope.telrun._Block`.
The `~pyscope.scheduling.Observer` associated with the `~pyscope.scheduling._Block`.
Returns
-------
observer : `~pyscope.telrun.Observer`
observer : `~pyscope.scheduling.Observer`
"""
logger.debug("_Block().observer == %s" % self._observer)
return self._observer

@observer.setter
def observer(self, value):
"""
The `~pyscope.telrun.Observer` associated with the `~pyscope.telrun._Block`.
The `~pyscope.scheduling.Observer` associated with the `~pyscope.scheduling._Block`.
Parameters
----------
value : `~pyscope.telrun.Observer`
value : `~pyscope.scheduling.Observer`
"""
logger.debug("_Block().observer = %s" % value)
if (
Expand All @@ -262,7 +262,7 @@ def observer(self, value):
@property
def name(self):
"""
A user-defined `str` name for the `~pyscope.telrun._Block`.
A user-defined `str` name for the `~pyscope.scheduling._Block`.
Returns
-------
Expand All @@ -275,7 +275,7 @@ def name(self):
@name.setter
def name(self, value):
"""
A user-defined `str` name for the `~pyscope.telrun._Block`.
A user-defined `str` name for the `~pyscope.scheduling._Block`.
Parameters
----------
Expand All @@ -291,7 +291,7 @@ def name(self, value):
@property
def description(self):
"""
A user-defined `str` description for the `~pyscope.telrun._Block`.
A user-defined `str` description for the `~pyscope.scheduling._Block`.
Returns
-------
Expand All @@ -303,7 +303,7 @@ def description(self):
@description.setter
def description(self, value):
"""
A user-defined `str` description for the `~pyscope.telrun._Block`.
A user-defined `str` description for the `~pyscope.scheduling._Block`.
Parameters
----------
Expand All @@ -320,7 +320,7 @@ def description(self, value):
@property
def kwargs(self):
"""
Additional user-defined keyword arguments in a `dict` for the `~pyscope.telrun._Block`.
Additional user-defined keyword arguments in a `dict` for the `~pyscope.scheduling._Block`.
Returns
-------
Expand All @@ -333,7 +333,7 @@ def kwargs(self):
@kwargs.setter
def kwargs(self, value):
"""
Additional user-defined keyword arguments for the `~pyscope.telrun._Block`.
Additional user-defined keyword arguments for the `~pyscope.scheduling._Block`.
Parameters
----------
Expand All @@ -350,38 +350,38 @@ def kwargs(self, value):
@property
def ID(self):
"""
A `~uuid.UUID` that uniquely identifies the `~pyscope.telrun._Block`.
A `~uuid.UUID` that uniquely identifies the `~pyscope.scheduling._Block`.
Returns
-------
ID : `~uuid.UUID`
The unique identifier for the `~pyscope.telrun._Block`.
The unique identifier for the `~pyscope.scheduling._Block`.
"""
logger.debug("_Block().ID == %s" % self._uuid)
return self._uuid

@property
def start_time(self):
"""
The `~astropy.time.Time` that represents the start of the `~pyscope.telrun._Block`.
The `~astropy.time.Time` that represents the start of the `~pyscope.scheduling._Block`.
Returns
-------
start_time : `astropy.time.Time`
The start time of the `~pyscope.telrun._Block`.
The start time of the `~pyscope.scheduling._Block`.
"""
logger.debug("_Block().start_time == %s" % self._start_time)
return self._start_time

@property
def end_time(self):
"""
The `~astropy.time.Time` that represents the end of the `~pyscope.telrun._Block`.
The `~astropy.time.Time` that represents the end of the `~pyscope.scheduling._Block`.
Returns
-------
end_time : `astropy.time.Time`
The end time of the `~pyscope.telrun._Block`.
The end time of the `~pyscope.scheduling._Block`.
"""
logger.debug("_Block().end_time == %s" % self._end_time)
return self._end_time
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ markdown == 3.6
matplotlib == 3.9.1
numpy == 2.1.2
oschmod == 0.3.12
pandas == 2.2.3
paramiko == 3.5.0
photutils == 1.13.0
prettytable == 3.11.0
Expand Down

0 comments on commit 7c9e156

Please sign in to comment.