Skip to content

Commit

Permalink
export 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsean committed Sep 9, 2024
1 parent b19a71a commit 915f24c
Show file tree
Hide file tree
Showing 18 changed files with 678 additions and 32 deletions.
10 changes: 8 additions & 2 deletions andes_migrate/capture_mollusque.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ def _init_rows(self):
placopecten_magellanicus = 156972
chlamys_islandica = 140692

# DOUBLE HACK! only choose catches that contain baskets that are NOT and NA size-class (shared_models_sizeclass.code=0)
# DOUBLE HACK! only choose catches that contain baskets that are NOT an NA size-class (shared_models_sizeclass.code=0)
# some NA baskets can still exist in a catch that has a non-NA basket
# The NA basket filter is probably not needed...
# also do not consider basket class 9 (biodiversity basket)
size_class_code_NA = 0
size_class_code_biodiversity = 9

query = (
"SELECT DISTINCT ecosystem_survey_catch.id "
Expand All @@ -74,7 +77,8 @@ def _init_rows(self):
"LEFT JOIN shared_models_cruise "
"ON shared_models_cruise.sampling_protocol_id = shared_models_sizeclass.sampling_protocol_id "
f"WHERE shared_models_cruise.id={self.engin.trait.proj._get_current_row_pk()} "
f"AND NOT shared_models_sizeclass.code=0 "
f"AND NOT shared_models_sizeclass.code={size_class_code_NA} "
f"AND NOT shared_models_sizeclass.code={size_class_code_biodiversity} "
f"AND ecosystem_survey_catch.set_id={self.engin.trait._get_current_row_pk()} "
f"AND (shared_models_species.aphia_id = {placopecten_magellanicus} OR shared_models_species.aphia_id = {chlamys_islandica}) "
"ORDER BY ecosystem_survey_catch.id ASC "
Expand Down Expand Up @@ -814,6 +818,8 @@ def _compute_couverture_epibiont(self, catch_id: int) -> int | None:
f"AND ecosystem_survey_observation.observation_type_id='{observation_coverage_type_id}' "
f"AND NOT ecosystem_survey_observation.observation_value='{observation_value_no_barnacles}' "
"AND ecosystem_survey_observation.observation_value IS NOT NULL "
"AND NOT ecosystem_survey_observation.observation_value='NaN' "

)
result = self.andes_db.execute_query(query)

Expand Down
14 changes: 8 additions & 6 deletions andes_migrate/engin_mollusque.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,29 +121,31 @@ def get_no_engin(self) -> int:
"""COD_ENG_GEN INTEGER / NUMBER(5,0)
Numéro identifiant l'engin utilisé tel que défini dans la table NO_ENGIN
Andes: shared_models_set.gear_type_id-> shared_models.geartype.code
Andes: shared_models_auxiliaryequipment.code
This one would be good to have linked with a regional code lookup
https://github.com/dfo-gulf-science/andes/issues/988
Code lookup
1 -> Engin babord
2 -> Engin tribord
3 -> Treuil océano
"""

set_pk = self.trait._get_current_row_pk()
query = (
"SELECT shared_models_set.winch_code "
"SELECT shared_models_auxiliaryequipment.code "
"FROM shared_models_set "
"LEFT JOIN shared_models_set_operations "
"ON shared_models_set_operations.set_id = shared_models_set.id "
"LEFT JOIN shared_models_operation "
"ON shared_models_operation.id = shared_models_set_operations.operation_id "
"LEFT JOIN shared_models_auxiliaryequipment "
"ON shared_models_set.auxiliary_equipment_id = shared_models_auxiliaryequipment.id "

f"WHERE shared_models_set.id={set_pk} "
)
result = self.andes_db.execute_query(query)
self._assert_one(result)
to_return = result[0][0]

return to_return

@log_results
Expand Down
28 changes: 21 additions & 7 deletions andes_migrate/projet_mollusque.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime

from andes_migrate.andes_helper import AndesHelper
from andes_migrate.oracle_helper import OracleHelper
from andes_migrate.table_peche_sentinelle import TablePecheSentinelle
from andes_migrate.decorators import (
AndesCodeLookup,
Expand Down Expand Up @@ -54,7 +55,12 @@ def validate(self):
)
if self.zone in ["20"] and not cod_source_info == 19:
raise ValueError(
f"La zone {self.zone} est incompatible avec le COD_SOURCE_INFO: {cod_source_info}"
f"La zones {self.zone} est incompatible avec le COD_SOURCE_INFO: {cod_source_info}"
)

if self.zone is None and cod_source_info == 18:
raise ValueError(
f"Le COD_SOURCE_INFO: {cod_source_info} doit spécifier la zone de peche 16E ou 16F"
)

# year compatible with start and end dates
Expand Down Expand Up @@ -103,12 +109,12 @@ def _init_rows(self):

def init_input(
self,
zone: str = "defaultzone",
zone: str|None = None,
no_notif: str = "IML-2000-001",
espece: str = "pétoncle",
):
"""
zone (str): 16E, 16F ou 20
zone (str): 16E, 16F or None. ONLY for petoncle minganie
"""

Expand All @@ -118,7 +124,7 @@ def init_input(
)
self.espece = espece

if zone not in ["16E", "16F", "20"]:
if zone not in ["16E", "16F", "20", None]:
raise ValueError("zone doit etre un de 16E, 16F ou 20")
self.zone = zone

Expand Down Expand Up @@ -171,6 +177,8 @@ def get_cod_source_info(self) -> int:
18 -> Évaluation de stocks IML - Pétoncle Minganie
19 -> Évaluation de stocks IML - Pétoncle I de M (Access)
19 -> Évaluation de stocks IML - Pétoncle Îles-de-la-Madeleine (Oracle)
22 -> Relevé buccin Haute Côte-Nord
"""
query = (
f"SELECT shared_models_cruise.description "
Expand Down Expand Up @@ -299,6 +307,7 @@ def get_cod_serie_hist(self) -> int:
15 -> Indice d'abondance zone 16E - pétoncle
16 -> Indice d'abondance zone 16F - pétoncle
18 -> Indice d'abondance zone 20 - pétoncle
20 -> Indice d'abondance buccin
Valid description should be one of
Indice d'abondance zone 16E - pétoncle
Expand All @@ -311,8 +320,11 @@ def get_cod_serie_hist(self) -> int:
# TODO: use COD_SERIE_HIST as datainput
if self.espece == "pétoncle":
desc = f"Indice d'abondance zone {self.zone} - {self.espece}"
else:
elif self.espece == "buccin":
desc = f"Indice d'abondance {self.espece}"
else:
print("cannot find description for COD_SERIE_HIST")
raise ValueError

key = self.reference_data.get_ref_key(
table="Indice_Suivi_Etat_Stock",
Expand Down Expand Up @@ -417,7 +429,7 @@ def get_date_fin_project(self) -> str | None:

return to_return

@validate_string(max_len=12)
@validate_string(max_len=13)
@log_results
def get_no_notif_iml(self) -> str | None:
"""NO_NOTIF_IML VARCHAR(12) / VARCHAR2(12)
Expand Down Expand Up @@ -572,7 +584,8 @@ def get_dist_chalute_visee(self) -> float | None:
Andes: `shared_models_cruise.targeted_trawl_distance`
units: meters
units: meters Andes stores this in nautical miles, need to convert to m.
N.B Andes does not permit setting this value, but will rather calculate it.
Expand All @@ -591,6 +604,7 @@ def get_dist_chalute_visee(self) -> float | None:
self._assert_one(result)
to_return = result[0][0]
to_return = float(to_return)
to_return = OracleHelper.convert_nm_2_km(to_return)*1000
return to_return

@tag(HardCoded)
Expand Down
12 changes: 12 additions & 0 deletions andes_migrate/ref_data/stations_BC.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name,type,latitude,longitude,comments
101,27,49.20604167,-68.08777778,
102,1,49.20025,-68.08777778,
103,1,49.19431944,-68.08777778,
104,1,49.18855556,-68.08777778,
105,1,49.18273611,-68.08777778,
106,1,49.17693056,-68.08777778,
107,1,49.171,-68.08777778,
108,1,49.16506944,-68.08777778,
109,1,49.15927778,-68.09269444,
110,1,49.15333333,-68.09716667,
111,27,49.14766667,-68.09716667,
56 changes: 56 additions & 0 deletions andes_migrate/ref_data/stations_FOR.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name,type,latitude,longitude,comments
001,1,48.77044444,-68.94191667,
002,27,48.764625,-68.95073611,
003,1,48.764625,-68.95955556,
004,1,48.75880556,-68.95955556,
005,1,48.75880556,-68.96855556,
006,1,48.75880556,-68.977375,
007,1,48.75298611,-68.95955556,
008,1,48.75298611,-68.96855556,
009,1,48.75298611,-68.977375,
010,1,48.75298611,-68.98618889,
011,1,48.74715278,-68.96855556,
012,1,48.74715278,-68.977375,
013,1,48.74715278,-68.98618889,
014,1,48.74715278,-68.995,
015,1,48.74120278,-68.977375,
016,1,48.74120278,-68.98618889,
017,1,48.74120278,-68.995,
018,1,48.74120278,-69.00380556,
019,1,48.73537778,-68.977375,
020,1,48.73537778,-68.98618889,
021,1,48.73537778,-68.995,
022,1,48.73537778,-69.00380556,
023,1,48.72955556,-68.98618889,
024,1,48.72955556,-68.995,
025,1,48.72955556,-69.00380556,
026,27,48.72955556,-69.01261111,
027,1,48.72372222,-68.98618889,
028,1,48.72372222,-68.995,
035,1,48.7179,-69.02141667,
036,1,48.71207222,-69.00380556,
037,1,48.71207222,-69.01261111,
038,1,48.71207222,-69.02141667,
039,1,48.71207222,-69.03040278,
040,1,48.70611111,-69.00380556,
041,1,48.70611111,-69.01261111,
042,1,48.70611111,-69.02141667,
043,1,48.70611111,-69.03040278,
044,1,48.70029167,-69.01261111,
045,1,48.70029167,-69.02141667,
046,1,48.70029167,-69.03040278,
047,1,48.69445833,-69.01261111,
048,1,48.69445833,-69.02141667,
049,1,48.69445833,-69.03040278,
050,1,48.68863889,-69.02141667,
051,1,48.68863889,-69.03040278,
052,1,48.68280556,-69.02141667,
053,1,48.68280556,-69.03040278,
054,1,48.68280556,-69.03918056,
055,1,48.67698611,-69.03040278,
056,1,48.67698611,-69.03918056,
057,1,48.67102778,-69.03918056,
058,1,48.66519444,-69.03918056,
059,1,48.66519444,-69.04797222,
060,27,48.659375,-69.03918056,
061,1,48.659375,-69.04797222,
27 changes: 27 additions & 0 deletions andes_migrate/ref_data/stations_PaO.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name,type,latitude,longitude,comments
206,1,49.00827778,-68.48127778,
207,1,49.00527778,-68.49034722,
208,1,49.00527778,-68.49919444,
209,1,49.00527778,-68.50802778,
210,1,49.00527778,-68.51686111,
211,1,49.00527778,-68.525625,
212,1,49.00527778,-68.53475,
213,1,49.00527778,-68.54356944,
214,1,49.00527778,-68.55258333,
215,1,49.00527778,-68.56140278,
216,27,48.99952778,-68.51686111,
217,1,48.99952778,-68.525625,
218,1,48.99952778,-68.53475,
219,1,48.99952778,-68.54356944,
220,1,48.99952778,-68.55258333,
251,1,49.00901667,-68.56353333,
252,1,49.00476667,-68.57445,
253,1,49.00216667,-68.58161667,
254,1,48.99853333,-68.58731667,
255,27,48.99536667,-68.59416667,
256,1,49.00963333,-68.47291667,
257,1,49.01090278,-68.46453333,
258,1,49.01276111,-68.45584722,
259,1,49.014025,-68.44716944,
260,27,49.01528889,-68.43849167,
261,1,49.01703056,-68.43016944,
80 changes: 80 additions & 0 deletions andes_migrate/ref_data/stations_buccin01.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name,type,latitude,longitude,comments
001,1,48.77044444,-68.94191667,
002,27,48.764625,-68.95073611,
003,1,48.764625,-68.95955556,
004,1,48.75880556,-68.95955556,
005,1,48.75880556,-68.96855556,
006,1,48.75880556,-68.977375,
007,1,48.75298611,-68.95955556,
008,1,48.75298611,-68.96855556,
009,1,48.75298611,-68.977375,
010,1,48.75298611,-68.98618889,
011,1,48.74715278,-68.96855556,
012,1,48.74715278,-68.977375,
013,1,48.74715278,-68.98618889,
014,1,48.74715278,-68.995,
015,1,48.74120278,-68.977375,
016,1,48.74120278,-68.98618889,
017,1,48.74120278,-68.995,
018,1,48.74120278,-69.00380556,
019,1,48.73537778,-68.977375,
020,1,48.73537778,-68.98618889,
021,1,48.73537778,-68.995,
022,1,48.73537778,-69.00380556,
023,1,48.72955556,-68.98618889,
024,1,48.72955556,-68.995,
025,1,48.72955556,-69.00380556,
026,27,48.72955556,-69.01261111,
027,1,48.72372222,-68.98618889,
028,1,48.72372222,-68.995,
035,1,48.7179,-69.02141667,
036,1,48.71207222,-69.00380556,
037,1,48.71207222,-69.01261111,
038,1,48.71207222,-69.02141667,
039,1,48.71207222,-69.03040278,
040,1,48.70611111,-69.00380556,
041,1,48.70611111,-69.01261111,
042,1,48.70611111,-69.02141667,
043,1,48.70611111,-69.03040278,
044,1,48.70029167,-69.01261111,
045,1,48.70029167,-69.02141667,
046,1,48.70029167,-69.03040278,
047,1,48.69445833,-69.01261111,
048,1,48.69445833,-69.02141667,
049,1,48.69445833,-69.03040278,
050,1,48.68863889,-69.02141667,
051,1,48.68863889,-69.03040278,
052,1,48.68280556,-69.02141667,
053,1,48.68280556,-69.03040278,
054,1,48.68280556,-69.03918056,
055,1,48.67698611,-69.03040278,
056,1,48.67698611,-69.03918056,
057,1,48.67102778,-69.03918056,
058,1,48.66519444,-69.03918056,
059,1,48.66519444,-69.04797222,
060,27,48.659375,-69.03918056,
061,1,48.659375,-69.04797222,
206,1,49.00827778,-68.48127778,
207,1,49.00527778,-68.49034722,
208,1,49.00527778,-68.49919444,
209,1,49.00527778,-68.50802778,
210,1,49.00527778,-68.51686111,
211,1,49.00527778,-68.525625,
212,1,49.00527778,-68.53475,
213,1,49.00527778,-68.54356944,
214,1,49.00527778,-68.55258333,
215,1,49.00527778,-68.56140278,
216,27,48.99952778,-68.51686111,
217,1,48.99952778,-68.525625,
218,1,48.99952778,-68.53475,
219,1,48.99952778,-68.54356944,
220,1,48.99952778,-68.55258333,
251,1,49.00901667,-68.56353333,
252,1,49.00476667,-68.57445,
253,1,49.00216667,-68.58161667,
254,1,48.99853333,-68.58731667,
255,27,48.99536667,-68.59416667,
256,1,49.00963333,-68.47291667,
257,1,49.01090278,-68.46453333,
258,1,49.01276111,-68.45584722,
259,1,49.014025,-68.44716944,
14 changes: 14 additions & 0 deletions andes_migrate/ref_data/stations_buccin02.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name,type,latitude,longitude,comments
101,27,49.20604167,-68.08777778,
102,1,49.20025,-68.08777778,
103,1,49.19431944,-68.08777778,
104,1,49.18855556,-68.08777778,
105,1,49.18273611,-68.08777778,
106,1,49.17693056,-68.08777778,
107,1,49.171,-68.08777778,
108,1,49.16506944,-68.08777778,
109,1,49.15927778,-68.09269444,
110,1,49.15333333,-68.09716667,
111,27,49.14766667,-68.09716667,
260,27,49.01528889,-68.43849167,
261,1,49.01703056,-68.43016944,
Loading

0 comments on commit 915f24c

Please sign in to comment.